Skip to content

Commit

Permalink
fix edge case.
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Nov 14, 2017
1 parent 7d97579 commit da28611
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/one-var.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ module.exports = {
const declarationCounts = countDeclarations(declarations);
const currentOptions = options[statementType] || {};
const currentScope = getCurrentScope(statementType);
const hasRequires = declarations.some(isRequire);

if (currentOptions.uninitialized === MODE_ALWAYS && currentOptions.initialized === MODE_ALWAYS) {
if (currentScope.uninitialized || currentScope.initialized) {
Expand All @@ -264,6 +265,9 @@ module.exports = {
return false;
}
}
if (currentScope.required && hasRequires) {
return false;
}
recordTypes(statementType, declarations, currentScope);
return true;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/one-var.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,17 @@ ruleTester.run("one-var", rule, {
line: 1,
column: 1
}]
},
{
code: "const foo = require('foo'); const bar = require('bar');",
options: [{ separateRequires: true, const: "always" }],
parserOptions: { env: { node: true } },
errors: [{
message: "Combine this with the previous 'const' statement.",
type: "VariableDeclaration",
line: 1,
column: 29
}]
}
]
});

0 comments on commit da28611

Please sign in to comment.