Skip to content

Commit

Permalink
[New] no-named-as-default: support arbitrary module namespace names
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Jan 22, 2022
1 parent bdcbb8e commit de5d4f6
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions tests/src/rules/no-named-as-default.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { test, SYNTAX_CASES } from '../utils';
import { test, testVersion, SYNTAX_CASES } from '../utils';
import { RuleTester } from 'eslint';

const ruleTester = new RuleTester();
const rule = require('rules/no-named-as-default');

ruleTester.run('no-named-as-default', rule, {
valid: [
valid: [].concat(
test({ code: 'import "./malformed.js"' }),

test({ code: 'import bar, { foo } from "./bar";' }),
Expand All @@ -21,10 +21,16 @@ ruleTester.run('no-named-as-default', rule, {
test({ code: 'export default from "./bar";',
parser: require.resolve('babel-eslint') }),

// es2022: Arbitrary module namespae identifier names
testVersion('>= 8.7', () => ({
code: 'import bar, { foo } from "./export-default-string-and-named"',
parserOptions: { ecmaVersion: 2022 },
})),

...SYNTAX_CASES,
],
),

invalid: [
invalid: [].concat(
test({
code: 'import foo from "./bar";',
errors: [ {
Expand Down Expand Up @@ -57,5 +63,23 @@ ruleTester.run('no-named-as-default', rule, {
type: 'Literal',
}],
}),
],

// es2022: Arbitrary module namespae identifier names
testVersion('>= 8.7', () => ({
code: 'import foo from "./export-default-string-and-named"',
errors: [{
message: 'Using exported name \'foo\' as identifier for default export.',
type: 'ImportDefaultSpecifier',
}],
parserOptions: { ecmaVersion: 2022 },
})),
testVersion('>= 8.7', () => ({
code: 'import foo, { foo as bar } from "./export-default-string-and-named"',
errors: [{
message: 'Using exported name \'foo\' as identifier for default export.',
type: 'ImportDefaultSpecifier',
}],
parserOptions: { ecmaVersion: 2022 },
})),
),
});

0 comments on commit de5d4f6

Please sign in to comment.