Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
Add ClassProperty support to semi rule
Browse files Browse the repository at this point in the history
Fixes #43
  • Loading branch information
aaronjensen committed Feb 17, 2017
1 parent 81e9bb9 commit 3ac17b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ original ones as well!).
"babel/object-curly-spacing": 1,
"babel/no-await-in-loop": 1,
"babel/flow-object-type": 1,
"babel/no-invalid-this": 1
"babel/no-invalid-this": 1,
"babel/semi": 1
}
}
```
Expand All @@ -50,6 +51,7 @@ The following rules are not in `eslint`, but are relevant only to syntax that is
the current JavaScript standard or supported by `eslint`.

- `babel/no-await-in-loop`: guard against awaiting async functions inside of a loop
- `babel/semi`: Includes class properties

#### Deprecated

Expand Down
1 change: 1 addition & 0 deletions rules/semi.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ module.exports = {
ContinueStatement: checkForSemicolon,
ImportDeclaration: checkForSemicolon,
ExportAllDeclaration: checkForSemicolon,
ClassProperty: checkForSemicolon,
ExportNamedDeclaration(node) {
if (!node.declaration) {
checkForSemicolon(node);
Expand Down
20 changes: 18 additions & 2 deletions tests/rules/semi.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ ruleTester.run("semi", rule, {

// https://github.com/eslint/eslint/issues/7782
{ code: "var a = b;\n/foo/.test(c)", options: ["never"] },
{ code: "var a = b;\n`foo`", options: ["never"], parserOptions: { ecmaVersion: 6 } }
{ code: "var a = b;\n`foo`", options: ["never"], parserOptions: { ecmaVersion: 6 } },

// babel
"class Foo { bar = 'example'; }",
"class Foo { static bar = 'example'; }",

// babel, "never"
{ code: "class Foo { bar = 'example' }", options: ["never"] },
{ code: "class Foo { static bar = 'example' }", options: ["never"] }
],
invalid: [
{ code: "import * as utils from './utils'", output: "import * as utils from './utils';", parserOptions: { sourceType: "module" }, errors: [{ message: "Missing semicolon.", type: "ImportDeclaration", column: 33 }] },
Expand Down Expand Up @@ -170,6 +178,14 @@ ruleTester.run("semi", rule, {
{ code: "export default (foo) => foo.bar();", output: "export default (foo) => foo.bar()", options: ["never"], parserOptions: { sourceType: "module" }, errors: [{ message: "Extra semicolon.", type: "ExportDefaultDeclaration" }] },
{ code: "export default foo = 42;", output: "export default foo = 42", options: ["never"], parserOptions: { sourceType: "module" }, errors: [{ message: "Extra semicolon.", type: "ExportDefaultDeclaration" }] },
{ code: "export default foo += 42;", output: "export default foo += 42", options: ["never"], parserOptions: { sourceType: "module" }, errors: [{ message: "Extra semicolon.", type: "ExportDefaultDeclaration" }] },
{ code: "a;\n++b", output: "a\n++b", options: ["never"], errors: [{ message: "Extra semicolon." }] }
{ code: "a;\n++b", output: "a\n++b", options: ["never"], errors: [{ message: "Extra semicolon." }] },

// babel
{ code: "class Foo { bar = 'example' }", errors: [{ message: "Missing semicolon." }] },
{ code: "class Foo { static bar = 'example' }", errors: [{ message: "Missing semicolon." }] },

// babel, "never"
{ code: "class Foo { bar = 'example'; }", options: ["never"], errors: [{ message: "Extra semicolon." }] },
{ code: "class Foo { static bar = 'example'; }", options: ["never"], errors: [{ message: "Extra semicolon." }] }
]
});

0 comments on commit 3ac17b4

Please sign in to comment.