Skip to content

Commit

Permalink
chore: lint-staged for web (#5155)
Browse files Browse the repository at this point in the history
* chore: staged-lint

* chore: new commands

* chore: new commands with `realpath`

* chore: create shell script for pre-commit

* fix: pop first element
  • Loading branch information
keita-determined authored Oct 3, 2022
1 parent f920bde commit a2a66b7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
15 changes: 6 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ repos:
hooks:
- id: web-js-lint-check
name: Web JS Lint Check
entry: bash -c 'make -j$(nproc) -C webui/react check-eslint check-prettier-js'
entry: sh ./pre-commit/web_lint_check.sh js
language: system
files: 'webui/react/src/'
files: '^webui/react/src/'
types_or: [javascript, jsx, ts, tsx]
pass_filenames: false
- id: web-css-lint-check
name: Web CSS Lint Check
entry: bash -c 'make -j$(nproc) -C webui/react check-prettier-css check-stylelint'
entry: sh ./pre-commit/web_lint_check.sh css
language: system
files: 'webui/react/src/'
files: '^webui/react/src/'
types_or: [css, less, scss]
pass_filenames: false
- id: web-misc-lint-check
name: Web Misc Lint Check
entry: bash -c 'make -j$(nproc) -C webui/react check-prettier-misc check-package-lock'
entry: sh ./pre-commit/web_lint_check.sh misc
language: system
files: 'webui/react/src/'
files: '^webui/react/'
types_or: [markdown, json]
pass_filenames: false
5 changes: 5 additions & 0 deletions pre-commit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Pre-Commit

This is a folder to store scripts for [Pre-Commit](https://pre-commit.com/)

Config file for `Pre-Commit` is located at [.pre-commit-config.yaml](../.pre-commit-config.yaml)
14 changes: 14 additions & 0 deletions pre-commit/web_lint_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

D=webui/react
target=$1
shift
files=$(realpath --relative-to="$D" "${@}" | tr "\n" " ")

case $target in
js ) make -j$(nproc) -C "$D" prettier PRE_ARGS="-- -c $files" eslint ES_ARGS="$files" ;;
css ) make -j$(nproc) -C "$D" prettier PRE_ARGS="-- -c $files" stylelint ST_ARGS="$files" ;;
misc ) make -j$(nproc) -C "$D" prettier PRE_ARGS="-- -c $files" check-package-lock ;;
* ) echo "unknonwn target '$target'"; exit 1 ;;

esac
14 changes: 12 additions & 2 deletions webui/react/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,22 @@ live: check-requirements start
start:
npm start

.PHONY: prettier-check
prettier:
npm run prettier $(PRE_ARGS)
.PHONY: stylelint
stylelint:
npm run stylelint $(ST_ARGS)
.PHONY: eslint
eslint:
npm run eslint $(ES_ARGS)

.PHONY: check-eslint
check-eslint:
npm run eslint
npm run lint:eslint
.PHONY: check-stylelint
check-stylelint:
npm run stylelint
npm run lint:style
check-prettier-js:
npm run format-check:js > /dev/null
check-prettier-css:
Expand Down
7 changes: 5 additions & 2 deletions webui/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
"postshrinkwrap": "npx npm-force-resolutions && npm install --ignore-scripts",
"start": "craco start",
"build": "craco build",
"eslint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
"stylelint": "stylelint --config .stylelintrc.js \"src/**/*.{css,less,scss}\"",
"prettier": "prettier",
"eslint": "eslint",
"stylelint": "stylelint --config .stylelintrc.js",
"lint:eslint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
"lint:style": "stylelint --config .stylelintrc.js \"src/**/*.{css,less,scss}\"",
"lint": "npm run eslint && npm run stylelint && npm run format-check",
"format": "npm run format:js && npm run format:css && npm run format:misc",
"format:js": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
Expand Down

0 comments on commit a2a66b7

Please sign in to comment.