webcompat / webcompat.com

Source code for webcompat.com
https://webcompat.com
360 stars 191 forks source link

Precommit for JS files on python files commit #1736

Open karlcow opened 7 years ago

karlcow commented 7 years ago

Steps to reproduce:

  1. Modify a python file.
  2. git commit -m 'blabla' python_file.py

Actual: linter for JS and CSS are running. Expected: don't do things I don't need.

Could we just activate this when the files to commit are actually from the lint-checker family.

Example:

git commit -m 'Issue #132 - Adds FEED_PATH in data/' config/environment.py

> husky - npm run -s precommit
> husky - node v6.10.2

 ↓ Running tasks for *.js [skipped]
   → No staged files match *.js
 ↓ Running tasks for *.css [skipped]
   → No staged files match *.css
[132/1 0262f6d] Issue #132 - Adds FEED_PATH in data/
 1 file changed, 4 insertions(+)
karlcow commented 7 years ago

Ah maybe a hint in https://gist.github.com/jhartikainen/36a955f3bfe06557e16e#gistcomment-1990800

"lint-staged": "eslint `git diff --staged --diff-filter=AM --name-only | grep .js$ | tr '\n' ' '`"

Let's add a comment on a python file. Removing --staged

→ git diff --diff-filter=AM --name-only 
config/environment.py
→ git diff --diff-filter=AM --name-only | grep .js$ | tr '\n' ' '
# returns nothing. Cool!

Let's do the same in a JS.

→ git diff --diff-filter=AM --name-only 
config/environment.py
webcompat/static/js/lib/diagnose.js
→ git diff --diff-filter=AM --name-only | grep .js$ | tr '\n' ' '
webcompat/static/js/lib/diagnose.js

Yeah working!