Skip to content

Commit

Permalink
requireNumericLiterals: miss if first argument is an Identifier
Browse files Browse the repository at this point in the history
Prior to this fix, the following would trigger an error:

```
let foo = '123';
parseInt(foo, 16);
```

After this change, an error is only triggered when using an actual
literal (as intended and indicated by the rule name)

Closes jscs-devgh-2133
  • Loading branch information
rwjblue authored and markelog committed Feb 14, 2016
1 parent a14d020 commit c695048
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/require-numeric-literals.js
Expand Up @@ -65,7 +65,8 @@ module.exports.prototype = {

if (node.callee.type === 'Identifier' &&
node.callee.name === 'parseInt' &&
radixName
radixName &&
node.arguments[0].type === 'Literal'
) {
errors.add('Use ' + radixName + ' literals instead of parseInt', node);
}
Expand Down
5 changes: 5 additions & 0 deletions test/specs/rules/require-numeric-literals.js
Expand Up @@ -43,4 +43,9 @@ describe('rules/require-numeric-literals', function() {
it('should not report for non-identifier call', function() {
expect(checker.checkString('a[parseInt](1,2);')).to.have.no.errors();
});

it('should not report on use of parseInt with an identifier for string', function() {
expect(checker.checkString('parseInt(foo);')).to.have.no.errors();
expect(checker.checkString('parseInt(foo, 2);')).to.have.no.errors();
});
});

0 comments on commit c695048

Please sign in to comment.