webpack-autoconf icon indicating copy to clipboard operation
webpack-autoconf copied to clipboard

Proposal: Add ESLint, git pre-hooks

Open theajr opened this issue 5 years ago • 12 comments

Hello @jakoblind

To maintain consistent coding standards in this repository, we should add the following.

Please have a look and let me know your thoughts.

theajr avatar Oct 16 '19 09:10 theajr

Good idea, I agree. I'm not sure we need both lint-staged and husky. Isn't one of them enough?

We also need to agree on the eslint rules. I suggest starting with something not too strict, and then add rules continuously.

jakoblind avatar Oct 16 '19 09:10 jakoblind

@jakoblind In most of the cases lint-staged and husky are being used together. I will try to analyse more and update you.

And coming to eslint rules, my choice would be using eslint:recommended, airbnb, plugin:prettier/recommended and prettier/react.

theajr avatar Oct 16 '19 10:10 theajr

I'll keep this issue open because there are some remaining tasks related to cleaning up the code. I quote @theajr from his merged PR:

here are 240+ error altogether, for now I updated eslint rules such that they will be ignored. We should fix them some at a time. Below are the high priority ones and having more errors react/prop-types - having 90 errors. We should define propTypes for all components. react/destructuring-assignment - having 34 errors.

jakoblind avatar Oct 18 '19 06:10 jakoblind

@jakoblind Sure, You can assign this issue to me. I am already done with adding prop-types for all components. I will raise a pull request in couple of minutes.

theajr avatar Oct 18 '19 06:10 theajr

awesome @theajr ! :+1:

jakoblind avatar Oct 18 '19 06:10 jakoblind

For some reason I get an error when I try to commit code now.

lind@localhost ~/d/webpack-autoconf (master)> git commit -m "test"
husky > pre-commit (node v10.15.3)
  ↓ Stashing changes... [skipped]
    → No partially staged files found...
  ❯ Running tasks...
    ❯ Running tasks for src/**/*.{js,jsx,ts,tsx}
      ✔ eslint --fix
      ✔ prettier —-write
      ✖ npm test
        git add



✖ npm test found some errors. Please fix them and try committing again.

> [email protected] test /home/jlind/dev/webpack-autoconf
> jest "/home/jlind/dev/webpack-autoconf/src/components/configurator/Features.js"

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /home/jlind/dev/webpack-autoconf
818 files checked.
testMatch:  - 0 matches
testPathIgnorePatterns: node_modules, .cache - 734 matches
testRegex: /.*(__tests__\/.*)|(.*(test|spec))\.jsx?$ - 9 matches
Pattern: /home/jlind/dev/webpack-autoconf/src/components/configurator/Features.js - 0 matches
npm ERR! Test failed.  See above for more details.
husky > pre-commit hook failed (add --no-verify to bypass)
jlind@localhost ~/d/webpack-autoconf (master) [1]> git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   src/components/configurator/Features.js

Any ideas before I start debugging?

jakoblind avatar Oct 18 '19 07:10 jakoblind

@jakoblind I faced it and fixing it now.

Root cause: in lint-staged object, we have regex to run commands on src/**/*.{js,jsx,ts,tsx} which is return all staged js, jsx, ts, and tsx files. but npm test expects *.test.js or *.spec.js, as our matching files are note test/specs, it's throwing the error.

I am trying to find the way to handle this case.

theajr avatar Oct 18 '19 07:10 theajr

Ok I see. If it's too much work fixing, we could consider disabling running tests on commit.

jakoblind avatar Oct 18 '19 07:10 jakoblind

To unblock yourself, you can move npm test to pre-push hook like shown in this screenshot.

Screenshot 2019-10-18 at 12 55 36 PM

theajr avatar Oct 18 '19 07:10 theajr

I'm thinking maybe that's a good long term solution? To run tests on push instead. :thinking:

jakoblind avatar Oct 18 '19 07:10 jakoblind

I'm thinking maybe that's a good long term solution? To run tests on push instead. 🤔

I totally agree. We can go with this approach then.

theajr avatar Oct 18 '19 07:10 theajr

@jakoblind Please review the raised PR.

theajr avatar Oct 18 '19 07:10 theajr