Skip to content

Commit 9dbabb6

Browse files
committed
fix(rules): removed switch from 'no-shadowing' check
1 parent 5841eff commit 9dbabb6

File tree

3 files changed

+2
-21
lines changed

3 files changed

+2
-21
lines changed

docs/rules/no-shadowing.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var $ = 1;
2424
var a = 2, $$ = 3;
2525
for (var by = 0; by < 10; ++by) {}
2626
try { json = JSON.parse(input) } catch (browser) {}
27-
switch (element) { case 1: break; default: break; }
2827
```
2928

3029
The following patterns are not warnings:
@@ -37,5 +36,4 @@ var elm = $(".myclass");
3736
var elements = $$(".myclass");
3837
for (var i = 0; i < 10; ++i) {}
3938
try { json = JSON.parse(input) } catch (e) {}
40-
switch (a) { case 1: break; default: break; }
4139
```

lib/rules/no-shadowing.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,12 @@ module.exports = function (context) {
2222
context.report(node, 'Unexpected Protractor built-in global variable shadowing')
2323
}
2424
}
25-
26-
// handling switch manually - getDeclaredVariables() does not return the switch discriminant
27-
if (node.type === 'SwitchStatement' && node.discriminant) {
28-
if (protractorGlobals.indexOf(node.discriminant.name) !== -1) {
29-
context.report(node, 'Unexpected Protractor built-in global variable shadowing')
30-
}
31-
}
3225
}
3326

3427
return {
3528
'VariableDeclaration': checkVariables,
3629
'FunctionDeclaration': checkVariables,
3730
'FunctionExpression': checkVariables,
38-
'CatchClause': checkVariables,
39-
'SwitchStatement': checkVariables
31+
'CatchClause': checkVariables
4032
}
4133
}

test/rules/no-shadowing.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ eslintTester.run('no-shadowing', rule, {
1313
'var elm = $(".myclass");',
1414
'var elements = $$(".myclass");',
1515
'for (var i = 0; i < variables.length; ++i) {}',
16-
'try { json = JSON.parse(input) } catch (e) {}',
17-
'switch (a) { case 1: break; default: break; }'
16+
'try { json = JSON.parse(input) } catch (e) {}'
1817
],
1918

2019
invalid: [
@@ -81,14 +80,6 @@ eslintTester.run('no-shadowing', rule, {
8180
message: 'Unexpected Protractor built-in global variable shadowing'
8281
}
8382
]
84-
},
85-
{
86-
code: 'switch (element) { case 1: break; default: break; }',
87-
errors: [
88-
{
89-
message: 'Unexpected Protractor built-in global variable shadowing'
90-
}
91-
]
9283
}
9384
]
9485
})

0 commit comments

Comments
 (0)