Skip to content

Commit

Permalink
[Tests] no-named-as-default: add cases for invalid code
Browse files Browse the repository at this point in the history
  • Loading branch information
akwodkiewicz committed Sep 9, 2024
1 parent 7dfee21 commit 3a0af7e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rules/no-named-as-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ module.exports = {
}

if (!importedModule.hasDefault) {
// Impossible: how could we even get here? Kept in case of unexpected regressions.
// The rule is triggered for default imports/exports, so if the imported module has no default
// this means we're dealing with incorrect source code anyway
return;
}

Expand Down
1 change: 1 addition & 0 deletions tests/files/no-named-as-default/no-default-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foobar = 4;
8 changes: 8 additions & 0 deletions tests/src/rules/no-named-as-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ ruleTester.run('no-named-as-default', rule, {
test({
code: 'import variable from "./no-named-as-default/misleading-re-exports.js";',
}),
test({
// incorrect import
code: 'import foobar from "./no-named-as-default/no-default-export.js";',
}),
// same tests, but for exports
test({
code: 'export something from "./no-named-as-default/re-exports.js";',
Expand All @@ -66,6 +70,10 @@ ruleTester.run('no-named-as-default', rule, {
code: 'export variable from "./no-named-as-default/misleading-re-exports.js";',
parser: parsers.BABEL_OLD,
}),
test({
code: 'export foobar from "./no-named-as-default/no-default-export.js";',
parser: parsers.BABEL_OLD,
}),

...SYNTAX_CASES,
),
Expand Down

0 comments on commit 3a0af7e

Please sign in to comment.