oui icon indicating copy to clipboard operation
oui copied to clipboard

Change pre-commit hook to only lint

Open BSFishy opened this issue 2 years ago • 5 comments

The current pre-commit hook takes a non-insignificant amount of time. It would be nice if our precommit hook mirrored OSD's and only ran the linter (assuming it will run in an insignificant amount of time).

BSFishy avatar Oct 09 '23 19:10 BSFishy

hi @BSFishy ,

Hope you are doing well! I can work on this issue for you. I just wanted to clarify before I get started: you want "test-staged" to only run lint and absolutely nothing else?

Thanks!

DustyDogCodex avatar Oct 10 '23 00:10 DustyDogCodex

I just wanted to clarify before I get started: you want "test-staged" to only run lint and absolutely nothing else?

Here is the outcome I envision: when making a commit, only the linter is run (ideally, it is only run on files which have been added, modified, etc., but for this task, running the linter in its entirety is fine).

I think 2 parts will be involved:

  1. Changing the script that is run for precommit (to lint):

    https://github.com/opensearch-project/oui/blob/a1b90296c324ac936f2c6594f694324ef299cd44/package.json#L92-L94

  2. Changing test staged to run only the scripts/test-staged.js script (without running the lint script):

    https://github.com/opensearch-project/oui/blob/a1b90296c324ac936f2c6594f694324ef299cd44/package.json#L32

BSFishy avatar Oct 10 '23 16:10 BSFishy

Hi @BSFishy ,

Thanks for responding to my comment! I will use your comment as a guideline while I work on this issue.

Cheers!

DustyDogCodex avatar Oct 10 '23 21:10 DustyDogCodex

hi @BSFishy ,

Hope you are doing well! I saw your comment in the discussion for lint-staged as a dependency. I agree with the points you made, so I will try and write a script instead of adding a new dependency. Can I submit a new PR with that script once its complete?

Thanks!

DustyDogCodex avatar Oct 18 '23 15:10 DustyDogCodex

Can I submit a new PR with that script once its complete?

Absolutely! Ideally, this is what runs pre-commit instead of linting the entire project. The script should be relatively simple too, some pseudocode:

changes -> files that were added, changed, renamed, etc.

eslint_changes -> changes that have the proper suffix (.js, .ts, .tsx, etc.)
if eslint_changes is not empty then
  run eslint on eslint_changes
endif

sass_lint_changes -> changes that have the proper suffix (.scss, etc.)
if sass_lint_changes is not empty then
  run sass-lint on sass_lint_changes
endif

That should be good. I don't think we should run Typescript type checking to pre-commit, as you can only check the entire project and it will run in CI anyway.

BSFishy avatar Oct 18 '23 17:10 BSFishy