Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with relative paths #143

Closed
montogeek opened this issue Mar 27, 2017 · 3 comments
Closed

Error with relative paths #143

montogeek opened this issue Mar 27, 2017 · 3 comments

Comments

@montogeek
Copy link

Hi!

I am using lint-staged in a subfolder, with the following configuration:

"scripts": {
    "format-js": "./node_modules/.bin/prettier --single-quote --print-width=90 --trailing-comma=all --write '{src,test}/**/*.js'",
    "format-css": "./node_modules/.bin/stylefmt src/styles/main.css"
}
"lint-staged": {
    "gitDir": "../../../",
    "linters": {
      "subpath/src/**/*.js": [
        "yarn format-js",
        "git add"
      ],
      "subpath/src/styles/**/*.css": [
        "yarn format-css",
        "git add"
      ]
    }
  }

When trying to commit it fails with the following error:

montogeek ~/project_path/subpath [01:16 AM]→ 😀  (feature/app)
👉  git commit -S -m "SVG Icons!"
git commit -S -m "SVG Icons"

> husky - npm run -s precommit

 ❯ Running tasks for subpath/src/**/*.js
   → yarn format-js v0.21.3
   ✖ yarn format-js
     → yarn format-js v0.21.3
     git add
 ↓ Running tasks for subpath/src/styles/**/*.css [skipped]
   → No staged files match subpath/src/styles/**/*.css
🚫 yarn format-js found some errors. Please fix them and try committing again.
error Couldn't find a package.json file in "/Users/montogeek/project_path"

yarn format-js v0.21.3


> husky - pre-commit hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run precommit'
montogeek ~/project_path/subpath [01:16 AM]→ 😀  (feature/app)
👉  npm run precommit

> instagram@1.0.0 precommit /Users/montogeek/project_path/subpath
> lint-staged --verbose

 ❯ Running tasks for subpath/src/**/*.js
   → yarn format-js v0.21.3
   ✖ yarn format-js
     → yarn format-js v0.21.3
     git add
 ↓ Running tasks for subpath/src/styles/**/*.css [skipped]
   → No staged files match subpath/src/styles/**/*.css
🚫 yarn format-js found some errors. Please fix them and try committing again.
error Couldn't find a package.json file in "/Users/montogeek/project_path"

yarn format-js v0.21.3


npm ERR! Darwin 16.5.0
npm ERR! argv "/Users/montogeek/.nvm/versions/node/v7.7.2/bin/node" "/Users/montogeek/.nvm/versions/node/v7.7.2/bin/npm" "run" "precommit"
npm ERR! node v7.7.2
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! instagram@1.0.0 precommit: `lint-staged --verbose`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the instagram@1.0.0 precommit script 'lint-staged --verbose'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the instagram package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     lint-staged --verbose
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs instagram
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls instagram
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/montogeek/project_path/subpath/npm-debug.log

But running the npm script works without problem:

montogeek ~/project_path/subpath [01:17 AM]→ 😀  (feature/app)
👉  yarn format-js
yarn format-js v0.21.3
$ ./node_modules/.bin/prettier --single-quote --print-width=90 --trailing-comma=all --write '{src,test}/**/*.js'
src/components/footer.js 79ms
src/components/icon.js 16ms
src/components/post.js 195ms
src/components/navbar.js 9ms
src/containers/App.js 11ms
src/instagram-api.js 29ms
src/main.js 8ms
✨  Done in 0.94s.

Why it is trying to find a package.json at the root of the project?

@okonet
Copy link
Collaborator

okonet commented Mar 27, 2017

I honestly don't know. If you believe there is a bug in lint-staged, please provide me with a reproducible repo on GitHub.

I've also noticed that your config isn't quite correct: you don't need file globs in your tasks when running them with lint-staged since this is what this lib is responsible for — passing the matched file paths to scripts.

It also supports npm run out of the box so you don't need yarn part either nor you need the ./node_modules/.bin/ when defining scripts in package.json.

I'd recommend to try this config out:

"lint-staged": {
    "gitDir": "../../../",
    "linters": {
      "subpath/src/**/*.js": [
        "prettier --single-quote --print-width=90 --trailing-comma=all --write",
        "git add"
      ],
      "subpath/src/styles/**/*.css": [
        "stylefmt",
        "git add"
      ]
    }
  }

@montogeek
Copy link
Author

@okonet Thanks, it works!
I missed passing the matched file paths to scripts in the docs.
What if I need/want a npm script?

@okonet
Copy link
Collaborator

okonet commented Mar 27, 2017

Same. Just use the name of your script and "it will just work" tm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants