Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
feat: add deprecation/recommended configuration (#69)
Browse files Browse the repository at this point in the history
Allows to use simplified `deprecation/recommended` configuration:
```json
{
"extends": [
    "plugin:deprecation/recommended",
  ]
}
```

Closes #68
  • Loading branch information
gund authored Jul 27, 2023
2 parents 1dd6818 + 8466194 commit 4b482c0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
60 changes: 41 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,79 @@
[![Npm](https://img.shields.io/npm/v/eslint-plugin-deprecation.svg)](https://www.npmjs.com/package/eslint-plugin-deprecation)
[![Npm Downloads](https://img.shields.io/npm/dt/eslint-plugin-deprecation.svg)](https://www.npmjs.com/package/eslint-plugin-deprecation)
![Size](https://badgen.net/bundlephobia/minzip/eslint-plugin-deprecation)
[![Licence](https://img.shields.io/npm/l/eslint-plugin-deprecation.svg?maxAge=2592000)](https://github.com/gund/eslint-plugin-deprecation/blob/master/LICENSE)
[![License](https://img.shields.io/npm/l/eslint-plugin-deprecation.svg?maxAge=2592000)](https://github.com/gund/eslint-plugin-deprecation/blob/master/LICENSE)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

> ESLint rule that reports usage of deprecated code
> An [ESLint](https://eslint.org/) rule that reports usage of deprecated code.
## Prerequisites

This plugin only works with `@typescript-eslint/parser`.
If you already use [TypeScript](https://www.typescriptlang.org/) and one or more rules from the [`typescript-eslint`](https://typescript-eslint.io/) plugin, then `eslint-plugin-deprecation` will work out of the box without any additional dependencies or special configuration specified in this section. (This is because `@typescript-eslint/plugin` automatically contains `@typescript-eslint/parser` and your ESLint should already be configured with the `parserOptions` to work properly with TypeScript.)

Which means that you should install dev deps:
Otherwise, in order for you to use this plugin, you must also install the following dependencies:

- `@typescript-eslint/parser`
- `typescript`
- `@typescript-eslint/parser`

For example, if you use the `npm` package manager, then you would run the following command in the root of your project:

```sh
npm install --save-dev typescript @typescript-eslint/parser
```

Then configure ESLint to parse TypeScript and include type information:
Next, you must configure ESLint to parse TypeScript and include type information:

```jsonc
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"project": "./tsconfig.json" // <-- Point to your project's tsconfig.json or create new one
"project": "./tsconfig.json" // <-- Point to your project's "tsconfig.json" or create a new one.
}
}
```

## Install

Install the plugin
For example, if you use the `npm` package manager, then you would run the following command in the root of your project:

```
npm i -D eslint-plugin-deprecation
```sh
npm install --save-dev eslint-plugin-deprecation
```

## Setup

Now add deprecation plugin and rule to your `.eslintrc`:
### Using the `recommended` Config

The easiest way to use this plugin is to extend from the `recommended` config, like this:

```jsonc
{
"plugins": ["deprecation", ...],
"rules": {
"deprecation/deprecation": "warn", // or "error" to have stricter rule
...
}
"extends": [
"plugin:deprecation/recommended",
],
}
```

Now eslint will report all deprecated code that you use!
The `recommended` config will enable the plugin and enable the rule with a value of `error`.

### Manually Enable the Plugin and Rule

If you don't want to use the `recommended` config for some reason, you can accomplish the same thing by specifying the following config:

```jsonc
{
"plugins": [
"deprecation",
],

"rules": {
"deprecation/deprecation": "error",
},
}
```

---
## Credits

_NOTE:_ This rule was ported from https://github.com/SonarSource/SonarJS repository.
This rule was originally ported from [SonarJS repository](https://github.com/SonarSource/SonarJS).
3 changes: 3 additions & 0 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import recommended from './recommended';

export { recommended };
8 changes: 8 additions & 0 deletions src/configs/recommended.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const recommended = {
plugins: ['deprecation'],
rules: {
'deprecation/deprecation': 'error',
},
};

export default recommended;
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as rules from './rules';
import * as configs from './configs';

export { rules };
export { configs, rules };

0 comments on commit 4b482c0

Please sign in to comment.