style(eslint): add eslint-unicorn (#14257)

* style: add eslint-unicorn

* style: fix unicorn/no-useless-spread

* style: fix unicorn/no-useless-promise-resolve-reject

* style: fix unicorn/no-for-loop

* fix: codeql bad HTML filtering regexp

* fix: codeql incomplete replace

* fix: unicorn/no-abusive-eslint-disable

* style: fix unicorn/no-new-array

* style: fix unicorn/no-typeof-undefined

* style: fix unicorn/no-zero-fractions

* style: fix unicorn/no-empty-file

* style: fix unicorn/prefer-date-now

* revert: auto fix unicorn/prefer-switch on lib/v2/kuaidi100/utils.js

* style: fix unicorn/prefer-array-find

* style: fix unicorn/prefer-array-flat

* style: fix unicorn/prefer-array-flat-map

* style: fix unicorn/prefer-at

* style: fix unicorn/prefer-string-starts-ends-with

* style: fix unicorn/prefer-includes

* fix: codeql URL substring sanitization

* style: fix unicorn/prefer-optional-catch-binding

* style: fix unicorn/catch-error-name

* style: fix unicorn/escape-case

* style: fix unicorn/prefer-native-coercion-functions

* style: fix unicorn/prefer-regexp-test

* style: fix unicorn/require-array-join-separator

* style: fix unicorn/prefer-math-trunc

* style: fix unicorn/prefer-negative-index

* style: fix unicorn/prefer-dom-node-dataset

* style: fix unicorn/prefer-dom-node-text-content

* style: fix unicorn/prefer-query-selector

* style: fix unicorn/no-array-for-each

* style: fix unicorn/no-negated-condition

* style: fix unicorn/prefer-add-event-listener

* style: fix unicorn/import-style

* style: fix prefer-regex-literals

* style: disable unicorn/no-useless-switch-case

* style: disable unicorn/text-encoding-identifier-case

* style: fix unicorn/prefer-set-has

* style: fix unicorn/prefer-spread

* revert: auto fix on lib/routes/universities/ynnu/edu/base64.js

* style: fix unicorn/no-useless-undefined

* style: fix unicorn/no-array-push-push

* style: fix unicorn/no-useless-undefined again

* style: fix unicorn/no-lonely-if

* style: fix unicorn/prefer-reflect-apply

* style: fix unicorn/switch-case-braces

* style: fix unicorn/prefer-switch

* style: fix unicorn/prefer-array-some

* fix: deepscan UNUSED_VAR_ASSIGN

* style: fix unicorn/prefer-ternary

* fix: follow-up of unicorn/prefer-ternary

* revert: auto fix of unicorn/prefer-string-slice for substring()

* style: disable unicorn/prefer-string-slice

fix: auto fix slice over deprecated substr

* style: fix unicorn/throw-new-error

* style: fix unicorn/filename-case

* test: fix dateParser renaming

* style: fix unicorn/better-regex

* style: fix unicorn/prefer-string-replace-all

* fix(deps): add sanitize-html

* style: fix no-prototype-builtins

* style: fix unicorn/consistent-destructuring

* style: fix unicorn/consistent-function-scoping

* style: fix unicorn/prefer-regexp-test

* style: fix unicorn/prefer-logical-operator-over-ternary

* style: fix unicorn/no-array-callback-reference

* style: add prefer-object-has-own

* style: warn unicorn/no-empty-file

* style: fix unicorn/prefer-number-properties

* style: fix no-useless-undefined again

* style: fix unicorn/numeric-separators-style

* style: disable unicorn/no-array-callback-reference

false postive with cheerio
This commit is contained in:
Tony
2024-01-18 20:43:40 +08:00
committed by GitHub
parent cd00220d98
commit 6d901cb7dc
1652 changed files with 6334 additions and 6435 deletions
+3 -3
View File
@@ -13,14 +13,14 @@ const files = ['lib/index.js', 'api/vercel.js'].map((file) => path.join(projectR
const { fileList: fileSet } = await nodeFileTrace(files, {
base: projectRoot,
});
let fileList = Array.from(fileSet);
let fileList = [...fileSet];
console.log('Total touchable files:', fileList.length);
fileList = fileList.filter((file) => file.startsWith('node_modules/')); // only need node_modules
console.log('Total files need to be copied (touchable files in node_modules/):', fileList.length);
console.log('Start copying files, destination:', resultFolder);
return Promise.all(fileList.map((e) => fs.copy(path.join(projectRoot, e), path.join(resultFolder, e))));
})().catch((err) => {
})().catch((error) => {
// fix unhandled promise rejections
console.error(err, err.stack);
console.error(error, error.stack);
process.exit(1);
});
+2 -2
View File
@@ -108,9 +108,9 @@ function generateOne() {
const oldAccounts = fs.readFileSync(path.join(__dirname, 'accounts.txt'));
const tokens = oldAccounts.toString().split('\n')[0].split('=')[1].split(',');
const secrets = oldAccounts.toString().split('\n')[1].split('=')[1].split(',');
for (let i = 0; i < tokens.length; i++) {
for (const [i, token] of tokens.entries()) {
accounts.push({
t: tokens[i],
t: token,
s: secrets[i],
});
}
+3 -3
View File
@@ -5,9 +5,9 @@ const maintainer = require(path.join(__dirname, '../../lib/maintainer.js'));
const count = Object.keys(maintainer).length;
const uniqueMaintainer = new Set();
Object.values(maintainer)
.flat()
.forEach((e) => uniqueMaintainer.add(e));
for (const e of Object.values(maintainer).flat()) {
uniqueMaintainer.add(e);
}
// eslint-disable-next-line no-console
console.log(`We have ${count} routes and maintained by ${uniqueMaintainer.size} contributors!`);
+11 -12
View File
@@ -31,7 +31,7 @@ async function parseBodyRoutes(body, core) {
}
if (routes) {
routes = routes.split(/\r?\n/).filter((n) => n);
routes = routes.split(/\r?\n/).filter(Boolean);
const dedup = [...new Set(routes)];
if (dedup.length !== routes.length) {
core.warning('Duplication detected.');
@@ -40,7 +40,7 @@ async function parseBodyRoutes(body, core) {
return dedup;
}
throw Error('unable to parse the issue body: route does not exist');
throw new Error('unable to parse the issue body: route does not exist');
}
async function getMaintainersByRoutes(routes, core) {
@@ -73,8 +73,8 @@ module.exports = async ({ github, context, core }) => {
...issue_facts,
labels,
})
.catch((e) => {
core.warning(e);
.catch((error) => {
core.warning(error);
});
const updateIssueState = (state) =>
github.rest.issues
@@ -82,16 +82,16 @@ module.exports = async ({ github, context, core }) => {
...issue_facts,
state,
})
.catch((e) => {
core.warning(e);
.catch((error) => {
core.warning(error);
});
if (context.payload.issue.state === 'closed') {
await updateIssueState('open');
}
const routes = await parseBodyRoutes(body, core).catch((e) => {
core.warning(e);
const routes = await parseBodyRoutes(body, core).catch((error) => {
core.warning(error);
});
if (routes === null) {
@@ -110,8 +110,7 @@ module.exports = async ({ github, context, core }) => {
let failedCount = 0;
let comments = '##### Searching for maintainers: \n\n';
for (let i = 0; i < routes.length; i++) {
const route = routes[i];
for (const [i, route] of routes.entries()) {
const main = maintainers[i];
if (main === undefined) {
comments += `- \`${route}\`: **Route not found**\n`;
@@ -171,8 +170,8 @@ module.exports = async ({ github, context, core }) => {
If all routes can not be found, the issue will be closed automatically. Please use \`NOROUTE\` for a route-irrelevant issue or leave a comment if it is a mistake.
`,
})
.catch((e) => {
core.warning(e);
.catch((error) => {
core.warning(error);
});
if (failedCount && emptyCount === 0 && successCount === 0) {
+14 -14
View File
@@ -1,10 +1,10 @@
const noFound = 'Auto: Route No Found';
const allowedUser = ['dependabot[bot]', 'pull[bot]']; // dependabot and downstream PR requested by pull[bot]
const allowedUser = new Set(['dependabot[bot]', 'pull[bot]']); // dependabot and downstream PR requested by pull[bot]
module.exports = async ({ github, context, core }, body, number, sender) => {
core.debug(`sender: ${sender}`);
core.debug(`body: ${body}`);
const m = body.match(/```routes\s+([\s\S]*?)```/);
const m = body.match(/```routes\s+([\S\s]*?)```/);
core.debug(`match: ${m}`);
let res = null;
@@ -25,8 +25,8 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
...issueFacts,
labels,
})
.catch((e) => {
core.warning(e);
.catch((error) => {
core.warning(error);
});
const removeLabel = () =>
@@ -35,8 +35,8 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
...issueFacts,
name: noFound,
})
.catch((e) => {
core.warning(e);
.catch((error) => {
core.warning(error);
});
const updatePrState = (state) =>
@@ -45,8 +45,8 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
...prFacts,
state,
})
.catch((e) => {
core.warning(e);
.catch((error) => {
core.warning(error);
});
const createComment = (body) =>
@@ -55,8 +55,8 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
...issueFacts,
body,
})
.catch((e) => {
core.warning(e);
.catch((error) => {
core.warning(error);
});
const createFailedComment = () => {
@@ -75,14 +75,14 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
.get({
...issueFacts,
})
.catch((e) => {
core.warning(e);
.catch((error) => {
core.warning(error);
});
if (pr.pull_request && pr.state === 'closed') {
await updatePrState('open');
}
if (allowedUser.includes(sender)) {
if (allowedUser.has(sender)) {
core.info('PR created by a allowed user, passing');
await removeLabel();
await addLabels(['Auto: allowed']);
@@ -116,5 +116,5 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
await updatePrState('closed');
}
throw Error('Please follow the PR rules: failed to detect route');
throw new Error('Please follow the PR rules: failed to detect route');
};
+8 -8
View File
@@ -29,15 +29,15 @@ module.exports = async ({ github, context, core, got }, baseUrl, routes, number)
const res = await got(lks);
if (res && res.body) {
success = true;
detail = res.body.replace(/\s+(\n|$)/g, '\n');
detail = res.body.replaceAll(/\s+(\n|$)/g, '\n');
}
} catch (err) {
} catch (error) {
// TODO: change me when https://github.com/actions/github-script is run on node20
// detail = `HTTPError: Response code ${err.status} (${err.statusText})`;
// const res = await err.text();
// const errInfoList = err.body && res.match(/(?<=<pre class="message">)(.+?)(?=<\/pre>)/gs);
detail = err.toString();
const errInfoList = err.response && err.response.body && err.response.body.match(/(?<=<pre class="message">)(.+?)(?=<\/pre>)/gs);
detail = error.toString();
const errInfoList = error.response && error.response.body && error.response.body.match(/(?<=<pre class="message">)(.+?)(?=<\/pre>)/gs);
if (errInfoList) {
detail += '\n\n';
detail += errInfoList
@@ -82,8 +82,8 @@ ${detail.slice(0, 65300 - temp_com.length)}
repo: context.repo.repo,
labels: ['Auto: Route Test Complete'],
})
.catch((e) => {
core.warning(e);
.catch((error) => {
core.warning(error);
});
}
@@ -96,8 +96,8 @@ ${detail.slice(0, 65300 - temp_com.length)}
repo: context.repo.repo,
body: com_s,
})
.catch((e) => {
core.warning(e);
.catch((error) => {
core.warning(error);
});
}
};