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

Commit 3b22580

Browse files
authored
Export "meta" for plugin (#472)
1 parent 7e23a07 commit 3b22580

File tree

7 files changed

+244
-430
lines changed

7 files changed

+244
-430
lines changed

Diff for: README.md

+21-10
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Code Smells, or maintainability issues, are raised for places of code which migh
8282
## Prerequisites
8383

8484
- Node.js (>=16.x).
85-
- ESLint 5.x, 6.x, 7.x or 8.x (peer dependency for the plugin).
85+
- ESLint 8.x or 9.x (peer dependency for the plugin).
8686

8787
## Usage
8888

@@ -94,25 +94,35 @@ npm install eslint-plugin-sonarjs --save-dev # install for your project
9494
npm install eslint-plugin-sonarjs -g # or install globally
9595
```
9696

97-
- Add `eslint-plugin-sonarjs` to the `plugins` option of your `.eslintrc`:
97+
- Add `eslint-plugin-sonarjs` to the plugins of your ESLint config.
9898

99-
```json
100-
{
101-
"plugins": ["sonarjs"]
102-
}
99+
For ESLint 9: add `plugins` option to your `eslint.config.js` and include the recommended config to enable all rules:
100+
101+
```code
102+
import sonarjs from "eslint-plugin-sonarjs";
103+
104+
[
105+
sonarjs.configs.recommended,
106+
{
107+
"plugins": {
108+
sonarjs,
109+
}
110+
}
111+
]
103112
```
104113

105-
- Add `plugin:sonarjs/recommended` to the `extends` option to enable all recommended rules:
114+
For ESLint 8: add `plugins` option to your `.eslintrc` and `plugin:sonarjs/recommended` to the `extends` option to enable all recommended rules:
106115

107116
```json
108117
{
109-
"extends": ["plugin:sonarjs/recommended"]
118+
"plugins": ["sonarjs"],
119+
"extends": ["plugin:sonarjs/recommended-legacy"]
110120
}
111121
```
112122

113123
- or enable only some rules manually:
114124

115-
```javascript
125+
```json
116126
{
117127
"rules": {
118128
"sonarjs/cognitive-complexity": "error",
@@ -122,11 +132,12 @@ npm install eslint-plugin-sonarjs -g # or install globally
122132
}
123133
```
124134

125-
- To enable all rules of this plugin, use `@typescript-eslint/parser` as a parser for ESLint ([like we do](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/6e06d59a233e07b28fbbd6398e08b9b0c63b18f9/.eslintrc.js#L4)) and set the [parserOptions.project](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#parseroptionsproject) option. Thanks to it, type information is available, which is beneficial or even essential for some rules.
135+
- To allow each of the rules to fully perform, use `@typescript-eslint/parser` as a parser for ESLint ([like we do](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/6e06d59a233e07b28fbbd6398e08b9b0c63b18f9/.eslintrc.js#L4)) and set the [parserOptions.project](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#parseroptionsproject) option. Thanks to it, type information is available, which is beneficial or even essential for some rules.
126136

127137
## Available Configurations
128138

129139
This plugin provides only a `recommended` configuration. Almost all rules are activated in this profile with a few exceptions (check the `disabled` tag in the rules list). The `recommended` configuration activates rules with `error` severity.
140+
We include a `recommended-legacy` configuration to be backward compatible with ESLint v8, with the same rule configuration..
130141

131142
## ESLint and Sonar
132143

0 commit comments

Comments
 (0)