Skip to content

Commit

Permalink
Support export declarations in extensions rule
Browse files Browse the repository at this point in the history
Fixes #964.
  • Loading branch information
silvenon committed Feb 6, 2018
1 parent 3268a82 commit ab49972
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
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
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 ab49972

Please sign in to comment.