Skip to content

Commit 9aca7b9

Browse files
authored
Remove use of node.{range,loc} (#2790)
1 parent 2e27981 commit 9aca7b9

28 files changed

+59
-57
lines changed

eslint.dogfooding.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const config = [
1010
// If external rules needs to be disabled, add the rule name here.
1111
'n/no-unsupported-features/es-syntax',
1212
'eslint-plugin/require-meta-default-options',
13-
'internal/no-restricted-property-access',
1413
'@stylistic/max-len',
1514
]),
1615
{

rules/catch-error-name.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const create = context => {
9595
};
9696

9797
if (fixedName) {
98-
problem.fix = fixer => renameVariable(variable, fixedName, fixer);
98+
problem.fix = fixer => renameVariable(variable, fixedName, context, fixer);
9999
}
100100

101101
return problem;

rules/escape-case.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const create = context => {
5656
node,
5757
original: node.value.raw,
5858
lowercase,
59-
fix: (fixer, fixed) => replaceTemplateElement(fixer, node, fixed),
59+
fix: (fixer, fixed) => replaceTemplateElement(node, fixed, context, fixer),
6060
});
6161
});
6262
};

rules/fix/rename-variable.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import getVariableIdentifiers from '../utils/get-variable-identifiers.js';
22
import replaceReferenceIdentifier from './replace-reference-identifier.js';
33

4-
const renameVariable = (variable, name, fixer) => getVariableIdentifiers(variable)
5-
.map(identifier => replaceReferenceIdentifier(identifier, name, fixer));
4+
const renameVariable = (variable, name, context, fixer) =>
5+
getVariableIdentifiers(variable)
6+
.map(identifier => replaceReferenceIdentifier(identifier, name, context, fixer));
67

78
export default renameVariable;

rules/fix/replace-reference-identifier.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ import isShorthandPropertyAssignmentPatternLeft from '../utils/is-shorthand-prop
33
import isShorthandImportLocal from '../utils/is-shorthand-import-local.js';
44
import isShorthandExportLocal from '../utils/is-shorthand-export-local.js';
55

6-
export default function replaceReferenceIdentifier(identifier, replacement, fixer) {
6+
export default function replaceReferenceIdentifier(identifier, replacement, context, fixer) {
77
if (
88
isShorthandPropertyValue(identifier)
99
|| isShorthandPropertyAssignmentPatternLeft(identifier)
1010
) {
1111
return fixer.replaceText(identifier, `${identifier.name}: ${replacement}`);
1212
}
1313

14-
if (isShorthandImportLocal(identifier)) {
14+
if (isShorthandImportLocal(identifier, context)) {
1515
return fixer.replaceText(identifier, `${identifier.name} as ${replacement}`);
1616
}
1717

18-
if (isShorthandExportLocal(identifier)) {
18+
if (isShorthandExportLocal(identifier, context)) {
1919
return fixer.replaceText(identifier, `${replacement} as ${identifier.name}`);
2020
}
2121

2222
// `typeAnnotation`
2323
if (identifier.typeAnnotation) {
24+
const {sourceCode} = context;
2425
return fixer.replaceTextRange(
25-
// eslint-disable-next-line internal/no-restricted-property-access
26-
[identifier.range[0], identifier.typeAnnotation.range[0]],
26+
[sourceCode.getRange(identifier)[0], sourceCode.getRange(identifier.typeAnnotation)[0]],
2727
`${replacement}${identifier.optional ? '?' : ''}`,
2828
);
2929
}

rules/fix/replace-string-raw.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// Replace `StringLiteral` or `TemplateLiteral` node with raw text
2-
const replaceStringRaw = (fixer, node, raw) =>
2+
const replaceStringRaw = (node, raw, context, fixer) =>
33
fixer.replaceTextRange(
44
// Ignore quotes and backticks
55
[
6-
// eslint-disable-next-line internal/no-restricted-property-access
7-
node.range[0] + 1,
8-
// eslint-disable-next-line internal/no-restricted-property-access
9-
node.range[1] - 1,
6+
context.sourceCode.getRange(node)[0] + 1,
7+
context.sourceCode.getRange(node)[1] - 1,
108
],
119
raw,
1210
);

rules/fix/replace-template-element.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const replaceTemplateElement = (fixer, node, replacement) => {
2-
// eslint-disable-next-line internal/no-restricted-property-access
3-
const {range: [start, end], tail} = node;
1+
const replaceTemplateElement = (node, replacement, context, fixer) => {
2+
const {tail} = node;
3+
const [start, end] = context.sourceCode.getRange(node);
44
return fixer.replaceTextRange(
55
[start + 1, end - (tail ? 1 : 2)],
66
replacement,

rules/fix/switch-new-expression-to-call-expression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function * switchNewExpressionToCallExpression(newExpression, con
3434
}
3535
```
3636
*/
37-
if (!isOnSameLine(newToken, newExpression.callee) && !isParenthesized(newExpression, context.sourceCode)) {
37+
if (!isOnSameLine(newToken, newExpression.callee, context) && !isParenthesized(newExpression, context.sourceCode)) {
3838
// Ideally, we should use first parenthesis of the `callee`, and should check spaces after the `new` token
3939
// But adding extra parentheses is harmless, no need to be too complicated
4040
yield * addParenthesizesToReturnOrThrowExpression(fixer, newExpression.parent, context);

rules/no-hex-escape.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function checkEscape(context, node, value) {
1515
messageId: MESSAGE_ID,
1616
fix: fixer =>
1717
node.type === 'TemplateElement'
18-
? replaceTemplateElement(fixer, node, fixedValue)
18+
? replaceTemplateElement(node, fixedValue, context, fixer)
1919
: fixer.replaceText(node, fixedValue),
2020
};
2121
}

rules/no-negated-condition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const create = context => {
111111
if (
112112
(parent.type === 'ReturnStatement' || parent.type === 'ThrowStatement')
113113
&& parent.argument === node
114-
&& !isOnSameLine(firstToken, secondToken)
114+
&& !isOnSameLine(firstToken, secondToken, context)
115115
&& !isParenthesized(node, sourceCode)
116116
&& !isParenthesized(test, sourceCode)
117117
) {

0 commit comments

Comments
 (0)