From e1d9306cf977d6b6bf77c4064d5156300ad373d4 Mon Sep 17 00:00:00 2001 From: Kevin Partington Date: Mon, 19 Mar 2018 18:43:30 -0400 Subject: [PATCH] Fix: object-curly-newline minProperties w/default export (fixes #10101) minProperties only tracks ImportSpecifier and ExportSpecifier nodes --- lib/rules/object-curly-newline.js | 3 ++- tests/lib/rules/object-curly-newline.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/rules/object-curly-newline.js b/lib/rules/object-curly-newline.js index 14b5d06a723..39043a8b9bf 100644 --- a/lib/rules/object-curly-newline.js +++ b/lib/rules/object-curly-newline.js @@ -116,7 +116,8 @@ function areLineBreaksRequired(node, options, first, last) { } else { // is ImportDeclaration or ExportNamedDeclaration - objectProperties = node.specifiers; + objectProperties = node.specifiers + .filter(s => s.type === "ImportSpecifier" || s.type === "ExportSpecifier"); } return objectProperties.length >= options.minProperties || diff --git a/tests/lib/rules/object-curly-newline.js b/tests/lib/rules/object-curly-newline.js index 73d9a233a94..a3235a91a96 100644 --- a/tests/lib/rules/object-curly-newline.js +++ b/tests/lib/rules/object-curly-newline.js @@ -493,6 +493,10 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ImportDeclaration: { minProperties: 3 } }] }, + { + code: "import DefaultExport, {a} from 'module';", + options: [{ ImportDeclaration: { minProperties: 2 } }] + }, // "ExportDeclaration" --------------------------------------------- { @@ -1590,6 +1594,19 @@ ruleTester.run("object-curly-newline", rule, { { line: 3, column: 1, message: "Unexpected line break before this closing brace." } ] }, + { + code: "import DefaultExport, {a, b} from 'module';", + output: [ + "import DefaultExport, {", + "a, b", + "} from 'module';" + ].join("\n"), + options: [{ ImportDeclaration: { minProperties: 2 } }], + errors: [ + { line: 1, column: 23, message: "Expected a line break after this opening brace." }, + { line: 1, column: 28, message: "Expected a line break before this closing brace." } + ] + }, // "ExportDeclaration" --------------------------------------------- {