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 authored and btmills committed Feb 15, 2019
1 parent 0c02932 commit 85a04b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rules/one-var.js
Expand Up @@ -235,7 +235,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 @@ -246,7 +248,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
19 changes: 19 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 Expand Up @@ -1092,6 +1100,17 @@ ruleTester.run("one-var", rule, {
column: 25
}]
},
{
code: "var a = true; var b = false;",
output: "var a = true, b = false;",
options: [{ separateRequires: true, var: "always" }],
errors: [{
message: "Combine this with the previous 'var' statement.",
type: "VariableDeclaration",
line: 1,
column: 15
}]
},
{
code: "const a = 0; let b = 1; let c = 2; const d = 3;",
output: "const a = 0; let b = 1, c = 2; const d = 3;",
Expand Down

0 comments on commit 85a04b3

Please sign in to comment.