docs: {
description: "Enforce the consistent use of the radix argument when using `parseInt()`",
recommended: false,
- url: "https://eslint.org/docs/rules/radix"
+ url: "https://eslint.org/docs/latest/rules/radix"
},
hasSuggestions: true,
create(context) {
const mode = context.options[0] || MODE_ALWAYS;
+ const sourceCode = context.sourceCode;
/**
* Checks the arguments of a given CallExpression node and reports it if it
{
messageId: "addRadixParameter10",
fix(fixer) {
- const sourceCode = context.getSourceCode();
const tokens = sourceCode.getTokens(node);
const lastToken = tokens[tokens.length - 1]; // Parenthesis.
const secondToLastToken = tokens[tokens.length - 2]; // May or may not be a comma.
}
return {
- "Program:exit"() {
- const scope = context.getScope();
+ "Program:exit"(node) {
+ const scope = sourceCode.getScope(node);
let variable;
// Check `parseInt()`
variable = astUtils.getVariableByName(scope, "parseInt");
if (variable && !isShadowed(variable)) {
variable.references.forEach(reference => {
- const node = reference.identifier;
+ const idNode = reference.identifier;
- if (astUtils.isCallee(node)) {
- checkArguments(node.parent);
+ if (astUtils.isCallee(idNode)) {
+ checkArguments(idNode.parent);
}
});
}
variable = astUtils.getVariableByName(scope, "Number");
if (variable && !isShadowed(variable)) {
variable.references.forEach(reference => {
- const node = reference.identifier.parent;
- const maybeCallee = node.parent.type === "ChainExpression"
- ? node.parent
- : node;
+ const parentNode = reference.identifier.parent;
+ const maybeCallee = parentNode.parent.type === "ChainExpression"
+ ? parentNode.parent
+ : parentNode;
- if (isParseIntMethod(node) && astUtils.isCallee(maybeCallee)) {
+ if (isParseIntMethod(parentNode) && astUtils.isCallee(maybeCallee)) {
checkArguments(maybeCallee.parent);
}
});