Skip to content

Commit 0f49380

Browse files
Support ESLint v9 (#13)
2 parents 9d4a0db + 63c7666 commit 0f49380

41 files changed

Lines changed: 6822 additions & 14269 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Smoke Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout the repository
17+
uses: actions/checkout@v4
18+
19+
- name: Setup environment
20+
uses: prezly/setup-github-actions@v1
21+
with:
22+
pnpm: 9.7.0
23+
node: 20
24+
25+
- name: Install dependencies
26+
run: pnpm install
27+
28+
- name: Run ESLint on should-fail
29+
id: eslint_should_fail
30+
run: |
31+
cd tests/should-fail
32+
pnpm lint
33+
lint_exit_code=$?
34+
echo "The exit code of pnpm lint for should-fail is: $lint_exit_code"
35+
echo "lint_exit_code=$lint_exit_code" >> $GITHUB_ENV
36+
continue-on-error: true
37+
38+
- name: Evaluate ESLint result for should-fail
39+
run: |
40+
if [ -n "$lint_exit_code" ]; then
41+
echo "ESLint for should-fail passed unexpectedly. Marking this as a failure."
42+
exit 1
43+
else
44+
echo "ESLint for should-fail failed as expected. Marking this as a success."
45+
exit 0
46+
fi
47+
env:
48+
lint_exit_code: ${{ env.lint_exit_code }}
49+
50+
- name: Run ESLint on should-pass
51+
id: eslint_should_pass
52+
run: |
53+
cd tests/should-pass
54+
pnpm lint
55+
lint_exit_code=$?
56+
echo "The exit code of pnpm lint for should-pass is: $lint_exit_code"
57+
echo "lint_exit_code=$lint_exit_code" >> $GITHUB_ENV
58+
continue-on-error: true
59+
60+
- name: Evaluate ESLint result for should-pass
61+
run: |
62+
if [ "$lint_exit_code" -eq 0 ]; then
63+
echo "ESLint for should-pass passed as expected. Marking this as a success."
64+
exit 0
65+
else
66+
echo "ESLint for should-pass failed unexpectedly. Marking this as a failure."
67+
exit 1
68+
fi
69+
env:
70+
lint_exit_code: ${{ env.lint_exit_code }}

lib/index.js

Lines changed: 119 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,130 @@
1-
const importOrderConfig = require("./rule-configs/import-order/base.js");
2-
const namingConventionConfig = require("./rule-configs/naming-convention/base.js");
1+
//@ts-check
2+
import importOrderConfig from "./rule-configs/import-order/base.js";
3+
import namingConventionConfig from "./rule-configs/naming-convention/base.js";
4+
import typescriptEslintPlugin from "@typescript-eslint/eslint-plugin";
5+
import prettierPlugin from "eslint-plugin-prettier";
6+
import sortExportAllPlugin from "eslint-plugin-sort-export-all";
7+
import js from "@eslint/js";
8+
import globals from "globals";
9+
import tseslint from "typescript-eslint";
10+
import eslintConfigPrettier from "eslint-config-prettier";
311

4-
module.exports = {
5-
env: {
6-
browser: true,
7-
es2021: true,
8-
node: true,
12+
//@ts-ignore -- Package provides no types.
13+
import reactRefresh from "eslint-plugin-react-refresh";
14+
//@ts-ignore -- Package provides no types.
15+
import importPlugin from "eslint-plugin-import";
16+
17+
export default tseslint.config(
18+
{
19+
ignores: ["dist"],
920
},
10-
extends: ["airbnb-base", "airbnb-typescript/base", "prettier"],
11-
parser: "@typescript-eslint/parser",
12-
parserOptions: {
13-
ecmaFeatures: {
14-
jsx: true,
21+
{
22+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
23+
files: ["**/*.{ts,tsx,js,jsx,mjs}"],
24+
languageOptions: {
25+
ecmaVersion: 2020,
26+
parserOptions: {
27+
projectService: true,
28+
},
29+
globals: {
30+
...globals.browser,
31+
...globals.node,
32+
},
33+
},
34+
plugins: {
35+
"react-refresh": reactRefresh,
36+
},
37+
rules: {
38+
"react-refresh/only-export-components": [
39+
"warn",
40+
{ allowConstantExport: true },
41+
],
1542
},
16-
ecmaVersion: 12,
17-
sourceType: "module",
18-
project: ["./tsconfig.json"],
1943
},
20-
plugins: [
21-
"@typescript-eslint",
22-
"prettier",
23-
"import",
24-
"sort-export-all",
25-
"deprecation",
26-
],
27-
rules: {
28-
// Prettier handles indent, whitespace and empty lines
29-
"prettier/prettier": 2,
44+
{
45+
plugins: {
46+
"@typescript-eslint": typescriptEslintPlugin,
47+
prettier: prettierPlugin,
48+
import: importPlugin,
49+
"sort-export-all": sortExportAllPlugin,
50+
},
51+
rules: {
52+
// Prettier rules
53+
"prettier/prettier": 2,
3054

31-
// Warn about deprecated methods and properties
32-
"deprecation/deprecation": "warn",
55+
// Warn about deprecated methods and properties
56+
"@typescript-eslint/no-deprecated": "warn",
3357

34-
// Import rules
35-
"sort-export-all/sort-export-all": [
36-
"error",
37-
"asc",
38-
{
39-
caseSensitive: false,
40-
natural: false,
41-
},
42-
],
43-
"import/extensions": [
44-
"error",
45-
"never",
46-
{ svg: "always", json: "always", css: "always", scss: "always" },
47-
],
48-
"import/order": ["error", importOrderConfig],
49-
"import/prefer-default-export": "off",
50-
"import/no-default-export": "error",
51-
"import/no-extraneous-dependencies": "error",
52-
"sort-imports": [
53-
"error",
54-
{
55-
ignoreCase: true,
56-
ignoreDeclarationSort: true,
57-
ignoreMemberSort: false,
58-
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
59-
},
60-
],
58+
// Import rules
59+
"sort-export-all/sort-export-all": [
60+
"error",
61+
"asc",
62+
{
63+
caseSensitive: false,
64+
natural: false,
65+
},
66+
],
67+
"import/extensions": [
68+
"error",
69+
"never",
70+
{
71+
svg: "always",
72+
json: "always",
73+
css: "always",
74+
scss: "always",
75+
},
76+
],
77+
"import/order": ["error", importOrderConfig],
78+
"import/prefer-default-export": "off",
79+
"import/no-default-export": "error",
80+
"import/no-extraneous-dependencies": "error",
81+
"sort-imports": [
82+
"error",
83+
{
84+
ignoreCase: true,
85+
ignoreDeclarationSort: true,
86+
ignoreMemberSort: false,
87+
memberSyntaxSortOrder: [
88+
"none",
89+
"all",
90+
"multiple",
91+
"single",
92+
],
93+
},
94+
],
6195

62-
// General code-style rules
63-
"@typescript-eslint/naming-convention": namingConventionConfig,
64-
"id-blacklist": [
65-
2,
66-
"arr",
67-
"cb",
68-
"e",
69-
"el",
70-
"err",
71-
"idx",
72-
"num",
73-
"str",
74-
"tmp",
75-
"val",
76-
],
77-
"no-return-assign": ["error", "except-parens"],
78-
"no-unused-vars": "off",
79-
"@typescript-eslint/no-unused-vars": [
80-
"error",
81-
{ argsIgnorePattern: "^_", ignoreRestSiblings: true },
82-
],
83-
"@typescript-eslint/consistent-type-imports": "error",
84-
"@typescript-eslint/no-import-type-side-effects": "error",
96+
// General code-style rules
97+
// @ts-ignore
98+
"@typescript-eslint/naming-convention": namingConventionConfig,
99+
"id-blacklist": [
100+
2,
101+
"arr",
102+
"cb",
103+
"e",
104+
"el",
105+
"err",
106+
"idx",
107+
"num",
108+
"str",
109+
"tmp",
110+
"val",
111+
],
112+
"no-return-assign": ["error", "except-parens"],
113+
"no-unused-vars": "off",
114+
"@typescript-eslint/no-unused-vars": [
115+
"error",
116+
{ argsIgnorePattern: "^_", ignoreRestSiblings: true },
117+
],
118+
"@typescript-eslint/consistent-type-imports": "error",
119+
"@typescript-eslint/no-import-type-side-effects": "error",
85120

86-
"prefer-destructuring": "warn",
87-
"no-nested-ternary": "warn",
121+
"prefer-destructuring": "warn",
122+
"no-nested-ternary": "warn",
88123

89-
"func-style": ["error", "declaration"],
124+
"func-style": ["error", "declaration"],
90125

91-
// Extra rules
92-
radix: "off",
126+
radix: "off",
127+
},
93128
},
94-
};
129+
eslintConfigPrettier,
130+
);

lib/nextjs-tailwind.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
const importOrderConfig = require("./rule-configs/import-order/next.js");
2-
const namingConventionConfig = require("./rule-configs/naming-convention/next-tailwind.js");
1+
import namingConventionConfig from "./rule-configs/naming-convention/next-tailwind.js";
2+
import nextJsConfig from "./nextjs.js";
33

4-
module.exports = {
5-
extends: [require.resolve("./nextjs.js")],
6-
rules: {
7-
// General code-style rules
8-
"@typescript-eslint/naming-convention": namingConventionConfig,
4+
export default [
5+
...nextJsConfig,
6+
{
7+
files: ["**/*.{ts,tsx,js,jsx}"],
8+
rules: {
9+
"@typescript-eslint/naming-convention": namingConventionConfig,
10+
},
911
},
10-
};
12+
];

0 commit comments

Comments
 (0)