Skip to content

Commit

Permalink
Fix: adds conditional for separateRequires in one-var (fixes #10179).
Browse files Browse the repository at this point in the history
  • Loading branch information
sstern6 committed Oct 15, 2018
1 parent d45b184 commit 413d44c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rules/one-var.js
Expand Up @@ -255,7 +255,9 @@ module.exports = {

if (currentOptions.uninitialized === MODE_ALWAYS && currentOptions.initialized === MODE_ALWAYS) {
if (currentScope.uninitialized || currentScope.initialized) {
return false;
if (!hasRequires) {
return false;
}
}
}

Expand All @@ -266,7 +268,9 @@ module.exports = {
}
if (declarationCounts.initialized > 0) {
if (currentOptions.initialized === MODE_ALWAYS && currentScope.initialized) {
return false;
if (!hasRequires) {
return false;
}
}
}
if (currentScope.required && hasRequires) {
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/one-var.js
Expand Up @@ -209,6 +209,14 @@ ruleTester.run("one-var", rule, {
options: [{ separateRequires: true, var: "always" }],
parserOptions: { env: { node: true } }
},
{
code: "var bar = 'bar'; var foo = require('foo');",
options: [{ separateRequires: true, var: "always" }]
},
{
code: "var foo = require('foo'); var bar = 'bar';",
options: [{ separateRequires: true, var: "always" }]
},
{
code: "var foo = require('foo'); var bar = 'bar';",
options: [{ separateRequires: true, var: "always" }],
Expand Down

0 comments on commit 413d44c

Please sign in to comment.