Skip to content

Commit

Permalink
feat: add deprecation plugin (#45)
Browse files Browse the repository at this point in the history
Start with warn so we can assess impact.
  • Loading branch information
targos authored May 1, 2024
1 parent 0bcca25 commit 7c1810e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 7 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions test/notOk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ function testY(y: (number | string)[]) {
}

testY([1, 2, 3, '4']);

deprecatedFn();

/**
* @deprecated
*/
function deprecatedFn() {
return 42;
}
24 changes: 20 additions & 4 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 7c1810e

Please sign in to comment.