Skip to content

Commit

Permalink
Update: ensure semi-spacing checks import/export declarations (#8033)
Browse files Browse the repository at this point in the history
* Update: ensure semi-spacing checks import/export declarations

* Also check ExportAllDeclarations and ExportDefaultDeclarations
  • Loading branch information
not-an-aardvark authored and alberto committed Feb 7, 2017
1 parent e228d56 commit f47fb98
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/rules/semi-spacing.js
Expand Up @@ -206,6 +206,10 @@ module.exports = {
DebuggerStatement: checkNode,
ReturnStatement: checkNode,
ThrowStatement: checkNode,
ImportDeclaration: checkNode,
ExportNamedDeclaration: checkNode,
ExportAllDeclaration: checkNode,
ExportDefaultDeclaration: checkNode,
ForStatement(node) {
if (node.init) {
checkSemicolonSpacing(sourceCode.getTokenAfter(node.init), node);
Expand Down
46 changes: 45 additions & 1 deletion tests/lib/rules/semi-spacing.js
Expand Up @@ -163,7 +163,51 @@ ruleTester.run("semi-spacing", rule, {
{ message: "Unexpected whitespace after semicolon.", type: "ForStatement", line: 1, column: 15 },
{ message: "Unexpected whitespace after semicolon.", type: "ForStatement", line: 1, column: 23 }
]
},
{
code: "import Foo from 'bar' ;",
output: "import Foo from 'bar';",
parserOptions: { sourceType: "module" },
options: [{ before: false, after: true }],
errors: [
{ message: "Unexpected whitespace before semicolon.", type: "ImportDeclaration", line: 1, column: 23 }
]
},
{
code: "import * as foo from 'bar' ;",
output: "import * as foo from 'bar';",
parserOptions: { sourceType: "module" },
options: [{ before: false, after: true }],
errors: [
{ message: "Unexpected whitespace before semicolon.", type: "ImportDeclaration", line: 1, column: 28 }
]
},
{
code: "export {foo} ;",
output: "export {foo};",
parserOptions: { sourceType: "module" },
options: [{ before: false, after: true }],
errors: [
{ message: "Unexpected whitespace before semicolon.", type: "ExportNamedDeclaration", line: 1, column: 14 }
]
},
{
code: "export * from 'foo' ;",
output: "export * from 'foo';",
parserOptions: { sourceType: "module" },
options: [{ before: false, after: true }],
errors: [
{ message: "Unexpected whitespace before semicolon.", type: "ExportAllDeclaration", line: 1, column: 21 }
]
},
{
code: "export default foo ;",
output: "export default foo;",
parserOptions: { sourceType: "module" },
options: [{ before: false, after: true }],
errors: [
{ message: "Unexpected whitespace before semicolon.", type: "ExportDefaultDeclaration", line: 1, column: 20 }
]
}

]
});

0 comments on commit f47fb98

Please sign in to comment.