Skip to content

Commit e9e33cf

Browse files
authored
Merge pull request #1496 from timothykang/fix-node-range
Replace node.start/node.end with node.range[0]/node.range[1], respectively
2 parents 06f93e2 + 99b78a7 commit e9e33cf

9 files changed

+18
-18
lines changed

lib/rules/jsx-closing-bracket-location.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ module.exports = {
232232

233233
'JSXOpeningElement:exit': function(node) {
234234
const attributeNode = lastAttributeNode[getOpeningElementId(node)];
235-
const cachedLastAttributeEndPos = attributeNode ? attributeNode.end : null;
235+
const cachedLastAttributeEndPos = attributeNode ? attributeNode.range[1] : null;
236236
let expectedNextLine;
237237
const tokens = getTokensLocations(node);
238238
const expectedLocation = getExpectedLocation(tokens);
@@ -260,18 +260,18 @@ module.exports = {
260260
switch (expectedLocation) {
261261
case 'after-tag':
262262
if (cachedLastAttributeEndPos) {
263-
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
263+
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.range[1]],
264264
(expectedNextLine ? '\n' : '') + closingTag);
265265
}
266-
return fixer.replaceTextRange([node.name.range[1], node.end],
266+
return fixer.replaceTextRange([node.name.range[1], node.range[1]],
267267
(expectedNextLine ? '\n' : ' ') + closingTag);
268268
case 'after-props':
269-
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
269+
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.range[1]],
270270
(expectedNextLine ? '\n' : '') + closingTag);
271271
case 'props-aligned':
272272
case 'tag-aligned':
273273
case 'line-aligned':
274-
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
274+
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.range[1]],
275275
`\n${getIndentation(tokens, expectedLocation, correctColumn)}${closingTag}`);
276276
default:
277277
return true;

lib/rules/jsx-closing-tag-location.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module.exports = {
7373
const indent = Array(opening.loc.start.column + 1).join(' ');
7474
if (isNodeFirstInLine(node)) {
7575
return fixer.replaceTextRange(
76-
[node.start - node.loc.start.column, node.start],
76+
[node.range[0] - node.loc.start.column, node.range[0]],
7777
indent
7878
);
7979
}

lib/rules/jsx-equals-spacing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = {
5959
loc: equalToken.loc.start,
6060
message: 'There should be no space before \'=\'',
6161
fix: function(fixer) {
62-
return fixer.removeRange([attrNode.name.range[1], equalToken.start]);
62+
return fixer.removeRange([attrNode.name.range[1], equalToken.range[0]]);
6363
}
6464
});
6565
}
@@ -69,7 +69,7 @@ module.exports = {
6969
loc: equalToken.loc.start,
7070
message: 'There should be no space after \'=\'',
7171
fix: function(fixer) {
72-
return fixer.removeRange([equalToken.end, attrNode.value.range[0]]);
72+
return fixer.removeRange([equalToken.range[1], attrNode.value.range[0]]);
7373
}
7474
});
7575
}

lib/rules/jsx-first-prop-new-line.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = {
4242
node: decl,
4343
message: 'Property should be placed on a new line',
4444
fix: function(fixer) {
45-
return fixer.replaceTextRange([node.name.end, decl.start], '\n');
45+
return fixer.replaceTextRange([node.name.end, decl.range[0]], '\n');
4646
}
4747
});
4848
}
@@ -55,7 +55,7 @@ module.exports = {
5555
node: firstNode,
5656
message: 'Property should be placed on the same line as the component declaration',
5757
fix: function(fixer) {
58-
return fixer.replaceTextRange([node.name.end, firstNode.start], ' ');
58+
return fixer.replaceTextRange([node.name.end, firstNode.range[0]], ' ');
5959
}
6060
});
6161
return;

lib/rules/jsx-indent-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module.exports = {
9797
message: MESSAGE,
9898
data: msgContext,
9999
fix: function(fixer) {
100-
return fixer.replaceTextRange([node.start - node.loc.start.column, node.start],
100+
return fixer.replaceTextRange([node.range[0] - node.loc.start.column, node.range[0]],
101101
Array(needed + 1).join(indentType === 'space' ? ' ' : '\t'));
102102
}
103103
});

lib/rules/jsx-indent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports = {
8181
return function(fixer) {
8282
const indent = Array(needed + 1).join(indentChar);
8383
return fixer.replaceTextRange(
84-
[node.start - node.loc.start.column, node.start],
84+
[node.range[0] - node.loc.start.column, node.range[0]],
8585
indent
8686
);
8787
};
@@ -225,7 +225,7 @@ module.exports = {
225225
}
226226
// Use the parent in a list or an array
227227
if (prevToken.type === 'JSXText' || prevToken.type === 'Punctuator' && prevToken.value === ',') {
228-
prevToken = sourceCode.getNodeByRangeIndex(prevToken.start);
228+
prevToken = sourceCode.getNodeByRangeIndex(prevToken.range[0]);
229229
prevToken = prevToken.type === 'Literal' ? prevToken.parent : prevToken;
230230
// Use the first non-punctuator token in a conditional expression
231231
} else if (prevToken.type === 'Punctuator' && prevToken.value === ':') {

lib/rules/jsx-max-props-per-line.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ module.exports = {
4747

4848
function generateFixFunction(line, max) {
4949
const output = [];
50-
const front = line[0].start;
51-
const back = line[line.length - 1].end;
50+
const front = line[0].range[0];
51+
const back = line[line.length - 1].range[1];
5252
for (let i = 0; i < line.length; i += max) {
5353
const nodes = line.slice(i, i + max);
5454
output.push(nodes.reduce((prev, curr) => {

lib/rules/jsx-sort-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const generateFixerFunction = (node, context) => {
102102
const sortedAttr = sortedAttributeGroups[ii][jj];
103103
const sortedAttrText = sourceCode.getText(sortedAttr);
104104
fixers.push(
105-
fixer.replaceTextRange([attr.start, attr.end], sortedAttrText)
105+
fixer.replaceTextRange([attr.range[0], attr.range[1]], sortedAttrText)
106106
);
107107
});
108108
});

lib/rules/self-closing-comp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ module.exports = {
7777
message: 'Empty components are self-closing',
7878
fix: function(fixer) {
7979
// Represents the last character of the JSXOpeningElement, the '>' character
80-
const openingElementEnding = node.end - 1;
80+
const openingElementEnding = node.range[1] - 1;
8181
// Represents the last character of the JSXClosingElement, the '>' character
82-
const closingElementEnding = node.parent.closingElement.end;
82+
const closingElementEnding = node.parent.closingElement.range[1];
8383

8484
// Replace />.*<\/.*>/ with '/>'
8585
const range = [openingElementEnding, closingElementEnding];

0 commit comments

Comments
 (0)