chore: remove all .substring() usage (#6352)

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
This commit is contained in:
CommanderRoot 2022-03-30 13:25:12 +02:00 committed by GitHub
parent 59b9348093
commit ad82a0f0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 12 additions and 21 deletions

View File

@ -88,7 +88,7 @@ async function prepareTestBitBucketRepo({ lfs }) {
// postfix a random string to avoid collisions // postfix a random string to avoid collisions
const postfix = Math.random() const postfix = Math.random()
.toString(32) .toString(32)
.substring(2); .slice(2);
const testRepoName = `${repo}-${Date.now()}-${postfix}`; const testRepoName = `${repo}-${Date.now()}-${postfix}`;
console.log('Creating repository', testRepoName); console.log('Creating repository', testRepoName);

View File

@ -61,7 +61,7 @@ async function prepareTestGitHubRepo() {
// postfix a random string to avoid collisions // postfix a random string to avoid collisions
const postfix = Math.random() const postfix = Math.random()
.toString(32) .toString(32)
.substring(2); .slice(2);
const testRepoName = `${repo}-${Date.now()}-${postfix}`; const testRepoName = `${repo}-${Date.now()}-${postfix}`;
const client = getGitHubClient(token); const client = getGitHubClient(token);

View File

@ -52,7 +52,7 @@ async function prepareTestGitLabRepo() {
// postfix a random string to avoid collisions // postfix a random string to avoid collisions
const postfix = Math.random() const postfix = Math.random()
.toString(32) .toString(32)
.substring(2); .slice(2);
const testRepoName = `${repo}-${Date.now()}-${postfix}`; const testRepoName = `${repo}-${Date.now()}-${postfix}`;
const client = getGitLabClient(token); const client = getGitLabClient(token);

View File

@ -61,7 +61,7 @@ let serverProcess;
async function setupProxy(options) { async function setupProxy(options) {
const postfix = Math.random() const postfix = Math.random()
.toString(32) .toString(32)
.substring(2); .slice(2);
const testRepoName = `proxy-test-repo-${Date.now()}-${postfix}`; const testRepoName = `proxy-test-repo-${Date.now()}-${postfix}`;
const tempDir = path.join('.temp', testRepoName); const tempDir = path.join('.temp', testRepoName);

View File

@ -36,8 +36,7 @@ const parsers = {
let JSONoutput = jsonFormatter.toFile(metadata).trim(); let JSONoutput = jsonFormatter.toFile(metadata).trim();
// Trim leading and trailing brackets. // Trim leading and trailing brackets.
if (JSONoutput.slice(0, 1) === '{' && JSONoutput.slice(-1) === '}') { if (JSONoutput.slice(0, 1) === '{' && JSONoutput.slice(-1) === '}') {
// eslint-disable-next-line unicorn/prefer-string-slice JSONoutput = JSONoutput.slice(1, -1);
JSONoutput = JSONoutput.substring(1, JSONoutput.length - 1);
} }
return JSONoutput; return JSONoutput;
}, },
@ -55,8 +54,8 @@ const parsers = {
}; };
function inferFrontmatterFormat(str: string) { function inferFrontmatterFormat(str: string) {
// eslint-disable-next-line unicorn/prefer-string-slice const lineEnd = str.indexOf('\n');
const firstLine = str.substring(0, str.indexOf('\n')).trim(); const firstLine = str.slice(0, lineEnd !== -1 ? lineEnd : 0).trim();
if (firstLine.length > 3 && firstLine.slice(0, 3) === '---') { if (firstLine.length > 3 && firstLine.slice(0, 3) === '---') {
// No need to infer, `gray-matter` will handle things like `---toml` for us. // No need to infer, `gray-matter` will handle things like `---toml` for us.
return; return;
@ -132,8 +131,7 @@ export class FrontmatterFormatter {
comments, comments,
...format, ...format,
}); });
// eslint-disable-next-line unicorn/prefer-string-slice return trimLastLineBreak && file.slice(-1) === '\n' ? file.slice(0, -1) : file;
return trimLastLineBreak && file.slice(-1) === '\n' ? file.substring(0, file.length - 1) : file;
} }
} }

View File

@ -7,6 +7,5 @@ export function stringToRGB(str) {
const c = (hash & 0x00ffffff).toString(16).toUpperCase(); const c = (hash & 0x00ffffff).toString(16).toUpperCase();
// eslint-disable-next-line unicorn/prefer-string-slice return `00000${c}`.slice(-6);
return '00000'.substring(0, 6 - c.length) + c;
} }

View File

@ -319,11 +319,7 @@ export default function withFileControl({ forImage } = {}) {
if (!value || value.length <= size) { if (!value || value.length <= size) {
return value; return value;
} }
// eslint-disable-next-line unicorn/prefer-string-slice const text = `${value.slice(0, size / 2)}\u2026${value.slice(-(size / 2) + 1)}`;
const text = `${value.substring(0, size / 2)}\u2026${value.substring(
value.length - size / 2 + 1,
value.length,
)}`;
return ( return (
<FileLink href={value} rel="noopener" target="_blank"> <FileLink href={value} rel="noopener" target="_blank">
{text} {text}

View File

@ -177,10 +177,8 @@ export default function slateToRemark(raw, { voidCodeBlock }) {
const index = node.text.search(exp); const index = node.text.search(exp);
if (index > -1) { if (index > -1) {
const substringIndex = trailing ? index : index + 1; const substringIndex = trailing ? index : index + 1;
// eslint-disable-next-line unicorn/prefer-string-slice const firstSplit = node.text.slice(0, substringIndex);
const firstSplit = node.text.substring(0, substringIndex); const secondSplit = node.text.slice(substringIndex);
// eslint-disable-next-line unicorn/prefer-string-slice
const secondSplit = node.text.substring(substringIndex);
const whitespace = trailing ? secondSplit : firstSplit; const whitespace = trailing ? secondSplit : firstSplit;
const text = trailing ? firstSplit : secondSplit; const text = trailing ? firstSplit : secondSplit;
return { whitespace, trimmedNode: { ...node, text } }; return { whitespace, trimmedNode: { ...node, text } };