Skip to content

Commit 26e9578

Browse files
committed
[Refactor] use slice instead of substring
1 parent 1629d44 commit 26e9578

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

lib/rules/jsx-curly-brace-presence.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ module.exports = {
184184
if (parentType === 'JSXAttribute') {
185185
textToReplace = `"${expressionType === 'TemplateLiteral'
186186
? expression.quasis[0].value.raw
187-
: expression.raw.substring(1, expression.raw.length - 1)
187+
: expression.raw.slice(1, -1)
188188
}"`;
189189
} else if (jsxUtil.isJSX(expression)) {
190190
const sourceCode = context.getSourceCode();
@@ -222,7 +222,7 @@ module.exports = {
222222

223223
const expression = literalNode.parent.type === 'JSXAttribute'
224224
? `{"${escapeDoubleQuotes(escapeBackslashes(
225-
literalNode.raw.substring(1, literalNode.raw.length - 1)
225+
literalNode.raw.slice(1, -1)
226226
))}"}`
227227
: wrapWithCurlyBraces(literalNode.raw);
228228

lib/rules/jsx-sort-props.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function generateFixerFunction(node, context, reservedList) {
250250
sortableAttributeGroups.forEach((sortableGroup, ii) => {
251251
sortableGroup.forEach((attr, jj) => {
252252
const sortedAttr = sortedAttributeGroups[ii][jj];
253-
const sortedAttrText = source.substring(sortedAttr.range[0], attributeMap.get(sortedAttr).end);
253+
const sortedAttrText = source.slice(sortedAttr.range[0], attributeMap.get(sortedAttr).end);
254254
fixers.push({
255255
range: [attr.range[0], attributeMap.get(attr).end],
256256
text: sortedAttrText,
@@ -266,10 +266,10 @@ function generateFixerFunction(node, context, reservedList) {
266266
const rangeEnd = firstFixer ? firstFixer.range[1] : -0;
267267

268268
fixers.forEach((fix) => {
269-
source = `${source.substr(0, fix.range[0])}${fix.text}${source.substr(fix.range[1])}`;
269+
source = `${source.slice(0, fix.range[0])}${fix.text}${source.slice(fix.range[1])}`;
270270
});
271271

272-
return fixer.replaceTextRange([rangeStart, rangeEnd], source.substr(rangeStart, rangeEnd - rangeStart));
272+
return fixer.replaceTextRange([rangeStart, rangeEnd], source.slice(rangeStart, rangeEnd));
273273
};
274274
}
275275

lib/rules/no-unescaped-entities.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = {
9393
if (i === node.loc.end.line) {
9494
end = node.loc.end.column;
9595
}
96-
rawLine = rawLine.substring(start, end);
96+
rawLine = rawLine.slice(start, end);
9797
for (let j = 0; j < entities.length; j++) {
9898
for (let index = 0; index < rawLine.length; index++) {
9999
const c = rawLine[index];

lib/util/propTypesSort.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,8 @@ function fixPropTypesSort(
181181
source = nodes.reduceRight((acc, attr, index) => {
182182
const sortedAttr = sortedAttributes[index];
183183
const sourceCodeText = sourceCode.getText();
184-
let sortedAttrText = sourceCodeText.substring(
185-
commentnodeMap.get(sortedAttr).start,
186-
commentnodeMap.get(sortedAttr).end
187-
);
184+
const commentNode = commentnodeMap.get(sortedAttr);
185+
let sortedAttrText = sourceCodeText.slice(commentNode.start, commentNode.end);
188186
if (sortShapeProp && isShapeProp(sortedAttr.value)) {
189187
const shape = getShapeProperties(sortedAttr.value);
190188
if (shape) {

0 commit comments

Comments
 (0)