From 8e83dc5747b92381aeba6f77d03bf875917bf423 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Thu, 19 Apr 2018 23:16:20 -0500 Subject: [PATCH] Fix bug with semi rule with class properties and omitLastInOneLineBlock option --- rules/semi.js | 4 ++-- tests/rules/semi.js | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/rules/semi.js b/rules/semi.js index 95a2467..2d2fcc4 100644 --- a/rules/semi.js +++ b/rules/semi.js @@ -83,11 +83,11 @@ const semiRuleWithClassProperty = ruleComposer.joinReports([ } } else { if (!isSemicolon(lastToken)) { - if (!exceptOneLine || !isOneLinerBlock(node)) { + if (!exceptOneLine || !isOneLinerBlock(context, node)) { report(context, node); } } else { - if (exceptOneLine && isOneLinerBlock(node)) { + if (exceptOneLine && isOneLinerBlock(context, node)) { report(context, node, true); } } diff --git a/tests/rules/semi.js b/tests/rules/semi.js index b3f4620..15ebea0 100644 --- a/tests/rules/semi.js +++ b/tests/rules/semi.js @@ -103,10 +103,12 @@ ruleTester.run("semi", rule, { "class Foo { bar = 'example'; }", "class Foo { static bar = 'example'; }", { code: "async function foo() { for await (let thing of {}) { console.log(thing); } }", parserOptions: { ecmaVersion: 6 } }, + { code: "class Foo { bar = () => {}; }", options: ["always", { omitLastInOneLineBlock: true }] }, // babel, "never" { code: "class Foo { bar = 'example' }", options: ["never"] }, - { code: "class Foo { static bar = 'example' }", options: ["never"] } + { code: "class Foo { static bar = 'example' }", options: ["never"] }, + { code: "class Foo { bar = () => {} }", 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 }] }, @@ -184,9 +186,19 @@ ruleTester.run("semi", rule, { // babel { code: "class Foo { bar = 'example' }", errors: [{ message: "Missing semicolon." }] }, { code: "class Foo { static bar = 'example' }", errors: [{ message: "Missing semicolon." }] }, + { + code: "class Foo { bar = () => {} }", + options: ["always", { omitLastInOneLineBlock: true }], + 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." }] } + { code: "class Foo { static bar = 'example'; }", options: ["never"], errors: [{ message: "Extra semicolon." }] }, + { + code: "class Foo { bar = () => {}; }", + options: ["never"], + errors: [{ message: "Extra semicolon." }] + }, ] });