sudo-suhas / lint-staged-multi-pkg

Example repo to demonstrate use of `lint-staged` with multi-pkg projects
MIT License
188 stars 19 forks source link

It didn't work! #23

Closed DrReMain closed 4 years ago

DrReMain commented 4 years ago

I just clone the repo, change the eslintrc: no-console: off -> no-console: error.

then

$ npx lerna bootstrap
$ git add .
$ git commit -m "test"

the result is:

husky > pre-commit (node v8.17.0) lerna notice cli v3.13.1 lerna info Executing command in 2 packages: "yarn run precommit" say-bye: yarn run v1.22.1 say-bye: $ lint-staged say-bye: Running tasks for lib/.js [started] say-bye: Running tasks for lib/.js [skipped] say-bye: → No staged files match lib/.js say-bye: Done in 0.46s. say-hi: yarn run v1.22.1 say-hi: $ lint-staged say-hi: Running tasks for src/.js [started] say-hi: Running tasks for src/.js [skipped] say-hi: → No staged files match src/.js say-hi: Done in 0.43s. lerna success run Ran npm script 'precommit' in 2 packages in 1.3s: lerna success - say-bye lerna success - say-hi [test 7ade78b] test 2 files changed, 2 insertions(+), 2 deletions(-)

I tried under win10/osx/ubuntu-18.04, they ware same.

sudo-suhas commented 4 years ago

Did you change any files before trying?

sudo-suhas commented 4 years ago

git diff --staged:

diff --git a/packages/say-bye/lib/index.js b/packages/say-bye/lib/index.js
index 4f72dff..4e321fc 100644
--- a/packages/say-bye/lib/index.js
+++ b/packages/say-bye/lib/index.js
@@ -1,5 +1,7 @@
 'use strict';

+let unused;
+
 module.exports = function sayBye() {
     console.log('Bye!')
 }
lint-staged-multi-pkg on master [+] via ⬢ v12.16.1
➜ git commit
husky > pre-commit (node v12.16.1)
lerna notice cli v3.13.1
lerna info Executing command in 2 packages: "yarn run precommit"
say-bye: yarn run v1.22.0
say-bye: $ lint-staged
say-bye: Running tasks for lib/*.js [started]
say-bye: eslint --fix [started]
say-bye: eslint --fix [failed]
say-bye: →
say-bye: Running tasks for lib/*.js [failed]
say-bye: →
say-bye: ✖ "eslint --fix" found some errors. Please fix them and try committing again.
say-bye:
say-bye: /Users/skaranth/dev/oss/lint-staged-multi-pkg/packages/say-bye/lib/index.js
say-bye: 3:1  error  Parsing error: The keyword 'let' is reserved
say-bye: ✖ 1 problem (1 error, 0 warnings)
say-bye: error Command failed with exit code 1.
say-bye: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
lerna ERR! yarn run precommit exited 1 in 'say-bye'
husky > pre-commit hook failed (add --no-verify to bypass)
DrReMain commented 4 years ago

I tried your demo, It's ok。 But I just change the eslintrc

$ git diff --staged
diff --git a/packages/say-bye/.eslintrc.yml b/packages/say-bye/.eslintrc.yml
index 3cd50c3..013b33e 100644
--- a/packages/say-bye/.eslintrc.yml
+++ b/packages/say-bye/.eslintrc.yml
@@ -2,4 +2,4 @@ extends: eslint:recommended
 env:
   node: true
 rules:
-  no-console: off
+  no-console: error
diff --git a/packages/say-hi/.eslintrc.yml b/packages/say-hi/.eslintrc.yml
index 3cd50c3..013b33e 100644
--- a/packages/say-hi/.eslintrc.yml
+++ b/packages/say-hi/.eslintrc.yml
@@ -2,4 +2,4 @@ extends: eslint:recommended
 env:
   node: true
 rules:
:...skipping...
diff --git a/packages/say-bye/.eslintrc.yml b/packages/say-bye/.eslintrc.yml
index 3cd50c3..013b33e 100644
--- a/packages/say-bye/.eslintrc.yml
+++ b/packages/say-bye/.eslintrc.yml
@@ -2,4 +2,4 @@ extends: eslint:recommended
 env:
   node: true
 rules:
-  no-console: off
+  no-console: error
diff --git a/packages/say-hi/.eslintrc.yml b/packages/say-hi/.eslintrc.yml
index 3cd50c3..013b33e 100644
--- a/packages/say-hi/.eslintrc.yml
+++ b/packages/say-hi/.eslintrc.yml
@@ -2,4 +2,4 @@ extends: eslint:recommended
 env:
   node: true
 rules:
-  no-console: off
+  no-console: error

It's fail,why

sudo-suhas commented 4 years ago

lint-staged runs for changed JS files. Even if your ESLint config is updated, unless there are any source files modified, the pre-commit hook won't catch them.