Skip to content

Commit

Permalink
Fix: Make MemberExpression option opt-in (fixes #6797) (#6798)
Browse files Browse the repository at this point in the history
The `MemberExpression` option should be opt-in as it is a breaking
change.
  • Loading branch information
Trott authored and gyandeeps committed Aug 1, 2016
1 parent 715e8fa commit c7488ac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/rules/indent.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ This rule has an object option:
* `"SwitchCase"` (default: 0) enforces indentation level for `case` clauses in `switch` statements
* `"VariableDeclarator"` (default: 1) enforces indentation level for `var` declarators; can also take an object to define separate rules for `var`, `let` and `const` declarations.
* `"outerIIFEBody"` (default: 1) enforces indentation level for file-level IIFEs.
* `"MemberExpression"` (default: 1) enforces indentation level for multi-line property chains
* `"MemberExpression"` (off by default) enforces indentation level for multi-line property chains

Level of indentation denotes the multiple of the indent specified. Example:

Expand Down
7 changes: 5 additions & 2 deletions lib/rules/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ module.exports = {
let: DEFAULT_VARIABLE_INDENT,
const: DEFAULT_VARIABLE_INDENT
},
outerIIFEBody: null,
MemberExpression: 1
outerIIFEBody: null
};

let sourceCode = context.getSourceCode();
Expand Down Expand Up @@ -809,6 +808,10 @@ module.exports = {
},

MemberExpression: function(node) {
if (typeof options.MemberExpression === "undefined") {
return;
}

if (isSingleLineNode(node)) {
return;
}
Expand Down
32 changes: 24 additions & 8 deletions tests/lib/rules/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1344,38 +1344,51 @@ ruleTester.run("indent", rule, {
},
{
code:
"Buffer.length"
"Buffer.length",
options: [4, { MemberExpression: 1 }]
},
{
code:
"Buffer\n" +
" .indexOf('a')\n" +
" .toString()"
" .toString()",
options: [4, { MemberExpression: 1 }]
},
{
code:
"Buffer.\n" +
" length"
" length",
options: [4, { MemberExpression: 1 }]
},
{
code:
"Buffer\n" +
" .foo\n" +
" .bar"
" .bar",
options: [4, { MemberExpression: 1 }]
},
{
code:
"Buffer\n" +
"\t.foo\n" +
"\t.bar",
options: ["tab"]
options: ["tab", { MemberExpression: 1 }]
},
{
code:
"Buffer\n" +
" .foo\n" +
" .bar",
options: [2, {MemberExpression: 2}]
},
{
code:
"MemberExpression\n" +
".is" +
" .off" +
" .by" +
" .default();",
options: [4]
}
],
invalid: [
Expand Down Expand Up @@ -1428,7 +1441,7 @@ ruleTester.run("indent", rule, {
{
code: fixture,
output: fixedFixture,
options: [2, {SwitchCase: 1}],
options: [2, {SwitchCase: 1, MemberExpression: 1}],
errors: expectedErrors([
[5, 2, 4, "VariableDeclaration"],
[10, 4, 6, "BlockStatement"],
Expand Down Expand Up @@ -2370,6 +2383,7 @@ ruleTester.run("indent", rule, {
output:
"Buffer\n" +
" .toString()",
options: [4, { MemberExpression: 1 }],
errors: expectedErrors([[2, 4, 0, "Punctuator"]])
},
{
Expand All @@ -2381,6 +2395,7 @@ ruleTester.run("indent", rule, {
"Buffer\n" +
" .indexOf('a')\n" +
" .toString()",
options: [4, { MemberExpression: 1 }],
errors: expectedErrors([[3, 4, 0, "Punctuator"]])
},
{
Expand All @@ -2390,6 +2405,7 @@ ruleTester.run("indent", rule, {
output:
"Buffer.\n" +
" length",
options: [4, { MemberExpression: 1 }],
errors: expectedErrors([[2, 4, 0, "Identifier"]])
},
{
Expand All @@ -2399,7 +2415,7 @@ ruleTester.run("indent", rule, {
output:
"Buffer.\n" +
"\tlength",
options: ["tab"],
options: ["tab", { MemberExpression: 1 }],
errors: expectedErrors("tab", [[2, 1, 2, "Identifier"]])
},
{
Expand All @@ -2411,7 +2427,7 @@ ruleTester.run("indent", rule, {
"Buffer\n" +
" .foo\n" +
" .bar",
options: [2, {MemberExpression: 2}],
options: [2, { MemberExpression: 2 }],
errors: expectedErrors([[2, 4, 2, "Punctuator"], [3, 4, 2, "Punctuator"]])
}
]
Expand Down

0 comments on commit c7488ac

Please sign in to comment.