Enable unicorn/prefer-string-slice (#7251)
This commit is contained in:
1 parent
d6a51d34dd
commit
c0517441b2
10 files changed
+23
-16
No files matched your search
@@ -58,6 +58,7 @@ rules:
|
||||
- exceptRange: true
|
||||
unicorn/new-for-builtins: error
|
||||
unicorn/prefer-includes: error
|
||||
unicorn/prefer-string-slice: error
|
||||
overrides:
|
||||
- files:
|
||||
- scripts/**/*.js
|
||||
|
||||
@@ -22,7 +22,7 @@ module.exports = function(babel) {
|
||||
if (isEvalRequire(node.callee) && node.arguments.length === 1) {
|
||||
let arg = node.arguments[0];
|
||||
if (t.isLiteral(arg) && arg.value.startsWith(".")) {
|
||||
const value = "." + arg.value.substring(arg.value.lastIndexOf("/"));
|
||||
const value = "." + arg.value.slice(arg.value.lastIndexOf("/"));
|
||||
arg = t.stringLiteral(value);
|
||||
}
|
||||
path.replaceWith(t.callExpression(t.identifier("require"), [arg]));
|
||||
|
||||
@@ -356,7 +356,7 @@ function parseNestedCSS(node, options) {
|
||||
const defaultSCSSDirectiveIndex = value.match(DEFAULT_SCSS_DIRECTIVE);
|
||||
|
||||
if (defaultSCSSDirectiveIndex) {
|
||||
value = value.substring(0, defaultSCSSDirectiveIndex.index);
|
||||
value = value.slice(0, defaultSCSSDirectiveIndex.index);
|
||||
node.scssDefault = true;
|
||||
|
||||
if (defaultSCSSDirectiveIndex[0].trim() !== "!default") {
|
||||
@@ -367,7 +367,7 @@ function parseNestedCSS(node, options) {
|
||||
const globalSCSSDirectiveIndex = value.match(GLOBAL_SCSS_DIRECTIVE);
|
||||
|
||||
if (globalSCSSDirectiveIndex) {
|
||||
value = value.substring(0, globalSCSSDirectiveIndex.index);
|
||||
value = value.slice(0, globalSCSSDirectiveIndex.index);
|
||||
node.scssGlobal = true;
|
||||
|
||||
if (globalSCSSDirectiveIndex[0].trim() !== "!global") {
|
||||
@@ -454,7 +454,7 @@ function parseNestedCSS(node, options) {
|
||||
const customSelector = params.match(/:--\S+?\s+/)[0].trim();
|
||||
|
||||
node.customSelector = customSelector;
|
||||
node.selector = parseSelector(params.substring(customSelector.length));
|
||||
node.selector = parseSelector(params.slice(customSelector.length));
|
||||
delete node.params;
|
||||
|
||||
return node;
|
||||
|
||||
@@ -534,7 +534,7 @@ function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
|
||||
}
|
||||
|
||||
const index = getNextNonSpaceNonCommentCharacterIndex(text, comment, options);
|
||||
if (text.substr(index, 2) === "=>") {
|
||||
if (text.slice(index, index + 2) === "=>") {
|
||||
addDanglingComment(enclosingNode, comment);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -525,7 +525,7 @@ function needsParens(path, options) {
|
||||
// See corresponding workaround in printer.js case: "Literal"
|
||||
((options.parser !== "typescript" && !parent.directive) ||
|
||||
(options.parser === "typescript" &&
|
||||
options.originalText.substr(options.locStart(node) - 1, 1) === "("))
|
||||
options.originalText.charAt(options.locStart(node) - 1) === "("))
|
||||
) {
|
||||
// To avoid becoming a directive
|
||||
const grandParent = path.getParentNode(1);
|
||||
|
||||
@@ -835,7 +835,10 @@ function printPathNoParens(path, options, print, args) {
|
||||
comment,
|
||||
options
|
||||
);
|
||||
return options.originalText.substr(nextCharacter, 2) === "=>";
|
||||
return (
|
||||
options.originalText.slice(nextCharacter, nextCharacter + 2) ===
|
||||
"=>"
|
||||
);
|
||||
}
|
||||
);
|
||||
if (dangling) {
|
||||
@@ -1191,7 +1194,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
path.call(print, "callee"),
|
||||
optional,
|
||||
isIdentifierWithFlowAnnotation
|
||||
? `/*:: ${n.callee.trailingComments[0].value.substring(2).trim()} */`
|
||||
? `/*:: ${n.callee.trailingComments[0].value.slice(2).trim()} */`
|
||||
: "",
|
||||
printFunctionTypeParameters(path, options, print),
|
||||
printArgumentsList(path, options, print)
|
||||
@@ -3034,7 +3037,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
value.typeAnnotation &&
|
||||
value.typeAnnotation.range &&
|
||||
options.originalText
|
||||
.substring(value.typeAnnotation.range[0])
|
||||
.slice(value.typeAnnotation.range[0])
|
||||
.match(/^\/\*\s*:/);
|
||||
return concat([
|
||||
"(",
|
||||
@@ -3051,13 +3054,13 @@ function printPathNoParens(path, options, print, args) {
|
||||
case "TypeParameterInstantiation": {
|
||||
const value = path.getValue();
|
||||
const commentStart = value.range
|
||||
? options.originalText.substring(0, value.range[0]).lastIndexOf("/*")
|
||||
? options.originalText.slice(0, value.range[0]).lastIndexOf("/*")
|
||||
: -1;
|
||||
// As noted in the TypeCastExpression comments above, we're able to use a normal whitespace regex here
|
||||
// because we know for sure that this is a type definition.
|
||||
const commentSyntax =
|
||||
commentStart >= 0 &&
|
||||
options.originalText.substring(commentStart).match(/^\/\*\s*::/);
|
||||
options.originalText.slice(commentStart).match(/^\/\*\s*::/);
|
||||
if (commentSyntax) {
|
||||
return concat([
|
||||
"/*:: ",
|
||||
@@ -6054,8 +6057,9 @@ function printComment(commentPath, options) {
|
||||
return printed;
|
||||
}
|
||||
|
||||
const commentEnd = options.locEnd(comment);
|
||||
const isInsideFlowComment =
|
||||
options.originalText.substr(options.locEnd(comment) - 3, 3) === "*-/";
|
||||
options.originalText.slice(commentEnd - 3, commentEnd) === "*-/";
|
||||
|
||||
return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
|
||||
}
|
||||
|
||||
@@ -645,7 +645,9 @@ function isLastStatement(path) {
|
||||
function isFlowAnnotationComment(text, typeAnnotation, options) {
|
||||
const start = options.locStart(typeAnnotation);
|
||||
const end = skipWhitespace(text, options.locEnd(typeAnnotation));
|
||||
return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
|
||||
return (
|
||||
text.slice(start, start + 2) === "/*" && text.slice(end, end + 2) === "*/"
|
||||
);
|
||||
}
|
||||
|
||||
function hasLeadingOwnLineComment(text, node, options) {
|
||||
|
||||
@@ -74,7 +74,7 @@ function embed(path, print, textToDoc, options) {
|
||||
language.name.toLowerCase() === lang ||
|
||||
(language.aliases && language.aliases.includes(lang)) ||
|
||||
(language.extensions &&
|
||||
language.extensions.find(ext => ext.substring(1) === lang))
|
||||
language.extensions.find(ext => ext === `.${lang}`))
|
||||
);
|
||||
if (language) {
|
||||
return language.parsers[0];
|
||||
|
||||
+1
-1
@@ -321,7 +321,7 @@ function format(text, opts) {
|
||||
|
||||
const hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM;
|
||||
if (hasUnicodeBOM) {
|
||||
text = text.substring(1);
|
||||
text = text.slice(1);
|
||||
if (hasCursor) {
|
||||
opts.cursorOffset++;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/* eslint-env browser */
|
||||
|
||||
if (location.hash.substring(1).startsWith(encodeURIComponent("{"))) {
|
||||
if (location.hash.slice(1).startsWith(encodeURIComponent("{"))) {
|
||||
location.pathname = "/playground/";
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user