Skip to content

Commit 156d5a2

Browse files
alexeyr-ci2alexeyr
andauthored
Upgrade ESLint (#529)
Upgrade ESLint and plugins and switch to flat config. Part 2 of #489, needs #528 to be merged. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit - **Chores** - Enhanced the linting setup and configurations to improve coding standards and error detection. - Adjusted linting commands to streamline the process. - Updated development dependencies to their latest versions for better performance and consistency. - Upgraded Ruby version across various configuration files to ensure compatibility and improvements. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alexey Romanov <[email protected]>
1 parent 7ae2bf7 commit 156d5a2

File tree

14 files changed

+1194
-974
lines changed

14 files changed

+1194
-974
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111
# Lint all
112112
lint-js-and-ruby:
113113
docker:
114-
- image: &docker_image cimg/ruby:3.3.0-browsers
114+
- image: &docker_image cimg/ruby:3.3.7-browsers
115115
steps:
116116
- checkout
117117
- run: *print-system-info

.controlplane/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ruby:3.3.0
1+
FROM ruby:3.3.7
22

33
RUN apt-get update
44

.eslintignore

Lines changed: 0 additions & 22 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 91 deletions
This file was deleted.

Gemfile.development_dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55

6-
ruby '3.3.0'
6+
ruby '3.3.7'
77

88
gem "react_on_rails", "15.0.0.alpha.2" # keep in sync with package.json files
99

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ DEPENDENCIES
486486
yard
487487

488488
RUBY VERSION
489-
ruby 3.3.0p0
489+
ruby 3.3.7p123
490490

491491
BUNDLED WITH
492492
2.5.4

eslint.config.mjs

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import path from 'node:path';
2+
import { includeIgnoreFile } from '@eslint/compat';
3+
import js from '@eslint/js';
4+
import { FlatCompat } from '@eslint/eslintrc';
5+
import { defineConfig, globalIgnores } from 'eslint/config';
6+
import importPlugin from 'eslint-plugin-import';
7+
import jest from 'eslint-plugin-jest';
8+
import prettierRecommended from 'eslint-plugin-prettier/recommended';
9+
import globals from 'globals';
10+
import typescriptEslint from 'typescript-eslint';
11+
12+
const compat = new FlatCompat({
13+
baseDirectory: import.meta.dirname,
14+
recommendedConfig: js.configs.recommended,
15+
allConfig: js.configs.all,
16+
});
17+
18+
export default defineConfig([
19+
includeIgnoreFile(path.resolve(import.meta.dirname, '.gitignore')),
20+
globalIgnores([
21+
'**/node_modules',
22+
'**/coverage',
23+
'gen-documentation/**/*',
24+
'spec/react_on_rails/dummy-for-generators',
25+
'spec/dummy',
26+
'spec/execjs-compatible-dummy',
27+
'packages/node-renderer/lib/',
28+
'packages/node-renderer/tests/fixtures',
29+
'packages/node-renderer/webpack.config.js',
30+
'**/node_modules/**/*',
31+
'**/assets/webpack/**/*',
32+
'**/generated/**/*',
33+
'**/app/assets/javascripts/application.js',
34+
'**/coverage/**/*',
35+
'**/cable.js',
36+
'**/public/**/*',
37+
'**/tmp/**/*',
38+
'**/vendor',
39+
'**/dist',
40+
'**/.yalc/',
41+
]),
42+
{
43+
files: ['**/*.[jt]s', '**/*.[cm][jt]s', '**/*.[jt]sx'],
44+
},
45+
js.configs.recommended,
46+
compat.extends('eslint-config-shakacode'),
47+
{
48+
languageOptions: {
49+
globals: globals.node,
50+
51+
parserOptions: {
52+
// We have @babel/eslint-parser from eslint-config-shakacode, but don't use Babel in the main project
53+
requireConfigFile: false,
54+
},
55+
},
56+
57+
settings: {
58+
'import/extensions': ['.js', '.ts'],
59+
60+
'import/parsers': {
61+
'@typescript-eslint/parser': ['.ts'],
62+
},
63+
64+
'import/resolver': {
65+
node: true,
66+
typescript: true,
67+
},
68+
},
69+
70+
rules: {
71+
'no-console': 'off',
72+
73+
'no-void': [
74+
'error',
75+
{
76+
// Allow using void to suppress errors about misused promises
77+
allowAsStatement: true,
78+
},
79+
],
80+
81+
// Allow using void to suppress errors about misused promises
82+
'no-restricted-syntax': 'off',
83+
// https://github.com/benmosher/eslint-plugin-import/issues/340
84+
'import/no-extraneous-dependencies': 'off',
85+
'import/extensions': 'off',
86+
'import/prefer-default-export': 'off',
87+
'lines-between-class-members': [
88+
'error',
89+
{
90+
enforce: [
91+
{ blankLine: 'always', prev: '*', next: '*' },
92+
{ blankLine: 'never', prev: 'field', next: 'field' },
93+
],
94+
},
95+
],
96+
'no-mixed-operators': 'off',
97+
},
98+
},
99+
{
100+
files: ['**/*.ts{x,}'],
101+
extends: [importPlugin.flatConfigs.typescript, typescriptEslint.configs.strictTypeChecked],
102+
103+
languageOptions: {
104+
parserOptions: {
105+
projectService: true,
106+
},
107+
},
108+
109+
rules: {
110+
'@typescript-eslint/restrict-template-expressions': 'off',
111+
112+
'@typescript-eslint/no-unused-vars': [
113+
'error',
114+
{
115+
argsIgnorePattern: '^_',
116+
caughtErrorsIgnorePattern: '^_',
117+
},
118+
],
119+
120+
'@typescript-eslint/no-floating-promises': [
121+
'error',
122+
{
123+
allowForKnownSafePromises: [
124+
{
125+
from: 'package',
126+
package: 'fastify',
127+
name: 'FastifyReply',
128+
},
129+
],
130+
},
131+
],
132+
133+
'no-shadow': 'off',
134+
'@typescript-eslint/no-shadow': 'error',
135+
},
136+
},
137+
{
138+
files: ['packages/node-renderer/tests/**'],
139+
140+
plugins: {
141+
jest,
142+
},
143+
144+
languageOptions: {
145+
globals: globals.jest,
146+
},
147+
148+
rules: {
149+
// Allows Jest mocks before import
150+
'import/first': 'off',
151+
'jest/no-disabled-tests': 'warn',
152+
'jest/no-focused-tests': 'error',
153+
'jest/no-identical-title': 'error',
154+
'jest/prefer-to-have-length': 'warn',
155+
'jest/valid-expect': 'error',
156+
// Simplifies test code
157+
'@typescript-eslint/no-non-null-assertion': 'off',
158+
},
159+
},
160+
{
161+
files: ['packages/node-renderer/src/integrations/**'],
162+
ignores: ['packages/node-renderer/src/integrations/api.ts'],
163+
164+
rules: {
165+
// Integrations should only use the public integration API
166+
'no-restricted-imports': [
167+
'error',
168+
{
169+
patterns: ['../*'],
170+
},
171+
],
172+
},
173+
},
174+
// must be the last config in the array
175+
// https://github.com/prettier/eslint-plugin-prettier?tab=readme-ov-file#configuration-new-eslintconfigjs
176+
prettierRecommended,
177+
]);

package-scripts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ scripts:
5656
eslint:
5757
default:
5858
description: Run eslint.
59-
script: eslint . --ext ".js,.mts,.mjs,.jsx,.ts,.tsx" --report-unused-disable-directives
59+
script: eslint . --report-unused-disable-directives
6060
fix:
6161
description: Run eslint and auto-fix.
6262
script: nps "eslint --fix"

package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@babel/eslint-parser": "^7.24.1",
5252
"@babel/preset-env": "^7.12.1",
5353
"@babel/preset-typescript": "^7.24.1",
54+
"@eslint/compat": "^1.2.8",
5455
"@honeybadger-io/js": "^6.10.1",
5556
"@sentry/node": "^7.120.0",
5657
"@tsconfig/node14": "^14.1.2",
@@ -60,18 +61,19 @@
6061
"@types/touch": "^3.1.5",
6162
"babel-jest": "^29.7.0",
6263
"concurrently": "^9.1.0",
63-
"eslint": "^8.57.0",
64-
"eslint-config-prettier": "^9.1.0",
64+
"eslint": "^9.24.0",
65+
"eslint-config-prettier": "^10.1.1",
6566
"eslint-config-shakacode": "^19.0.0",
66-
"eslint-import-resolver-typescript": "^3.6.1",
67-
"eslint-plugin-import": "^2.29.1",
68-
"eslint-plugin-jest": "^27.9.0",
69-
"eslint-plugin-jsx-a11y": "^6.8.0",
70-
"eslint-plugin-prettier": "^5.1.3",
71-
"eslint-plugin-react": "^7.34.1",
72-
"eslint-plugin-react-hooks": "^4.6.0",
67+
"eslint-import-resolver-typescript": "^4.3.2",
68+
"eslint-plugin-import": "^2.31.0",
69+
"eslint-plugin-jest": "^28.11.0",
70+
"eslint-plugin-jsx-a11y": "^6.10.2",
71+
"eslint-plugin-prettier": "^5.2.6",
72+
"eslint-plugin-react": "^7.37.5",
73+
"eslint-plugin-react-hooks": "^5.2.0",
7374
"form-auto-content": "^3.2.1",
7475
"form-data": "^4.0.1",
76+
"globals": "^16.0.0",
7577
"husky": "^4.3.6",
7678
"jest": "^29.7.0",
7779
"jest-junit": "^16.0.0",

spec/dummy/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ DEPENDENCIES
532532
webmock
533533

534534
RUBY VERSION
535-
ruby 3.3.0p0
535+
ruby 3.3.7p123
536536

537537
BUNDLED WITH
538538
2.5.4

0 commit comments

Comments
 (0)