Files
renovate/tools/lint/rules/no-number-constructor.ts
Jamie Tanna 021612414c fix(lint): use parseInt over Number (#45472)
* fix(lint): use `parseInt` over `Number`

As a code review comment that comes up every so often, we can add a
linting rule to enforce this check.

This also fixes any existing usages.

As this could be breaking, we can release it as a `fix`.

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! fix(lint): use `parseInt` over `Number`

* fixup! fix(lint): use `parseInt` over `Number`

---------

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-08-26 13:02:26 +00:00

32 lines
741 B
TypeScript

import { defineRule } from '@oxlint/plugins';
export default defineRule({
meta: {
type: 'problem',
messages: {
noNumberConstructor:
"Use parseInt(x, 10) instead of the 'Number' constructor.",
},
},
createOnce(context) {
return {
CallExpression(node) {
if (
node.callee.type === 'Identifier' &&
node.callee.name === 'Number'
) {
context.report({ node, messageId: 'noNumberConstructor' });
}
},
NewExpression(node) {
if (
node.callee.type === 'Identifier' &&
node.callee.name === 'Number'
) {
context.report({ node, messageId: 'noNumberConstructor' });
}
},
};
},
});