From 7db4ad5b433bb28cc36d472821000e01d944b09d Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Fri, 16 Jun 2023 19:21:51 -0400 Subject: [PATCH 1/3] add requirements.txt and precommit --- .pre-commit-config.yaml | 11 +++++++++++ requirements.txt | 9 +++++++++ 2 files changed, 20 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 requirements.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..6bc346ff --- /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/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 From 114f24630efc60c894b5d63652384797f75c500c Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Fri, 16 Jun 2023 19:32:53 -0400 Subject: [PATCH 2/3] add ADR for pre commit --- .../0007-add-pre-commit-hooks-and-directions | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 docs/adr/0007-add-pre-commit-hooks-and-directions 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) From d4195521dfcc96cd5f10cc0a5433e6e8e504d56a Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Thu, 17 Aug 2023 11:16:30 -0400 Subject: [PATCH 3/3] update pre-commit config --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6bc346ff..a78ef9d2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,6 @@ repos: entry: ./node_modules/.bin/eslint language: script types: [javascript] - args: ["--ignore-path .gitignore /\"**/*.{js,jsx}\"", "--fix"] + args: ["--ignore-path .gitignore /\"**/*.{js,jsx}\" , --fix"] pass_filenames: true always_run: false