diff --git a/package.json b/package.json index 8bc0addc7471abfcf9cfa154660b93d3a8c2b96e..2f0401ad92aef13795af8514444aac19a30cfa4a 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 0000000000000000000000000000000000000000..00a5942d1125b509863f432f9089d96ed59f6a8f --- /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 0000000000000000000000000000000000000000..901f171b7b0af8519c6d9f4133442b44a5904dae --- /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 c49f3910b446a575cd7f022f73c355e02b0437ea..1107c0f03358f061d245232bdf1eb951f1276356 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"