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
New: add option first
for VariableDeclarator in indent (fixes #8976)
#11193
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -522,25 +522,13 @@ module.exports = { | |
}, | ||
VariableDeclarator: { | ||
oneOf: [ | ||
{ | ||
type: "integer", | ||
minimum: 0 | ||
}, | ||
ELEMENT_LIST_SCHEMA, | ||
{ | ||
type: "object", | ||
properties: { | ||
var: { | ||
type: "integer", | ||
minimum: 0 | ||
}, | ||
let: { | ||
type: "integer", | ||
minimum: 0 | ||
}, | ||
const: { | ||
type: "integer", | ||
minimum: 0 | ||
} | ||
var: ELEMENT_LIST_SCHEMA, | ||
let: ELEMENT_LIST_SCHEMA, | ||
const: ELEMENT_LIST_SCHEMA | ||
}, | ||
additionalProperties: false | ||
} | ||
|
@@ -661,7 +649,7 @@ module.exports = { | |
if (context.options[1]) { | ||
lodash.merge(options, context.options[1]); | ||
|
||
if (typeof options.VariableDeclarator === "number") { | ||
if (typeof options.VariableDeclarator === "number" || options.VariableDeclarator === "first") { | ||
options.VariableDeclarator = { | ||
var: options.VariableDeclarator, | ||
let: options.VariableDeclarator, | ||
|
@@ -1385,6 +1373,15 @@ module.exports = { | |
if (astUtils.isSemicolonToken(lastToken)) { | ||
offsets.ignoreToken(lastToken); | ||
} | ||
|
||
if (options.VariableDeclarator[node.kind] === "first") { | ||
addElementListIndent( | ||
node.declarations, | ||
sourceCode.getFirstToken(node), | ||
sourceCode.getLastToken(node), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of It might not be necessary to change this because the last token would be indented properly later on (e.g. in the let foo = 1,
bar = 2,
baz let
foo let foo = 1,
bar =
2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you expect the cases above are reporting warnings or not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, they should be valid. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added those test cases. See the latest commit please. |
||
"first" | ||
); | ||
} | ||
}, | ||
|
||
VariableDeclarator(node) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For performance, it might be better to skip the lines above (starting with
if (node.declarations...
on line 1344) when the offset isfirst
, because those lines would have no effect.