Skip to content

Commit

Permalink
Fix: make separateRequires work in consecutive mode (fixes #10784) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored and not-an-aardvark committed Sep 28, 2018
1 parent e51868d commit 9432b10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rules/one-var.js
Expand Up @@ -384,8 +384,13 @@ module.exports = {
if (nodeIndex > 0) {
const previousNode = parent.body[nodeIndex - 1];
const isPreviousNodeDeclaration = previousNode.type === "VariableDeclaration";
const declarationsWithPrevious = declarations.concat(previousNode.declarations || []);

if (isPreviousNodeDeclaration && previousNode.kind === type) {
if (
isPreviousNodeDeclaration &&
previousNode.kind === type &&
!(declarationsWithPrevious.some(isRequire) && !declarationsWithPrevious.every(isRequire))
) {
const previousDeclCounts = countDeclarations(previousNode.declarations);

if (options[type].initialized === MODE_CONSECUTIVE && options[type].uninitialized === MODE_CONSECUTIVE) {
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/one-var.js
Expand Up @@ -263,6 +263,13 @@ ruleTester.run("one-var", rule, {
options: ["consecutive"],
parserOptions: { ecmaVersion: 6 }
},

// https://github.com/eslint/eslint/issues/10784
{
code: "const foo = require('foo'); const bar = 'bar';",
options: [{ const: "consecutive", separateRequires: true }],
parserOptions: { ecmaVersion: 6 }
},
{
code: "var a = 0, b = 1; var c, d;",
options: [{ initialized: "consecutive", uninitialized: "always" }]
Expand Down

0 comments on commit 9432b10

Please sign in to comment.