Skip to content

Commit 5a96eba

Browse files
Setup ESLint and Prettier (7.16) (#4705)
* add prettier and eslint for wazuh * update .eslintrc * downgraded version eslint-import-resolver-typescri * add a plugin for filename control * add default settings for vscode workspace * Extend .gitignore for VSCode settings * Add recommended extensions for VSCode * move eslint-plugin-filenames-simple to devDepend * Bump Node version to 16.13.0 This is the version of Node usd by Kibana v7.16.0 * Add React version to ESLint configuration Fixes a warning about the React version not being set Co-authored-by: yenienserrano <ian.serrano@wazuh.com> Co-authored-by: Ian Yenien Serrano <63758389+yenienserrano@users.noreply.github.com>
1 parent 24496cc commit 5a96eba

11 files changed

+200
-77
lines changed

.eslintignore

-4
This file was deleted.

.eslintrc.js

-38
This file was deleted.

.eslintrc.json

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"browser": true,
5+
"es2021": true,
6+
"node": true,
7+
"jest": true
8+
},
9+
"extends": [
10+
"eslint:recommended",
11+
"plugin:react/recommended",
12+
"plugin:@typescript-eslint/recommended",
13+
"prettier"
14+
],
15+
"overrides": [],
16+
"parser": "@typescript-eslint/parser",
17+
"parserOptions": {
18+
"ecmaFeatures": {
19+
"jsx": true
20+
},
21+
"ecmaVersion": "latest",
22+
"sourceType": "module"
23+
},
24+
"plugins": [
25+
"react",
26+
"react-hooks",
27+
"@typescript-eslint",
28+
"prettier",
29+
"filenames-simple"
30+
],
31+
"settings": {
32+
"import/resolver": {
33+
"typescript": {}
34+
},
35+
"react": {
36+
"version": "16.12.0"
37+
}
38+
},
39+
"ignorePatterns": [
40+
"node_modules/",
41+
"public/utils/codemirror/",
42+
"public/kibana-integrations/",
43+
"public/utils/jquery-ui.js"
44+
],
45+
"rules": {
46+
"filenames-simple/naming-convention": "error",
47+
"indent": ["error", 2, { "SwitchCase": 1 }],
48+
"quotes": ["error", "single"],
49+
"semi": ["error", "always"],
50+
"react/react-in-jsx-scope": "off",
51+
"camelcase": "error",
52+
"spaced-comment": "error",
53+
"no-duplicate-imports": "error",
54+
"no-await-in-loop": "error",
55+
"no-use-before-define": [
56+
"error",
57+
{
58+
"functions": true,
59+
"classes": true,
60+
"variables": true,
61+
"allowNamedExports": false
62+
}
63+
],
64+
"block-scoped-var": "error",
65+
"curly": "error",
66+
"default-case": "error",
67+
"default-param-last": "error",
68+
"eqeqeq": "error",
69+
"no-var": "error",
70+
"require-await": "error",
71+
"array-bracket-newline": ["error", "consistent"],
72+
"array-bracket-spacing": [
73+
"error",
74+
"always",
75+
{
76+
"singleValue": false
77+
}
78+
],
79+
"array-element-newline": ["error", "always"],
80+
"arrow-parens": ["error", "as-needed"],
81+
"arrow-spacing": "error",
82+
"block-spacing": "error",
83+
"comma-spacing": [
84+
"error",
85+
{
86+
"before": false,
87+
"after": true
88+
}
89+
],
90+
"func-call-spacing": ["error", "never"],
91+
"function-call-argument-newline": ["error", "consistent"],
92+
"max-len": [
93+
"error",
94+
{
95+
"code": 100
96+
}
97+
],
98+
"no-trailing-spaces": "error",
99+
"semi-spacing": "error"
100+
}
101+
}

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ node_modules/
3737
jspm_packages/
3838

3939
# Visual Studio Code directory
40-
.vscode/
40+
.vscode/*
41+
!.vscode/settings.json
42+
!.vscode/tasks.json
43+
!.vscode/launch.json
44+
!.vscode/extensions.json
45+
!.vscode/*.code-snippets
46+
47+
# Ignore code-workspaces
48+
*.code-workspace
4149

4250
# Typescript v1 declaration files
4351
typings/

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10.23.1
1+
16.13.0

.prettierrc

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
2+
"semi": true,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"printWidth": 80,
26
"singleQuote": true,
3-
"trailingComma": "es5",
4-
"printWidth": 100
5-
}
7+
"trailingComma": "all",
8+
"jsxSingleQuote": true,
9+
"bracketSpacing": true,
10+
"arrowParens": "avoid",
11+
"bracketSameLine": false
12+
}

.tslint.yml

-2
This file was deleted.

.vscode/extensions.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
// ESLint support.
6+
"dbaeumer.vscode-eslint",
7+
// Prettier support.
8+
"esbenp.prettier-vscode",
9+
// JS/TS language support
10+
"ms-vscode.vscode-typescript-next",
11+
// VSCode Remote Dev Containers
12+
"ms-vscode-remote.remote-containers",
13+
// Docker extension for VSCode
14+
"ms-azuretools.vscode-docker",
15+
// GitLens — Git supercharged
16+
"eamodio.gitlens",
17+
// EditorConfig for VS Code
18+
"editorconfig.editorconfig",
19+
]
20+
}

.vscode/settings.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"diffEditor.ignoreTrimWhitespace": true,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.formatOnPaste": true,
5+
"editor.formatOnSave": true,
6+
"editor.inlineSuggest.enabled": true,
7+
"editor.insertSpaces": true,
8+
"editor.minimap.enabled": true,
9+
"editor.rulers": [80, 100],
10+
"editor.tabSize": 2,
11+
"editor.trimAutoWhitespace": true,
12+
"editor.wordWrap": "on",
13+
"explorer.confirmDelete": true,
14+
"files.autoSave": "off",
15+
"javascript.updateImportsOnFileMove.enabled": "always",
16+
"typescript.updateImportsOnFileMove.enabled": "always"
17+
}

package.json

+20-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
},
2525
"homepage": "https://www.wazuh.com/",
2626
"scripts": {
27-
"pretty": "prettier --single-quote \"{,!(node_modules)/**/}*.js\" --write",
28-
"tslint": "tslint -c .tslint.yml server/**/*.ts server/**/*.tsx public/**/*.ts public/**/*.tsx",
29-
"lint": "eslint . --ext .js -c .eslintrc.json --color",
27+
"lint": "eslint {public,server,common}/**/*.{js,jsx,ts,tsx,json}",
28+
"lint:public": "eslint public/**/*.{js,jsx,ts,tsx,json}",
29+
"lint:server": "eslint server/**/*.{js,jsx,ts,tsx,json}",
30+
"lint:common": "eslint common/**/*.{js,jsx,ts,tsx,json}",
31+
"lint:fix": "eslint --fix '{public,server,common}/**/*.{js,jsx,ts,tsx,json}'",
32+
"format": "prettier --write '{public,server,common}/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
3033
"kbn": "node ../../scripts/kbn",
3134
"es": "node ../../scripts/es",
3235
"start": "plugin-helpers start",
@@ -69,12 +72,25 @@
6972
"react-cookie": "^4.0.3",
7073
"read-last-lines": "^1.7.2",
7174
"timsort": "^0.3.0",
75+
"typescript": "^4.4.2",
7276
"winston": "3.0.0"
7377
},
7478
"devDependencies": {
75-
"redux-mock-store": "^1.5.4",
7679
"@types/node-cron": "^2.0.3",
80+
"@typescript-eslint/eslint-plugin": "^5.38.1",
81+
"@typescript-eslint/parser": "^5.38.1",
82+
"eslint": "^8.24.0",
83+
"eslint-config-prettier": "^8.5.0",
84+
"eslint-import-resolver-typescript": "2.7.1",
7785
"eslint-plugin-async-await": "^0.0.0",
86+
"eslint-plugin-cypress": "^2.12.1",
87+
"eslint-plugin-filenames-simple": "^0.7.0",
88+
"eslint-plugin-import": "^2.26.0",
89+
"eslint-plugin-prettier": "^4.2.1",
90+
"eslint-plugin-react": "^7.31.8",
91+
"eslint-plugin-react-hooks": "^4.6.0",
92+
"prettier": "^2.7.1",
93+
"redux-mock-store": "^1.5.4",
7894
"tslint": "^5.11.0",
7995
"typescript-eslint-parser": "^18.0.0"
8096
}

tsconfig.json

+22-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
{
2-
"extends": "../../tsconfig.json",
32
"compilerOptions": {
4-
"jsx": "react",
5-
"esModuleInterop": true,
6-
"outDir": "./target",
7-
"allowUnusedLabels": true,
8-
"noUnusedLocals": false,
9-
"noUnusedParameters": false,
3+
"target": "es5",
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
9+
"allowJs": true,
1010
"skipLibCheck": true,
11-
"alwaysStrict": false,
12-
"noImplicitUseStrict": false,
13-
"noImplicitAny": false,
11+
"esModuleInterop": true,
12+
"allowSyntheticDefaultImports": true,
13+
"strict": true,
14+
"forceConsistentCasingInFileNames": true,
15+
"noFallthroughCasesInSwitch": true,
16+
"module": "esnext",
17+
"moduleResolution": "node",
18+
"resolveJsonModule": true,
19+
"isolatedModules": true,
20+
"noEmit": true,
21+
"jsx": "react-jsx"
1422
},
1523
"include": [
16-
"index.ts",
17-
"server/**/*",
18-
"public/**/*",
19-
"common/**/*"
20-
],
21-
"exclude": [
22-
"public/**/*.test.ts",
23-
"public/**/*.test.tsx",
24-
"server/**/*.test.ts",
25-
"common/**/*.test.ts",
26-
"../../src/**/*",
27-
"**/request.ts",
28-
"src/**/*"
29-
],
24+
"public",
25+
"server",
26+
"common"
27+
]
3028
}

0 commit comments

Comments
 (0)