Skip to content

Commit

Permalink
Merge pull request #1012 from silvenon/extensions-export
Browse files Browse the repository at this point in the history
Support export declarations in extensions rule
  • Loading branch information
ljharb authored Feb 6, 2018
2 parents 3268a82 + ab49972 commit 219a8d2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/rules/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ module.exports = {

function checkFileExtension(node) {
const { source } = node

// bail if the declaration doesn't have a source, e.g. "export { foo };"
if (!source) return

const importPath = source.value

// don't enforce anything on builtins
Expand Down Expand Up @@ -159,6 +163,7 @@ module.exports = {

return {
ImportDeclaration: checkFileExtension,
ExportNamedDeclaration: checkFileExtension,
}
},
}
45 changes: 45 additions & 0 deletions tests/src/rules/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ ruleTester.run('extensions', rule, {
},
},
}),

// export (#964)
test({
code: [
'export { foo } from "./foo.js"',
'export { bar }',
].join('\n'),
options: [ 'always' ],
}),
test({
code: [
'export { foo } from "./foo"',
'export { bar }',
].join('\n'),
options: [ 'never' ],
}),
],

invalid: [
Expand Down Expand Up @@ -314,5 +330,34 @@ ruleTester.run('extensions', rule, {
options: [ 'never', {ignorePackages: true} ],
}),

// export (#964)
test({
code: [
'export { foo } from "./foo"',
'export { bar }',
].join('\n'),
options: [ 'always' ],
errors: [
{
message: 'Missing file extension for "./foo"',
line: 1,
column: 21,
},
],
}),
test({
code: [
'export { foo } from "./foo.js"',
'export { bar }',
].join('\n'),
options: [ 'never' ],
errors: [
{
message: 'Unexpected use of file extension "js" for "./foo.js"',
line: 1,
column: 21,
},
],
}),
],
})

0 comments on commit 219a8d2

Please sign in to comment.