Skip to content

Commit ff9e993

Browse files
authored
feat(ui): Add ESLint with plugins for react/hooks, prettier, flow (#26281)
## Description <!---Describe your changes in detail--> For developer + codebase life improvements, adding ESLint with prettier, react + react hooks, and flow plugins. ## Motivation and Context <!---Why is this change required? What problem does it solve?--> <!---If it fixes an open issue, please link to the issue here.--> * Improve the code quality and consistency, improves developer QOL * Implements feature mentioned in #21062 (comment) ## Impact <!---Describe any public API or user-facing feature change or any performance impact--> * There will be a large number of line changes once all files are linted, but no functional impact. > Note: All lint rules are up for discussion if folks on the project have strong feelings about tab spacing, semicolons, etc. This mostly implements the "recommended" rules for react, hooks, prettier formatting, and flow * Only impacts dev dependencies * Adds commands to package.json to lint, lint+fix, format, format+fix ## Follow up 1. Add ESLint + prettier config/packages (this PR) 2. Format all UI files, add eslint to CI build process 3. Convert flow -> typescript, add typescript-eslint, remove flow eslint plugins ## Test Plan <!---Please fill in how you tested your change--> For now this simply adds the dependencies, and implements an eslint/prettier configuration that works. No files have been linted or formatted yet. I plan to do this in a follow up to keep this PR manageable, first draft of linting all files here: #25726 Test the eslint config by running `yarn run lint` for eslint changes, or `yarn run format` for just prettier formatting changes ## Contributor checklist - [x] Please make sure your submission complies with our [contributing guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md), in particular [code style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style) and [commit standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards). - [x] PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced. - [ ] Documented new properties (with its default value), SQL syntax, functions, or other functionality. - [ ] If release notes are required, they follow the [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines). - [ ] Adequate tests were added if applicable. - [ ] CI passed. ## Release Notes Please follow [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) and fill in the release notes below. ``` == NO RELEASE NOTE == ```
1 parent c297061 commit ff9e993

File tree

6 files changed

+1572
-20
lines changed

6 files changed

+1572
-20
lines changed

presto-ui/src/.prettierignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.css
2+
*.map
3+
*.lock
4+
yarn.lock
5+
package-lock.json
6+
node_modules/
7+
target/
8+
static/
9+

presto-ui/src/.prettierrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"semi": true,
3+
"singleQuote": false,
4+
"trailingComma": "es5",
5+
"tabWidth": 4,
6+
"printWidth": 120,
7+
"overrides": [
8+
{
9+
"files": [
10+
"*.js",
11+
"*.jsx"
12+
],
13+
"options": {
14+
"parser": "flow"
15+
}
16+
}
17+
]
18+
}

presto-ui/src/d3utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import * as d3 from "d3";
1818
// DagreD3 Graph-related functions
1919
// ===============================
2020

21-
export function initializeGraph(): any
21+
export function initializeGraph()
2222
{
2323
return new dagreD3.graphlib.Graph({compound: true})
2424
.setGraph({rankdir: 'BT'})
2525
.setDefaultEdgeLabel(function () { return {}; });
2626
}
2727

28-
export function initializeSvg(selector: any): any
28+
export function initializeSvg(selector)
2929
{
3030
const svg = d3.select(selector);
3131
svg.append("g");

presto-ui/src/eslint.config.mjs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import ftFlow from "eslint-plugin-ft-flow";
2+
import js from "@eslint/js";
3+
import hermes from "hermes-eslint";
4+
import globals from "globals";
5+
import prettierEslint from "eslint-plugin-prettier/recommended";
6+
import react from "eslint-plugin-react";
7+
import reactHooks from "eslint-plugin-react-hooks";
8+
9+
export default [
10+
js.configs.recommended,
11+
prettierEslint,
12+
reactHooks.configs["recommended-latest"],
13+
{
14+
ignores: [
15+
"**/vendor/**",
16+
"**/node_modules/**",
17+
"**/sql-parser/**",
18+
"webpack.config.js",
19+
],
20+
},
21+
{
22+
languageOptions: {
23+
globals: {
24+
...globals.browser,
25+
...globals.jquery,
26+
},
27+
},
28+
},
29+
// Flow
30+
{
31+
languageOptions: {
32+
parser: hermes,
33+
},
34+
plugins: {
35+
"ft-flow": ftFlow,
36+
},
37+
settings: {
38+
flowtype: {
39+
onlyFilesWithFlowAnnotation: true,
40+
},
41+
},
42+
rules: {
43+
// Disable flow rules, but keep the plugin so files are parseable by eslint
44+
"flowtype/*": "off"
45+
},
46+
},
47+
// React
48+
{
49+
files: ["**/*.jsx"],
50+
plugins: {
51+
react,
52+
},
53+
rules: {
54+
...react.configs.recommended.rules,
55+
["react/prop-types"]: "warn",
56+
["react/no-deprecated"]: "warn",
57+
["no-prototype-builtins"]: "warn",
58+
},
59+
settings: {
60+
react: {
61+
version: "detect",
62+
},
63+
},
64+
},
65+
];

presto-ui/src/package.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@
1313
"@babel/preset-react": "^7.24.1",
1414
"babel-loader": "9.1.3",
1515
"css-loader": "^7.1.1",
16+
"eslint": "^9.32.0",
17+
"eslint-config-prettier": "^10.1.8",
18+
"eslint-plugin-ft-flow": "^3.0.11",
19+
"eslint-plugin-prettier": "^5.5.3",
20+
"eslint-plugin-react": "^7.37.5",
21+
"eslint-plugin-react-hooks": "^5.2.0",
1622
"flow-bin": "^0.236.0",
23+
"globals": "^16.3.0",
24+
"hermes-eslint": "^0.31.0",
1725
"html-inline-script-webpack-plugin": "^3.2.1",
1826
"html-webpack-plugin": "^5.6.0",
27+
"prettier": "^3.6.2",
1928
"style-loader": "^4.0.0",
2029
"webpack": "^5.91.0",
2130
"webpack-cli": "^5.1.4",
@@ -44,9 +53,13 @@
4453
"build:spa": "webpack --config webpack.config.js --env production --env config=spa",
4554
"serve:spa": "webpack serve --config webpack.config.js --env config=spa",
4655
"watch:spa": "webpack --config webpack.config.js --env config=spa --watch",
47-
"analyze": "webpack --env=production --config webpack.config.js --profile --json > stats.json && mv stats.json ../target/webapp/ && npx webpack-bundle-analyzer ../target/webapp/stats.json"
56+
"analyze": "webpack --env=production --config webpack.config.js --profile --json > stats.json && mv stats.json ../target/webapp/ && npx webpack-bundle-analyzer ../target/webapp/stats.json",
57+
"lint": "eslint . --ext .js,.jsx,.json,.html",
58+
"lint:fix": "eslint . --ext .js,.jsx,.json,.html --fix",
59+
"format": "prettier \"**/*.{js,jsx,json,html}\"",
60+
"format:fix": "prettier --write \"**/*.{js,jsx,json,html}\""
4861
},
4962
"resolutions": {
5063
"d3-color": "3.1.0"
5164
}
52-
}
65+
}

0 commit comments

Comments
 (0)