diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..a78ef9d2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: +- repo: local + hooks: + - id: eslint + name: eslint + entry: ./node_modules/.bin/eslint + language: script + types: [javascript] + args: ["--ignore-path .gitignore /\"**/*.{js,jsx}\" , --fix"] + pass_filenames: true + always_run: false diff --git a/docs/adr/0007-add-pre-commit-hooks-and-directions b/docs/adr/0007-add-pre-commit-hooks-and-directions new file mode 100644 index 00000000..fe63138f --- /dev/null +++ b/docs/adr/0007-add-pre-commit-hooks-and-directions @@ -0,0 +1,63 @@ +# NUMBER. ADD LINTING PRECOMMIT + +- Status: proposed : 2023-05-23 accepted: 2023-05-31 +- Deciders: Orbaco +- Date: 2023-05-31 + +Technical Story: [link to discussion issue](https://github.com/NASA-IMPACT/admg-casei/issues/522) + +## Context and Problem Statement + +[Describe the context and problem statement, e.g., in free form using two to three sentences. You may want to articulate the problem in form of a question.] + +## Decision Drivers + +- Discussion from post-mortem in reference ticket. + +## Considered Options + +- Local development environment for CASEI can more closely resemble Github Actions runners by using dev containers. +- Configuring a threshold for Jest unit tests +- pre-commit hooks for linting procedures in CI +- Pin versions in package.json + +## Decision Outcome + +Chosen option: to add pre-commit hooks because it will not slow commit and development process during feature development and is ultimately optional. + +### Positive Consequences + +- Use a python environment and pre-commit hooks to run `eslint` and other commands before they fail in CI. +- No debugging of linting issues in CI +- Automate `eslint` so developers do not need to remember to run it manually. + +### Negative Consequences + +### Pre-requisites +- Python virtualenv (venv, pyenv virtualenv, etc) +- Install pre-commit package + +### Setup +``` + # activate your pyenv environment + example... `pyenv activate casei-nodeenv` + + # install all requirements + pip install -r requirements.txt + + # OR install pre-commit + pip install pre-commit + + # install the local repository pre commits + pre-commit install + + # test a change a git commit + git add -A && git commit -m "testing pre commits" + + # optional: run on all files + pre-commit run --all-files +``` + +## Links + +- [Pre-commit library](https://pre-commit.com/index.html#plugins) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..50a058ab --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +cfgv==3.3.1 +distlib==0.3.6 +filelock==3.12.2 +identify==2.5.24 +nodeenv==1.7.0 +platformdirs==3.5.3 +pre-commit==3.3.3 +PyYAML==6.0 +virtualenv==20.23.1