Commit e86a0646 authored by Mike Greiling's avatar Mike Greiling

Merge branch 'mlunoe-add-eslint-staged-scripts' into 'master'

Feat(package.json): add eslint-staged scripts

See merge request gitlab-org/gitlab!34168
parents a739cfe6 d42fd772
......@@ -4,6 +4,44 @@
We use ESLint to encapsulate and enforce frontend code standards. Our configuration may be found in the [`gitlab-eslint-config`](https://gitlab.com/gitlab-org/gitlab-eslint-config) project.
### Yarn Script
This section describes yarn scripts that are available to validate and apply automatic fixes to files using ESLint.
To check all currently staged files (based on `git diff`) with ESLint, run the following script:
```shell
yarn eslint-staged
```
_A list of problems found will be logged to the console._
To apply automatic ESLint fixes to all currently staged files (based on `git diff`), run the following script:
```shell
yarn eslint-staged-fix
```
_If manual changes are required, a list of changes will be sent to the console._
To check **all** files in the repository with ESLint, run the following script:
```shell
yarn eslint
```
_A list of problems found will be logged to the console._
To apply automatic ESLint fixes to **all** files in the repository, run the following script:
```shell
yarn eslint-fix
```
_If manual changes are required, a list of changes will be sent to the console._
**Caution:** Limit use to global rule updates. Otherwise, the changes can lead to huge Merge Requests.
### Disabling ESLint in new files
Do not disable ESLint when creating new files. Existing files may have existing rules
......
......@@ -7,6 +7,8 @@
"dev-server": "NODE_OPTIONS=\"--max-old-space-size=3584\" node scripts/frontend/webpack_dev_server.js",
"eslint": "eslint --cache --max-warnings 0 --report-unused-disable-directives --ext .js,.vue .",
"eslint-fix": "eslint --cache --max-warnings 0 --report-unused-disable-directives --ext .js,.vue --fix .",
"eslint-staged": "git diff --cached --name-only | grep -E \"(.*)\\.(js|vue)$\" | xargs eslint --cache --max-warnings 0 --report-unused-disable-directives",
"eslint-staged-fix": "git diff --cached --name-only | grep -E \"(.*)\\.(js|vue)$\" | xargs eslint --cache --max-warnings 0 --report-unused-disable-directives --fix",
"eslint-report": "eslint --max-warnings 0 --ext .js,.vue --format html --output-file ./eslint-report.html --no-inline-config .",
"file-coverage": "scripts/frontend/file_test_coverage.js",
"prejest": "yarn check-dependencies",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment