Skip to content

Commit 565b5ec

Browse files
committed
🔧 [#244] chore: Add pre-commit path linting
``` npx ast-grep scan --interactive ``` or ``` npx ast-grep scan --update-all ``` or see: https://ast-grep.github.io/guide/project/severity.html#ignore-linting-error
1 parent 5e60375 commit 565b5ec

File tree

5 files changed

+204
-1
lines changed

5 files changed

+204
-1
lines changed

frontend/package-lock.json

Lines changed: 156 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"react-router": "^7.5.0"
2828
},
2929
"devDependencies": {
30+
"@ast-grep/cli": "^0.39.6",
3031
"@chromatic-com/storybook": "^3.2.6",
3132
"@commitlint/cli": "^19.8.0",
3233
"@commitlint/config-conventional": "^19.8.0",
@@ -64,7 +65,7 @@
6465
"vitest": "^3.1.3"
6566
},
6667
"lint-staged": {
67-
"*.{js,ts,md}": "npm run lint:fix"
68+
"*.{js,ts,md}": ["npm run lint:fix", "npx ast-grep scan"]
6869
},
6970
"msw": {
7071
"workerDirectory": [

frontend/rules/py-endpoint.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
id: force-py-endpoint-trailing-slash
2+
language: python
3+
rule:
4+
pattern: $PATH
5+
kind: string
6+
regex: '".+[^/]"'
7+
inside:
8+
kind: argument_list
9+
inside:
10+
kind: call
11+
pattern: path($$$)
12+
transform:
13+
NEW_PATH:
14+
replace:
15+
source: $PATH
16+
replace: "[^/]$"
17+
by: '$1/"'
18+
fix: $NEW_PATH

frontend/rules/ts-endpoint.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
id: ts-force-endpoint-trailing-slash
2+
language: TypeScript
3+
rule:
4+
pattern: $ENDPOINT
5+
any:
6+
- kind: template_string
7+
- kind: string
8+
regex: '[^/]["`]'
9+
follows:
10+
kind: string
11+
regex: (DELETE|GET|PATCH|POST|PUT)
12+
stopBy: end
13+
inside:
14+
any:
15+
- kind: array
16+
inside:
17+
kind: arguments
18+
- kind: arguments
19+
severity: error
20+
transform:
21+
NEW_ENDPOINT:
22+
replace:
23+
source: $ENDPOINT
24+
replace: '(["`])$'
25+
by: "/$1"
26+
fix: $NEW_ENDPOINT

frontend/sgconfig.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ruleDirs:
2+
- ./rules

0 commit comments

Comments
 (0)