From df7491304cdb86f28f87cfc5fbe36ad2a6c0956a Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Fri, 17 Feb 2017 15:46:58 -0800 Subject: [PATCH] Add ClassProperty support to semi rule Fixes #43 --- README.md | 4 +++- index.js | 2 ++ rules/semi.js | 1 + tests/rules/semi.js | 20 ++++++++++++++++++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 157bd2d..4da03e0 100644 --- a/README.md +++ b/README.md @@ -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 } } ``` @@ -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 diff --git a/index.js b/index.js index efba7b7..ffc2cf9 100644 --- a/index.js +++ b/index.js @@ -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, @@ -24,5 +25,6 @@ module.exports = { 'flow-object-type': 0, 'func-params-comma-dangle': 0, 'no-invalid-this': 0, + 'semi': 0, } }; diff --git a/rules/semi.js b/rules/semi.js index ee37ab0..48bbb7e 100644 --- a/rules/semi.js +++ b/rules/semi.js @@ -208,6 +208,7 @@ module.exports = { ContinueStatement: checkForSemicolon, ImportDeclaration: checkForSemicolon, ExportAllDeclaration: checkForSemicolon, + ClassProperty: checkForSemicolon, ExportNamedDeclaration(node) { if (!node.declaration) { checkForSemicolon(node); diff --git a/tests/rules/semi.js b/tests/rules/semi.js index a23a6e8..3d146a1 100644 --- a/tests/rules/semi.js +++ b/tests/rules/semi.js @@ -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 }] }, @@ -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." }] } ] });