Skip to content

Commit 86956ef

Browse files
authored
DEV: Add eslint integrated prettier (#4273)
* install dependencies * add scripts * add default settings for VSCode * handle tsx properly * ignore reports and mocks for linting * ignore scss files * update eslint ts because of this: WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.
1 parent 7b0be18 commit 86956ef

File tree

9 files changed

+220
-73
lines changed

9 files changed

+220
-73
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ package.json
6161
# temp folders - remove in future after fix all issues
6262
redisinsight/ui/src/packages/redisgraph
6363
redisinsight/ui/src/packages/redistimeseries-app
64+
65+
/report
66+
__mocks__

.eslintrc.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ module.exports = {
44
node: true,
55
browser: true,
66
},
7-
extends: ['airbnb-typescript'],
7+
extends: ['airbnb-typescript', 'prettier'],
88
plugins: ['@typescript-eslint'],
99
parser: '@typescript-eslint/parser',
1010
rules: {
11-
semi: ['error', 'never'],
11+
semi: ['error', 'always'],
1212
quotes: [2, 'single', { avoidEscape: true }],
13-
'max-len': ['error', { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true, code: 120 }],
13+
'max-len': [
14+
'error',
15+
{
16+
ignoreComments: true,
17+
ignoreStrings: true,
18+
ignoreRegExpLiterals: true,
19+
code: 120,
20+
},
21+
],
1422
'class-methods-use-this': 'off',
1523
'import/no-extraneous-dependencies': 'off', // temporary disabled
1624
'@typescript-eslint/semi': ['error', 'never'],
@@ -33,32 +41,45 @@ module.exports = {
3341
{
3442
pattern: 'desktopSrc/**',
3543
group: 'internal',
36-
position: 'after'
44+
position: 'after',
3745
},
3846
{
3947
pattern: 'uiSrc/**',
4048
group: 'internal',
41-
position: 'after'
49+
position: 'after',
4250
},
4351
{
4452
pattern: 'apiSrc/**',
4553
group: 'internal',
46-
position: 'after'
54+
position: 'after',
4755
},
4856
],
4957
warnOnUnassignedImports: true,
50-
pathGroupsExcludedImportTypes: ['builtin']
58+
pathGroupsExcludedImportTypes: ['builtin'],
5159
},
5260
],
5361
},
62+
overrides: [
63+
{
64+
files: ['*.ts', '*.tsx'],
65+
rules: {
66+
'@typescript-eslint/semi': ['error', 'never'],
67+
semi: 'off',
68+
},
69+
},
70+
{
71+
files: ['*.js', '*.jsx', '*.cjs'],
72+
rules: {
73+
semi: ['error', 'always'],
74+
'@typescript-eslint/semi': 'off',
75+
},
76+
},
77+
],
5478
parserOptions: {
5579
project: './tsconfig.json',
5680
ecmaVersion: 2020,
5781
sourceType: 'module',
5882
createDefaultProgram: true,
5983
},
60-
ignorePatterns: [
61-
'redisinsight/ui',
62-
'redisinsight/api',
63-
],
84+
ignorePatterns: ['redisinsight/ui', 'redisinsight/api'],
6485
}

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tests/e2e
2+
**/*.scss

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"semi": true,
3+
"overrides": [
4+
{
5+
"files": ["**/*.ts", "**/*.tsx"],
6+
"options": {
7+
"semi": false
8+
}
9+
}
10+
]
11+
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"[javascript]": {
4+
"editor.defaultFormatter": "esbenp.prettier-vscode"
5+
},
6+
"[typescript]": {
7+
"editor.defaultFormatter": "esbenp.prettier-vscode"
8+
}
9+
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"lint:api": "yarn --cwd redisinsight/api lint",
3131
"lint:desktop": "eslint ./redisinsight/desktop",
3232
"lint:e2e": "yarn --cwd tests/e2e lint",
33+
"prettier": "prettier --check .",
34+
"prettier:update": "prettier --write .",
3335
"package": "yarn package:dev",
3436
"package:prod": "ts-node ./scripts/prebuild.js dist && yarn build:prod && electron-builder build -p never",
3537
"package:stage": "ts-node ./scripts/prebuild.js dist && yarn build:stage && electron-builder build -p never -c.mac.bundleVersion=$GITHUB_RUN_ID",
@@ -135,8 +137,8 @@
135137
"@types/text-encoding": "^0.0.37",
136138
"@types/uuid": "^8.3.4",
137139
"@types/webpack-env": "^1.18.4",
138-
"@typescript-eslint/eslint-plugin": "^4.8.1",
139-
"@typescript-eslint/parser": "^4.8.1",
140+
"@typescript-eslint/eslint-plugin": "^5.62.0",
141+
"@typescript-eslint/parser": "^5.62.0",
140142
"@vitejs/plugin-react": "^4.2.1",
141143
"@vitejs/plugin-react-swc": "^3.6.0",
142144
"assert": "^2.1.0",
@@ -160,6 +162,7 @@
160162
"eslint": "^7.5.0",
161163
"eslint-config-airbnb": "^18.2.1",
162164
"eslint-config-airbnb-typescript": "^12.0.0",
165+
"eslint-config-prettier": "10.0.2",
163166
"eslint-import-resolver-webpack": "0.13.8",
164167
"eslint-plugin-compat": "^3.8.0",
165168
"eslint-plugin-import": "^2.22.0",
@@ -187,6 +190,7 @@
187190
"msw": "^1.3.4",
188191
"patch-package": "^8.0.0",
189192
"postinstall-postinstall": "^2.1.0",
193+
"prettier": "3.5.2",
190194
"react-refresh": "^0.9.0",
191195
"redux-mock-store": "^1.5.4",
192196
"regenerator-runtime": "^0.13.5",

redisinsight/api/.eslintrc.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module.exports = {
33
env: {
44
node: true,
55
},
6-
extends: ['airbnb-typescript/base', 'plugin:sonarjs/recommended'],
6+
extends: ['airbnb-typescript/base', 'plugin:sonarjs/recommended', 'prettier'],
77
plugins: ['@typescript-eslint', 'sonarjs'],
88
parser: '@typescript-eslint/parser',
99
rules: {
1010
'max-len': ['warn', 120],
1111
'@typescript-eslint/return-await': 'off',
12-
"@typescript-eslint/dot-notation": "off",
12+
'@typescript-eslint/dot-notation': 'off',
1313
'import/prefer-default-export': 'off', // ignore "export default" requirement
1414
'max-classes-per-file': 'off',
1515
'class-methods-use-this': 'off', // should be ignored since NestJS allow inheritance without using "this" inside class methods
@@ -21,12 +21,12 @@ module.exports = {
2121
},
2222
overrides: [
2323
{
24-
files: [ '**/*.spec.ts', '**/__mocks__/**/*' ],
24+
files: ['**/*.spec.ts', '**/__mocks__/**/*'],
2525
rules: {
2626
'sonarjs/no-duplicate-string': 0,
2727
'sonarjs/no-identical-functions': 0,
2828
'import/first': 0,
29-
}
30-
}
31-
]
29+
},
30+
},
31+
],
3232
};

redisinsight/ui/.eslintrc.js

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
const path = require('path')
1+
const path = require('path');
22

33
module.exports = {
44
root: true,
55
env: {
66
browser: true,
77
},
8-
extends: ['airbnb-typescript', 'airbnb/hooks', 'plugin:sonarjs/recommended'],
8+
extends: [
9+
'airbnb-typescript',
10+
'airbnb/hooks',
11+
'plugin:sonarjs/recommended',
12+
'prettier',
13+
],
914
// extends: ['airbnb', 'airbnb/hooks'],
1015
plugins: ['@typescript-eslint'],
1116
parser: '@typescript-eslint/parser',
@@ -18,23 +23,44 @@ module.exports = {
1823

1924
overrides: [
2025
{
21-
files: [
22-
'**/*.spec.ts',
23-
'**/*.spec.tsx',
24-
'**/*.spec.ts',
25-
],
26+
files: ['**/*.spec.ts', '**/*.spec.tsx', '**/*.spec.ts'],
2627
env: {
2728
jest: true,
2829
},
2930
},
31+
{
32+
files: ['*.ts', '*.tsx'],
33+
rules: {
34+
'@typescript-eslint/semi': ['error', 'never'],
35+
semi: 'off',
36+
},
37+
},
38+
{
39+
files: ['*.js', '*.jsx'],
40+
rules: {
41+
semi: ['error', 'always'],
42+
'@typescript-eslint/semi': 'off',
43+
},
44+
},
45+
],
46+
ignorePatterns: [
47+
'dist',
48+
'src/packages/redisearch/src/icons/*.js',
49+
'src/packages/common/src/icons/*.js',
3050
],
31-
ignorePatterns: ['dist', 'src/packages/redisearch/src/icons/*.js', 'src/packages/common/src/icons/*.js'],
32-
3351
rules: {
3452
radix: 'off',
35-
semi: ['error', 'never'],
53+
semi: ['error', 'always'],
3654
'no-bitwise': ['error', { allow: ['|'] }],
37-
'max-len': ['error', { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true, code: 120 }],
55+
'max-len': [
56+
'error',
57+
{
58+
ignoreComments: true,
59+
ignoreStrings: true,
60+
ignoreRegExpLiterals: true,
61+
code: 120,
62+
},
63+
],
3864
'class-methods-use-this': 'off',
3965
// A temporary hack related to IDE not resolving correct package.json
4066
'import/no-extraneous-dependencies': 'off',
@@ -82,23 +108,23 @@ module.exports = {
82108
{
83109
pattern: 'uiSrc/**',
84110
group: 'internal',
85-
position: 'after'
111+
position: 'after',
86112
},
87113
{
88114
pattern: 'apiSrc/**',
89115
group: 'internal',
90-
position: 'after'
116+
position: 'after',
91117
},
92118
{
93119
pattern: '{.,..}/*.scss', // same directory only
94120
// pattern: '{.,..}/**/*\.scss' // same & outside directories (e.g. import '../foo/foo.scss')
95121
group: 'object',
96-
position: 'after'
97-
}
122+
position: 'after',
123+
},
98124
],
99125
warnOnUnassignedImports: true,
100-
pathGroupsExcludedImportTypes: ['builtin']
126+
pathGroupsExcludedImportTypes: ['builtin'],
101127
},
102128
],
103129
},
104-
}
130+
};

0 commit comments

Comments
 (0)