From 7c1810e5d9460b7176690765cfa83ef8ea4b41da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Wed, 1 May 2024 10:41:55 +0200 Subject: [PATCH] feat: add deprecation plugin (#45) Start with warn so we can assess impact. --- .github/workflows/nodejs.yml | 14 ++++++++++++++ .prettierignore | 1 + README.md | 5 ++++- base.js | 4 +++- package.json | 7 ++++++- test/notOk.ts | 9 +++++++++ test/test.mjs | 24 ++++++++++++++++++++---- 7 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/nodejs.yml create mode 100644 .prettierignore diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..793698e --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,14 @@ +name: Node.js CI + +on: + push: + branches: + - main + pull_request: + +jobs: + nodejs: + # Documentation: https://github.com/zakodium/workflows#nodejs-ci + uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1 + with: + lint-eslint: false diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1b763b1 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +CHANGELOG.md diff --git a/README.md b/README.md index e5fdbe3..695d374 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,10 @@ npx i -D eslint-config-cheminfo-typescript eslint Create a `.eslintrc.yml` with the following contents: ```yml -extends: [cheminfo-typescript, cheminfo-typescript/jsdoc, cheminfo-typescript/unicorn] +extends: + - cheminfo-typescript + - cheminfo-typescript/jsdoc + - cheminfo-typescript/unicorn ``` You can then customize the config for your project by changing rules in this file. diff --git a/base.js b/base.js index ef44605..572f528 100644 --- a/base.js +++ b/base.js @@ -10,13 +10,15 @@ module.exports = { 'plugin:@typescript-eslint/strict-type-checked', 'plugin:@typescript-eslint/stylistic-type-checked', ], - plugins: ['@typescript-eslint'], + plugins: ['@typescript-eslint', 'deprecation'], parser: '@typescript-eslint/parser', parserOptions: { sourceType: 'module', project: true, }, rules: { + 'deprecation/deprecation': 'warn', + //region specific rules of typescript-eslint // https://typescript-eslint.io/rules/ '@typescript-eslint/array-type': [ diff --git a/package.json b/package.json index 2ad9e6a..b07534b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,10 @@ "unicorn.js" ], "scripts": { - "test": "node test/test.mjs" + "prettier": "prettier --check .", + "prettier-write": "prettier --write .", + "test": "npm run test-only && npm run prettier", + "test-only": "node test/test.mjs" }, "repository": { "type": "git", @@ -30,11 +33,13 @@ "@typescript-eslint/eslint-plugin": "^7.0.1", "@typescript-eslint/parser": "^7.0.1", "eslint": "^8.56.0", + "eslint-plugin-deprecation": "^2.0.0", "typescript": "^5.1.6" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "7.0.1", "@typescript-eslint/parser": "7.0.1", + "eslint-plugin-deprecation": "2.0.0", "eslint": "8.56.0", "prettier": "^3.2.5", "typescript": "5.1.6" diff --git a/test/notOk.ts b/test/notOk.ts index 5c610ff..37b8034 100644 --- a/test/notOk.ts +++ b/test/notOk.ts @@ -11,3 +11,12 @@ function testY(y: (number | string)[]) { } testY([1, 2, 3, '4']); + +deprecatedFn(); + +/** + * @deprecated + */ +function deprecatedFn() { + return 42; +} diff --git a/test/test.mjs b/test/test.mjs index 3fab194..566b8b4 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -21,16 +21,32 @@ assert.strictEqual( 'ok.js should have no warnings: ' + util.format(okResult.messages), ); -const errors = notOkResult.messages - .filter(isError) - .map((error) => error.ruleId) - .sort(); +const errors = notOkResult.messages.filter(isError).map(getRuleId).sort(); assert.deepStrictEqual(errors, [ '@typescript-eslint/array-type', '@typescript-eslint/no-non-null-assertion', '@typescript-eslint/no-unnecessary-type-assertion', ]); +const warnings = notOkResult.messages + .filter(isWarning) + .filter(excludeJsdoc) + .map(getRuleId) + .sort(); +assert.deepStrictEqual(warnings, ['deprecation/deprecation']); + function isError(message) { return message.severity === 2; } + +function isWarning(message) { + return message.severity === 1; +} + +function excludeJsdoc(message) { + return !message.ruleId.startsWith('jsdoc/'); +} + +function getRuleId(message) { + return message.ruleId; +}