New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSCS modifications to one-var #4680
JSCS modifications to one-var #4680
Comments
@confuser Thanks for the issue! If you're reporting a bug, please be sure to include:
Requesting a new rule? Please see Proposing a New Rule for instructions. |
It sounds like this would have to be an additional option for |
@nzakas what about setting the option to multi? E.g.
|
"Multi" is pretty ambiguous in this context because it's the opposite of one (and we already have "always" and "never") |
What about something like "non-consecutive" or "non-consecutive-only"? |
It sounds like the main request here is for a separate rule to allow or prevent multiple separate This rule would enforce or prevent a single Valid when var a = 0
var b = 1
var c = 2
console.log('hello')
var d
var e Valid when var a = 0
, b = 1
, c = 2
console.log('hello')
var d, e |
It can't be a separate rule because it will clash with |
We still need a concrete proposal for this rule. |
Repeating here to close #5910 as dup: requireMultipleVarDecl, disallowMultipleVarDecl → http://eslint.org/docs/rules/one-var (?)
Current |
@mysticatea I think it's responsibility of both rules. |
Doesn't |
@mysticatea |
My question is, why |
My proposal is
This avoids breaking changes. one-var{
"one-var": [
"error",
"always" or "never" or "neighbor",
{
"require": "always" or "never" or "neighbor"
}
],
// or
"one-var": [
"error",
{
"initialized": "always" or "never" or "neighbor",
"uninitialized": "always" or "never" or "neighbor"
},
{
"require": "always" or "never" or "neighbor"
}
],
// or
"one-var": [
"error",
{
"var": "always" or "never" or "neighbor",
"let": "always" or "never" or "neighbor",
"const": "always" or "never" or "neighbor"
},
{
"require": "always" or "never" or "neighbor"
}
]
}
/*eslint one-var:["error", "neighbor"]*/
//----------------------------------------------------------------
// Good
let a = 0,
b = 1;
foo();
let c = 2;
//----------------------------------------------------------------
// Bad
let a = 0,
b = 1;
let c = 2; /*eslint one-var:["error", "never", {"require": "always"}]*/
//----------------------------------------------------------------
// Good
let a = require("a"),
b = require("a");
let c = 2;
let d = 3;
//----------------------------------------------------------------
// Bad
let a = 0,
b = 1;
let c = require("c");
let d = require("d"); |
@mysticatea Basically |
hmmm, I think the pretty common pattern is the combination of |
Anyway, I don't like breaking changes. |
Starting to migrate from JSCS/JSHint and I was looking for the equivalent of requireMultipleVarDecl
Unfortunately
one-var
doesn't cover this, as it prevents multiple variable declarations in a single scope. I'm looking for allowing multiple variables throughout the scope, but preventing consecutive var declarations.Invalid:
Valid:
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: