Skip to content

Commit 787d793

Browse files
Marvin9Hariharasuthan99
authored andcommitted
chore(ui-dev): migrate tslint to eslint (argoproj#11652) (argoproj#18079)
* feat(ui): setup eslint Signed-off-by: Mayursinh Sarvaiya <marvinduff97@gmail.com> * chore(ui): update `lint:fix` command Signed-off-by: Mayursinh Sarvaiya <marvinduff97@gmail.com> * fix(ui-lint): run `yarn lint:fix` > solve remaining manually Signed-off-by: Mayursinh Sarvaiya <marvinduff97@gmail.com> * chore(ui): remove tslint from `ui` Signed-off-by: Mayursinh Sarvaiya <marvinduff97@gmail.com> * chore(docs-ui): add docs for VSCode configuration eslint Signed-off-by: Mayursinh Sarvaiya <marvinduff97@gmail.com> * chore(ui): prettier set `trailingComma` to `none` > prettier config default is changed after version bump - https://prettier.io/docs/en/options.html#trailing-commas Signed-off-by: Mayursinh Sarvaiya <marvinduff97@gmail.com> --------- Signed-off-by: Mayursinh Sarvaiya <marvinduff97@gmail.com>
1 parent 16c0241 commit 787d793

40 files changed

+1673
-335
lines changed

docs/developer-guide/static-code-analysis.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
We use the following static code analysis tools:
44

5-
* golangci-lint and tslint for compile time linting
5+
* golangci-lint and eslint for compile time linting
66
* [codecov.io](https://codecov.io/gh/argoproj/argo-cd) - for code coverage
77
* [snyk.io](https://app.snyk.io/org/argoproj/projects) - for image scanning
88
* [sonarcloud.io](https://sonarcloud.io/organizations/argoproj/projects) - for code scans and security alerts

ui/.prettierrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"tabWidth": 4,
77
"jsxBracketSameLine": true,
88
"quoteProps": "consistent",
9-
"arrowParens": "avoid"
9+
"arrowParens": "avoid",
10+
"trailingComma": "none"
1011
}

ui/README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,25 @@ Make sure your code passes the lint checks:
2222

2323
```
2424
yarn lint --fix
25-
```
25+
```
26+
27+
If you are using VSCode, add this configuration to `.vscode/settings.json` in the root of this repository to identify and fix lint issues automatically before you save file.
28+
29+
Install [Eslint Extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) in VSCode.
30+
31+
`.vscode/settings.json`
32+
```json
33+
{
34+
"eslint.format.enable": true,
35+
"editor.codeActionsOnSave": {
36+
"source.fixAll.eslint": "always"
37+
},
38+
"eslint.workingDirectories": [
39+
{
40+
"directory": "./ui",
41+
"!cwd": false
42+
}
43+
],
44+
"eslint.experimental.useFlatConfig": true
45+
}
46+
```

ui/eslint.config.mjs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import globals from 'globals';
2+
import pluginJs from '@eslint/js';
3+
import tseslint from 'typescript-eslint';
4+
import pluginReactConfig from 'eslint-plugin-react/configs/recommended.js';
5+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
6+
7+
export default [
8+
{languageOptions: {globals: globals.browser}},
9+
pluginJs.configs.recommended,
10+
...tseslint.configs.recommended,
11+
{
12+
rules: {
13+
'@typescript-eslint/no-explicit-any': 'off',
14+
'@typescript-eslint/ban-types': 'off',
15+
'@typescript-eslint/no-var-requires': 'off'
16+
}
17+
},
18+
{
19+
settings: {
20+
react: {
21+
version: 'detect'
22+
}
23+
},
24+
...pluginReactConfig,
25+
rules: {
26+
'react/display-name': 'off',
27+
'react/no-string-refs': 'off'
28+
}
29+
},
30+
eslintPluginPrettierRecommended,
31+
{
32+
files: ['./src/**/*.{ts,tsx}']
33+
},
34+
{
35+
ignores: ['dist', 'assets', '**/*.config.js', '__mocks__', 'coverage', '**/*.test.{ts,tsx}']
36+
}
37+
];

ui/package.json

+10-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"start": "webpack-dev-server --config ./src/app/webpack.config.js --mode development",
77
"docker": "./scripts/build_docker.sh",
88
"build": "find ./dist -type f -not -name gitkeep -delete && webpack --config ./src/app/webpack.config.js --mode production",
9-
"lint": "tsc --noEmit --project ./src/app && tslint -p ./src/app",
10-
"lint:fix": "tslint -p ./src/app --fix",
9+
"lint": "tsc --noEmit --project ./src/app && eslint",
10+
"lint:fix": "eslint --fix",
1111
"test": "jest"
1212
},
1313
"dependencies": {
@@ -69,6 +69,7 @@
6969
"@babel/preset-env": "^7.7.1",
7070
"@babel/preset-react": "^7.18.6",
7171
"@babel/preset-typescript": "^7.7.2",
72+
"@eslint/js": "^9.1.1",
7273
"@types/classnames": "^2.2.3",
7374
"@types/cookie": "^0.5.1",
7475
"@types/dagre": "^0.7.40",
@@ -96,14 +97,19 @@
9697
"codecov": "^3.8.3",
9798
"copy-webpack-plugin": "^6.1.1",
9899
"esbuild-loader": "^2.18.0",
100+
"eslint": "^9.1.1",
101+
"eslint-config-prettier": "^9.1.0",
102+
"eslint-plugin-prettier": "^5.1.3",
103+
"eslint-plugin-react": "^7.34.1",
104+
"globals": "^15.1.0",
99105
"html-webpack-plugin": "^5.5.0",
100106
"identity-obj-proxy": "^3.0.0",
101107
"jest": "^27.5.1",
102108
"jest-junit": "^6.4.0",
103109
"jest-transform-css": "^2.0.0",
104110
"monaco-editor-webpack-plugin": "^7.0.0",
105111
"postcss": "^8.4.38",
106-
"prettier": "1.19",
112+
"prettier": "^3.2.5",
107113
"raw-loader": "^0.5.1",
108114
"react-test-renderer": "16.8.3",
109115
"sass": "^1.49.9",
@@ -112,11 +118,8 @@
112118
"style-loader": "^0.20.1",
113119
"ts-jest": "^27.1.3",
114120
"ts-node": "10.9.1",
115-
"tslint": "^6.1.3",
116-
"tslint-config-prettier": "^1.18.0",
117-
"tslint-plugin-prettier": "^2.0.1",
118-
"tslint-react": "^5.0.0",
119121
"typescript": "^4.9.5",
122+
"typescript-eslint": "^7.8.0",
120123
"webpack": "^5.84.1",
121124
"webpack-cli": "^4.9.2",
122125
"webpack-dev-server": "^4.7.4",

ui/src/app/app.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ requests.onError.subscribe(async err => {
9898
}
9999
// Query for basehref and remove trailing /.
100100
// If basehref is the default `/` it will become an empty string.
101-
const basehref = document
102-
.querySelector('head > base')
103-
.getAttribute('href')
104-
.replace(/\/$/, '');
101+
const basehref = document.querySelector('head > base').getAttribute('href').replace(/\/$/, '');
105102
if (isSSO) {
106103
window.location.href = `${basehref}/auth/login?return_url=${encodeURIComponent(location.href)}`;
107104
} else {

ui/src/app/applications/components/application-create-panel/application-create-panel.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-prototype-builtins */
12
import {AutocompleteField, Checkbox, DataLoader, DropDownMenu, FormField, HelpIcon, Select} from 'argo-ui';
23
import * as deepMerge from 'deepmerge';
34
import * as React from 'react';

ui/src/app/applications/components/application-details/application-resource-list.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {ResourceIcon} from '../resource-icon';
66
import {ResourceLabel} from '../resource-label';
77
import {ComparisonStatusIcon, HealthStatusIcon, nodeKey, createdOrNodeKey} from '../utils';
88
import {Consumer} from '../../../shared/context';
9-
import * as _ from 'lodash';
109
import Moment from 'react-moment';
1110
import {format} from 'date-fns';
1211
import {ResourceNode, ResourceRef} from '../../../shared/models';

ui/src/app/applications/components/application-parameters/application-parameters.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ export const ApplicationParameters = (props: {
250250
if (params) {
251251
for (const param of params) {
252252
if (param.map && param.array) {
253+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
253254
// @ts-ignore
254255
param.map = param.array.reduce((acc, {name, value}) => {
256+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
255257
// @ts-ignore
256258
acc[name] = value;
257259
return acc;
@@ -322,6 +324,7 @@ function gatherDetails(
322324
setAppParamsDeletedState: any
323325
): EditablePanelItem[] {
324326
const hasMultipleSources = app.spec.sources && app.spec.sources.length > 0;
327+
// eslint-disable-next-line no-prototype-builtins
325328
const isHelm = source.hasOwnProperty('chart');
326329
if (hasMultipleSources) {
327330
attributes.push({

ui/src/app/applications/components/application-parameters/kustomize-image.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { format, parse } from './kustomize-image';
1+
import {format, parse} from './kustomize-image';
22

33
test('parse image version override', () => {
44
const image = parse('foo/bar:v1.0.0');
@@ -8,7 +8,7 @@ test('parse image version override', () => {
88
});
99

1010
test('format image version override', () => {
11-
const formatted = format({ name: 'foo/bar', newTag: 'v1.0.0' });
11+
const formatted = format({name: 'foo/bar', newTag: 'v1.0.0'});
1212
expect(formatted).toBe('foo/bar:v1.0.0');
1313
});
1414

@@ -21,7 +21,7 @@ test('parse image name override', () => {
2121
});
2222

2323
test('format image name override', () => {
24-
const formatted = format({ name: 'foo/bar', newTag: 'v1.0.0', newName: 'foo/bar1' });
24+
const formatted = format({name: 'foo/bar', newTag: 'v1.0.0', newName: 'foo/bar1'});
2525
expect(formatted).toBe('foo/bar=foo/bar1:v1.0.0');
2626
});
2727

@@ -33,6 +33,6 @@ test('parse image digest override', () => {
3333
});
3434

3535
test('format image digest override', () => {
36-
const formatted = format({ name: 'foo/bar', digest: 'sha:123' });
36+
const formatted = format({name: 'foo/bar', digest: 'sha:123'});
3737
expect(formatted).toBe('foo/bar@sha:123');
3838
});

ui/src/app/applications/components/application-pod-view/pod-view.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ export class PodView extends React.Component<PodViewProps> {
145145
</Moment>
146146
</div>
147147
) : null}
148-
{group.info?.map(infoItem => (
149-
<div key={infoItem.name}>{infoItem.value}</div>
150-
))}
148+
{group.info?.map(infoItem => <div key={infoItem.name}>{infoItem.value}</div>)}
151149
</div>
152150
)}
153151
</div>

0 commit comments

Comments
 (0)