Skip to content

Commit

Permalink
Update: Add offsetTernaryExpressions option for indent rule
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed Nov 26, 2019
1 parent 33190e9 commit bb4eab5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/rules/indent.md
Expand Up @@ -84,7 +84,7 @@ This rule has an object option:
* `"ObjectExpression"` (default: 1) enforces indentation level for properties in objects. It can be set to the string `"first"`, indicating that all properties in the object should be aligned with the first property. This can also be set to `"off"` to disable checking for object properties.
* `"ImportDeclaration"` (default: 1) enforces indentation level for import statements. It can be set to the string `"first"`, indicating that all imported members from a module should be aligned with the first member in the list. This can also be set to `"off"` to disable checking for imported module members.
* `"flatTernaryExpressions": true` (`false` by default) requires no indentation for ternary expressions which are nested in other ternary expressions.
* `"offsetTernaryExpressions": true` (`false` by default) requires indentation for values of ternary expressions
* `"offsetTernaryExpressions": true` (`false` by default) requires indentation for values of ternary expressions.
* `"ignoredNodes"` accepts an array of [selectors](/docs/developer-guide/selectors.md). If an AST node is matched by any of the selectors, the indentation of tokens which are direct children of that node will be ignored. This can be used as an escape hatch to relax the rule if you disagree with the indentation that it enforces for a particular syntactic pattern.
* `"ignoreComments"` (default: false) can be used when comments do not need to be aligned with nodes on the previous or next line.

Expand Down
41 changes: 41 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -7798,6 +7798,47 @@ ruleTester.run("indent", rule, {
[11, 6, 0, "Punctuator"]
])
},
{
code: unIndent`
condition
? () => {
return true
}
: condition2
? () => {
return true
}
: () => {
return false
}
`,
output: unIndent`
condition
? () => {
return true
}
: condition2
? () => {
return true
}
: () => {
return false
}
`,
options: [2, { offsetTernaryExpressions: false }],
errors: expectedErrors([
[2, 2, 0, "Punctuator"],
[3, 4, 0, "Keyword"],
[4, 2, 0, "Punctuator"],
[5, 2, 0, "Punctuator"],
[6, 4, 0, "Punctuator"],
[7, 6, 0, "Keyword"],
[8, 4, 0, "Punctuator"],
[9, 4, 0, "Punctuator"],
[10, 6, 0, "Keyword"],
[11, 4, 0, "Punctuator"]
])
},
{

/*
Expand Down

0 comments on commit bb4eab5

Please sign in to comment.