Skip to content

Commit 009e7b0

Browse files
AMorgaututarwyn
andauthored
Add ESLint v9 and flat config support (#51)
Co-authored-by: utarwyn <[email protected]>
1 parent d904503 commit 009e7b0

23 files changed

+142
-65
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ jobs:
5757
- name: Update Docker Compose configuration
5858
run: sed -i -E 's/plugin-(.*).jar/plugin-${{ steps.package-version.outputs.version }}.jar/' docker-compose.yml
5959

60+
- name: Update ESLint plugin version
61+
run: 'sed -i -E ''s/version: "(.*)"/version: "${{ steps.package-version.outputs.version }}"/'' eslint-plugin/lib/standalone.js'
62+
6063
- name: Extract release notes
6164
id: extract-release-notes
6265
uses: ffurrer2/extract-release-notes@v1

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- [#51](https://github.com/green-code-initiative/creedengo-javascript/pull/51) Add ESLint v9 and flat config support
13+
1014
## [2.1.0] - 2025-03-31
1115

1216
### Added
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
3+
/** @type {import('eslint-doc-generator').GenerateOptions} */
4+
const config = {
5+
configEmoji: [["flat/recommended", "✅"]],
6+
postprocess: (doc) => {
7+
return doc.replace(/\s*/gu, "✅");
8+
},
9+
};
10+
11+
module.exports = config;

eslint-plugin/README.md

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ An ESLint plugin which provides JavaScript and TypeScript rules of the Creedengo
88

99
### Installation
1010

11-
You'll need to install [ESLint](https://eslint.org/) (v7 or v8) and this plugin:
11+
You'll need to install [ESLint](https://eslint.org/) (v7+) and this plugin:
1212

1313
```sh
1414
# yarn
@@ -32,19 +32,54 @@ yarn add -D eslint @green-code-initiative/creedengo-eslint-plugin
3232
npm install -D eslint @green-code-initiative/creedengo-eslint-plugin
3333
```
3434

35-
### Enable whole plugin
35+
### Enable plugin with recommended configuration
3636

37-
Add `@creedengo` recommended configuration to `extends` section of your `.eslintrc`:
37+
#### ESLint Flat Configuration (`eslint.config.js`)
3838

39-
```jsonc
39+
Add `@creedengo` **"flat/recommended"** configuration to your `eslint.config.js`:
40+
41+
```js
42+
import creedengo from "@creedengo/eslint-plugin";
43+
44+
export default [
45+
/* other eslint configurations */
46+
creedengo.configs["flat/recommended"],
47+
];
48+
```
49+
50+
#### ESLint deprecated legacy configuration (`.eslintrc`)
51+
52+
For legacy ESLint versions using the deprecated `.eslintrc` file, add the `@creedengo` **"recommended"** configuration to the `extends` array :
53+
54+
```json
4055
{
41-
"extends": ["plugin:@creedengo/recommended"],
56+
"extends": ["plugin:@creedengo/recommended"]
4257
}
4358
```
4459

45-
### Enable only some rules
60+
### Enable specific rules
61+
62+
#### ESLint Flat configuration (`eslint.config.js`)
63+
64+
Add the `creedengo` plugin configuration to your `eslint.config.js` and select the rules to activate:
65+
66+
```js
67+
import creedengo from "@creedengo/eslint-plugin";
68+
69+
export default [
70+
/* other eslint configurations */
71+
{
72+
plugins: { "@creedengo": creedengo },
73+
rules: {
74+
"@creedengo/no-multiple-access-dom-element": "error",
75+
},
76+
},
77+
];
78+
```
79+
80+
#### ESLint deprecated legacy configuration (`.eslintrc`)
4681

47-
Add `@creedengo` to the `plugins` section of your `.eslintrc`, followed by rules configuration:
82+
If your project uses a legacy ESLint version, it may use as well the now deprecated `.eslintrc` file. In such case, add `@creedengo` to the `plugins` array, potentially followed by rules specific configurations:
4883

4984
```jsonc
5085
{
@@ -59,9 +94,10 @@ Add `@creedengo` to the `plugins` section of your `.eslintrc`, followed by rules
5994

6095
<!-- begin auto-generated configs list -->
6196

62-
| | Name |
63-
| :- | :------------ |
64-
|| `recommended` |
97+
| | Name |
98+
| :- | :----------------- |
99+
|| `flat/recommended` |
100+
|| `recommended` |
65101

66102
<!-- end auto-generated configs list -->
67103

@@ -70,25 +106,26 @@ Add `@creedengo` to the `plugins` section of your `.eslintrc`, followed by rules
70106
<!-- begin auto-generated rules list -->
71107

72108
⚠️ Configurations set to warn in.\
109+
✅ Set in the `flat/recommended` configuration.\
73110
✅ Set in the `recommended` configuration.
74111

75-
| Name | Description | ⚠️ |
76-
| :--------------------------------------------------------------------------------------------- | :-------------------------------------------------------- | :- |
77-
| [avoid-autoplay](docs/rules/avoid-autoplay.md) | Avoid autoplay for videos and audio content | |
78-
| [avoid-brightness-override](docs/rules/avoid-brightness-override.md) | Should avoid to override brightness | |
79-
| [avoid-css-animations](docs/rules/avoid-css-animations.md) | Avoid usage of CSS animations | |
80-
| [avoid-high-accuracy-geolocation](docs/rules/avoid-high-accuracy-geolocation.md) | Avoid using high accuracy geolocation in web applications | |
81-
| [avoid-keep-awake](docs/rules/avoid-keep-awake.md) | Avoid screen keep awake | |
82-
| [limit-db-query-results](docs/rules/limit-db-query-results.md) | Should limit the number of returns for a SQL query | |
83-
| [no-empty-image-src-attribute](docs/rules/no-empty-image-src-attribute.md) | Disallow usage of image with empty source attribute | |
84-
| [no-import-all-from-library](docs/rules/no-import-all-from-library.md) | Should not import all from library | |
85-
| [no-multiple-access-dom-element](docs/rules/no-multiple-access-dom-element.md) | Disallow multiple access of same DOM element | |
86-
| [no-multiple-style-changes](docs/rules/no-multiple-style-changes.md) | Disallow multiple style changes at once | |
87-
| [no-torch](docs/rules/no-torch.md) | Should not programmatically enable torch mode | |
88-
| [prefer-collections-with-pagination](docs/rules/prefer-collections-with-pagination.md) | Prefer API collections with pagination | |
89-
| [prefer-lighter-formats-for-image-files](docs/rules/prefer-lighter-formats-for-image-files.md) | Prefer lighter formats for image files | |
90-
| [prefer-shorthand-css-notations](docs/rules/prefer-shorthand-css-notations.md) | Encourage usage of shorthand CSS notations | |
91-
| [provide-print-css](docs/rules/provide-print-css.md) | Enforce providing a print stylesheet | |
112+
| Name | Description | ⚠️ |
113+
| :--------------------------------------------------------------------------------------------- | :-------------------------------------------------------- | :-- |
114+
| [avoid-autoplay](docs/rules/avoid-autoplay.md) | Avoid autoplay for videos and audio content ||
115+
| [avoid-brightness-override](docs/rules/avoid-brightness-override.md) | Should avoid to override brightness ||
116+
| [avoid-css-animations](docs/rules/avoid-css-animations.md) | Avoid usage of CSS animations ||
117+
| [avoid-high-accuracy-geolocation](docs/rules/avoid-high-accuracy-geolocation.md) | Avoid using high accuracy geolocation in web applications ||
118+
| [avoid-keep-awake](docs/rules/avoid-keep-awake.md) | Avoid screen keep awake ||
119+
| [limit-db-query-results](docs/rules/limit-db-query-results.md) | Should limit the number of returns for a SQL query ||
120+
| [no-empty-image-src-attribute](docs/rules/no-empty-image-src-attribute.md) | Disallow usage of image with empty source attribute ||
121+
| [no-import-all-from-library](docs/rules/no-import-all-from-library.md) | Should not import all from library ||
122+
| [no-multiple-access-dom-element](docs/rules/no-multiple-access-dom-element.md) | Disallow multiple access of same DOM element ||
123+
| [no-multiple-style-changes](docs/rules/no-multiple-style-changes.md) | Disallow multiple style changes at once ||
124+
| [no-torch](docs/rules/no-torch.md) | Should not programmatically enable torch mode ||
125+
| [prefer-collections-with-pagination](docs/rules/prefer-collections-with-pagination.md) | Prefer API collections with pagination ||
126+
| [prefer-lighter-formats-for-image-files](docs/rules/prefer-lighter-formats-for-image-files.md) | Prefer lighter formats for image files ||
127+
| [prefer-shorthand-css-notations](docs/rules/prefer-shorthand-css-notations.md) | Encourage usage of shorthand CSS notations ||
128+
| [provide-print-css](docs/rules/provide-print-css.md) | Enforce providing a print stylesheet ||
92129

93130
<!-- end auto-generated rules list -->
94131

eslint-plugin/docs/rules/avoid-autoplay.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Avoid autoplay for videos and audio content (`@creedengo/avoid-autoplay`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`.
44

55
<!-- end auto-generated rule header -->
66

eslint-plugin/docs/rules/avoid-brightness-override.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Should avoid to override brightness (`@creedengo/avoid-brightness-override`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`.
44

55
<!-- end auto-generated rule header -->
66

eslint-plugin/docs/rules/avoid-css-animations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Avoid usage of CSS animations (`@creedengo/avoid-css-animations`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`.
44

55
<!-- end auto-generated rule header -->
66

eslint-plugin/docs/rules/avoid-high-accuracy-geolocation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Avoid using high accuracy geolocation in web applications (`@creedengo/avoid-high-accuracy-geolocation`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`.
44

55
<!-- end auto-generated rule header -->
66

eslint-plugin/docs/rules/avoid-keep-awake.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Avoid screen keep awake (`@creedengo/avoid-keep-awake`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`.
44

55
<!-- end auto-generated rule header -->
66

eslint-plugin/docs/rules/limit-db-query-results.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Should limit the number of returns for a SQL query (`@creedengo/limit-db-query-results`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`.
44

55
<!-- end auto-generated rule header -->
66

0 commit comments

Comments
 (0)