From c5f792425383bc75e3b9d773abd4577e2154d0c9 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Fri, 6 Jan 2023 17:49:26 +0300 Subject: [PATCH] chore(eslint): Store custom eslint-plugin locally (#19698) --- package.json | 2 +- tools/eslint/index.js | 51 +++++++++++++++++++++++++++++++++++++++ tools/eslint/package.json | 5 ++++ yarn.lock | 4 +-- 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 tools/eslint/index.js create mode 100644 tools/eslint/package.json diff --git a/package.json b/package.json index 8bc0addc74..2f0401ad92 100644 --- a/package.json +++ b/package.json @@ -245,7 +245,7 @@ "@jest/test-result": "29.3.1", "@ls-lint/ls-lint": "1.11.2", "@openpgp/web-stream-tools": "0.0.13", - "@renovate/eslint-plugin": "https://github.com/renovatebot/eslint-plugin#v0.0.5", + "@renovate/eslint-plugin": "file:./tools/eslint", "@semantic-release/exec": "6.0.3", "@types/auth-header": "1.0.2", "@types/aws4": "1.11.2", diff --git a/tools/eslint/index.js b/tools/eslint/index.js new file mode 100644 index 0000000000..00a5942d11 --- /dev/null +++ b/tools/eslint/index.js @@ -0,0 +1,51 @@ +module.exports = { + rules: { + 'jest-root-describe': { + meta: { + fixable: 'code', + }, + /** + * @param {{ getFilename: () => any; report: (arg0: { node: any; message: string; fix(fixer: any): any; }) => void; }} context + */ + create(context) { + const absoluteFileName = context.getFilename(); + if (!absoluteFileName.endsWith('.spec.ts')) { + return {}; + } + const relativeFileName = absoluteFileName + .replace(process.cwd(), '') + .replace(/\\/g, '/') + .replace(/^(?:\/(?:lib|src|test))?\//, ''); + const testName = String(relativeFileName.replace(/\.spec\.ts$/, '')); + return { + /** + * @param {{ parent?: any; arguments?: any; callee?: any; }} node + */ + CallExpression(node) { + const { callee } = node; + if ( + callee.type === 'Identifier' && + callee.name === 'describe' && + node.parent.parent.type === 'Program' + ) { + const [descr] = node.arguments; + const isOkay = + descr.type === 'Literal' && + typeof descr.value === 'string' && + testName === descr.value; + if (!isOkay) { + context.report({ + node: descr, + message: `Test must be described by this string: '${testName}'`, + fix(fixer) { + return fixer.replaceText(descr, `'${testName}'`); + }, + }); + } + } + }, + }; + }, + }, + }, +}; diff --git a/tools/eslint/package.json b/tools/eslint/package.json new file mode 100644 index 0000000000..901f171b7b --- /dev/null +++ b/tools/eslint/package.json @@ -0,0 +1,5 @@ +{ + "name": "@renovatebot/eslint-plugin", + "version": "0.0.0", + "main": "index.js" +} diff --git a/yarn.lock b/yarn.lock index c49f3910b4..1107c0f033 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2447,10 +2447,8 @@ resolved "https://registry.yarnpkg.com/@redis/time-series/-/time-series-1.0.4.tgz#af85eb080f6934580e4d3b58046026b6c2b18717" integrity sha512-ThUIgo2U/g7cCuZavucQTQzA9g9JbDDY2f64u3AbAoz/8vE2lt2U37LamDUVChhaDA3IRT9R6VvJwqnUfTJzng== -"@renovate/eslint-plugin@https://github.com/renovatebot/eslint-plugin#v0.0.5": +"@renovate/eslint-plugin@file:./tools/eslint": version "0.0.5" - uid "1923e2e2776549cb25a2c6ea09915ee31bff6d05" - resolved "https://github.com/renovatebot/eslint-plugin#1923e2e2776549cb25a2c6ea09915ee31bff6d05" "@renovatebot/osv-offline-db@1.0.1": version "1.0.1" -- GitLab