Skip to content

Commit

Permalink
fix(rules): removed switch from 'no-shadowing' check
Browse files Browse the repository at this point in the history
  • Loading branch information
alecxe committed Jun 22, 2016
1 parent 5841eff commit 9dbabb6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 21 deletions.
2 changes: 0 additions & 2 deletions docs/rules/no-shadowing.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var $ = 1;
var a = 2, $$ = 3;
for (var by = 0; by < 10; ++by) {}
try { json = JSON.parse(input) } catch (browser) {}
switch (element) { case 1: break; default: break; }
```

The following patterns are not warnings:
Expand All @@ -37,5 +36,4 @@ var elm = $(".myclass");
var elements = $$(".myclass");
for (var i = 0; i < 10; ++i) {}
try { json = JSON.parse(input) } catch (e) {}
switch (a) { case 1: break; default: break; }
```
10 changes: 1 addition & 9 deletions lib/rules/no-shadowing.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,12 @@ module.exports = function (context) {
context.report(node, 'Unexpected Protractor built-in global variable shadowing')
}
}

// handling switch manually - getDeclaredVariables() does not return the switch discriminant
if (node.type === 'SwitchStatement' && node.discriminant) {
if (protractorGlobals.indexOf(node.discriminant.name) !== -1) {
context.report(node, 'Unexpected Protractor built-in global variable shadowing')
}
}
}

return {
'VariableDeclaration': checkVariables,
'FunctionDeclaration': checkVariables,
'FunctionExpression': checkVariables,
'CatchClause': checkVariables,
'SwitchStatement': checkVariables
'CatchClause': checkVariables
}
}
11 changes: 1 addition & 10 deletions test/rules/no-shadowing.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ eslintTester.run('no-shadowing', rule, {
'var elm = $(".myclass");',
'var elements = $$(".myclass");',
'for (var i = 0; i < variables.length; ++i) {}',
'try { json = JSON.parse(input) } catch (e) {}',
'switch (a) { case 1: break; default: break; }'
'try { json = JSON.parse(input) } catch (e) {}'
],

invalid: [
Expand Down Expand Up @@ -81,14 +80,6 @@ eslintTester.run('no-shadowing', rule, {
message: 'Unexpected Protractor built-in global variable shadowing'
}
]
},
{
code: 'switch (element) { case 1: break; default: break; }',
errors: [
{
message: 'Unexpected Protractor built-in global variable shadowing'
}
]
}
]
})

0 comments on commit 9dbabb6

Please sign in to comment.