Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 9cc27b9

Browse files
rwjbluemarkelog
authored andcommitted
requireNumericLiterals: miss if first argument is an Identifier
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 gh-2133
1 parent 7d30671 commit 9cc27b9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/rules/require-numeric-literals.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ module.exports.prototype = {
6565

6666
if (node.callee.type === 'Identifier' &&
6767
node.callee.name === 'parseInt' &&
68-
radixName
68+
radixName &&
69+
node.arguments[0].type === 'Literal'
6970
) {
7071
errors.add('Use ' + radixName + ' literals instead of parseInt', node.loc.start);
7172
}

test/specs/rules/require-numeric-literals.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ describe('rules/require-numeric-literals', function() {
4444
it('should not report for non-identifier call', function() {
4545
expect(checker.checkString('a[parseInt](1,2);')).to.have.no.errors();
4646
});
47+
48+
it('should not report on use of parseInt with an identifier for string', function() {
49+
expect(checker.checkString('parseInt(foo);')).to.have.no.errors();
50+
expect(checker.checkString('parseInt(foo, 2);')).to.have.no.errors();
51+
});
4752
});

0 commit comments

Comments
 (0)