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 18, 2017
1 parent 81e9bb9 commit df74913
Show file tree
Hide file tree
Showing 4 changed files with 24 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
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
'flow-object-type': require('./rules/flow-object-type'),
'func-params-comma-dangle': require('./rules/func-params-comma-dangle'),
'no-invalid-this': require('./rules/no-invalid-this'),
'semi': require('./rules/semi'),
},
rulesConfig: {
'generator-star-spacing': 0,
Expand All @@ -24,5 +25,6 @@ module.exports = {
'flow-object-type': 0,
'func-params-comma-dangle': 0,
'no-invalid-this': 0,
'semi': 0,
}
};
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 df74913

Please sign in to comment.