Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit fd65944

Browse files
authored
build: add linter and formar checker to the frontend (#677)
* Add eslint as linter and prettier as formater for app * Use @phlare Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent 02ee7dc commit fd65944

37 files changed

+1265
-121
lines changed

.eslintignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public/build/**
2+
scripts/**
3+
pkg/api/static/**
4+
**/dist
5+
.eslintrc.js
6+
jest.config.js
7+
cypress/**
8+
cypress.config.ts

.eslintrc.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
module.exports = {
2+
extends: [
3+
'@grafana/eslint-config',
4+
'plugin:import/recommended',
5+
'plugin:import/typescript',
6+
],
7+
plugins: ['unused-imports'],
8+
rules: {
9+
'react-hooks/exhaustive-deps': 'warn',
10+
'no-duplicate-imports': 'off',
11+
'@typescript-eslint/no-duplicate-imports': 'error',
12+
'@typescript-eslint/no-unused-vars': 'off',
13+
'unused-imports/no-unused-imports': 'error',
14+
'unused-imports/no-unused-vars': [
15+
'warn',
16+
{
17+
vars: 'all',
18+
varsIgnorePattern: '^_',
19+
args: 'after-used',
20+
argsIgnorePattern: '^_',
21+
},
22+
],
23+
'import/no-relative-packages': 'error',
24+
'no-restricted-imports': [
25+
'error',
26+
{
27+
patterns: [
28+
{
29+
group: ['../*', './*'],
30+
message:
31+
'Usage of relative parent imports is not allowed. Please use absolute(use alias) imports instead.',
32+
},
33+
],
34+
},
35+
],
36+
},
37+
env: {
38+
browser: true,
39+
jquery: true,
40+
},
41+
settings: {
42+
'import/internal-regex': '^@webapp',
43+
'import/resolver': {
44+
node: {
45+
extensions: ['.ts', '.tsx', '.es6', '.js', '.json', '.svg'],
46+
},
47+
typescript: {
48+
project: 'tsconfig.json',
49+
},
50+
},
51+
},
52+
parserOptions: {
53+
project: ['tsconfig.json'],
54+
},
55+
};

.github/workflows/frontend.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@ jobs:
2525
- run: yarn --frozen-lockfile
2626
- name: Run type-check
2727
run: yarn type-check
28+
format:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v3
33+
- uses: actions/setup-node@v3
34+
with:
35+
node-version: 18.15.0
36+
cache: yarn
37+
- run: yarn --frozen-lockfile
38+
- name: Run format
39+
run: yarn run format
40+
lint:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v3
45+
- uses: actions/setup-node@v3
46+
with:
47+
node-version: 18.15.0
48+
cache: yarn
49+
- run: yarn --frozen-lockfile
50+
- name: Run lint
51+
run: yarn lint
2852
build:
2953
runs-on: ubuntu-latest
3054
steps:

.gitignore

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
# Binaries for programs and plugins
22
bin
3-
# Test binary, built with `go test -c`
4-
*.test
53
/phlare
64
/profilecli
7-
5+
# Test binary, built with `go test -c`
6+
*.test
87
# Output of the go coverage tool, specifically when used with LiteIDE
98
*.out
109

1110
/cmd/phlare/data
1211
data/
1312
.DS_Store
13+
**/dist
1414

15+
# IDE
16+
.idea
17+
.vscode
18+
19+
# Frontend
20+
public/build
21+
cypress/screenshots
22+
.eslintcache
1523
node_modules
1624
/grafana/flamegraph/coverage/
17-
1825
# Yarn
1926
**/.yarn/*
2027
!**/.yarn/patches
@@ -23,17 +30,7 @@ node_modules
2330
!**/.yarn/sdks
2431
!**/.yarn/versions
2532
.pnp.*
26-
27-
28-
**/dist
29-
30-
.idea
31-
32-
dist/
33-
34-
public/build
33+
yarn-error.log
3534

3635
# Contains the docker image id for phlare
3736
/.docker-image-id-phlare
38-
39-
cypress/screenshots

.prettierignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public/build/**
2+
pkg/api/static/**
3+
vendor/**
4+
tools/**
5+
operations/**
6+
api/**
7+
data/**
8+
**/dist
9+
**/testdata
10+
*.md
11+
*.yaml
12+
*.yml
13+
*.html

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "singleQuote": true }

.trunk/config/svgo.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
plugins: [
33
{
4-
name: "preset-default",
4+
name: 'preset-default',
55
params: {
66
overrides: {
77
removeViewBox: false, // https://github.com/svg/svgo/issues/1128

cypress/fixtures/profileTypes.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
["memory:alloc_objects:count::","memory:alloc_space:bytes::","memory:inuse_objects:count::","memory:inuse_space:bytes::","process_cpu:cpu:nanoseconds:cpu:nanoseconds"]
2-
1+
[
2+
"memory:alloc_objects:count::",
3+
"memory:alloc_space:bytes::",
4+
"memory:inuse_objects:count::",
5+
"memory:inuse_space:bytes::",
6+
"process_cpu:cpu:nanoseconds:cpu:nanoseconds"
7+
]

cypress/support/commands.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@
3636
// }
3737
// }
3838
import '@testing-library/cypress/add-commands';
39-

cypress/support/e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// ***********************************************************
1515

1616
// Import commands.js using ES2015 syntax:
17-
import './commands'
17+
import './commands';
1818

1919
// Alternatively you can use CommonJS syntax:
20-
// require('./commands')
20+
// require('./commands')

0 commit comments

Comments
 (0)