lint-staged / lint-staged

🚫💩 — Run linters on git staged files

Home Page:https://www.npmjs.com/package/lint-staged

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File matching a parent directory

rondog opened this issue · comments

I just have a question of file matching and dont even know if this is possible. I have my package.json in a subfolder /docroot/themes/custom/my_theme/package.json and I am using lint-staged to run some precommit git hooks, but I cant get the file pattern matching to work for files that are in parent directories.

I want to search for files in /docroot/modules/custom/**/*.php

I have tried

"docroot/modules/custom/**/*.php": [
  "phpcs --standard=Drupal"
]

"/docroot/modules/custom/**/*.php": [
  "phpcs --standard=Drupal"
]

"modules/custom/**/*.php": [
  "phpcs --standard=Drupal"
]

"../../../modules/custom/**/*.php": [
  "phpcs --standard=Drupal"
]

and I cannot get any of them to match files. My git root is in the /docroot folder. Any ideas?

See #425

I had the same issue but settled on using 4.x until @sudo-suhas adds a flag to disable path-inside.

I personally prefer we don't go down this route as this is a rare use-case AFAIK.

I think it has garnered enough interest to warrant this change.

I'd be open to a PR which adds a flag for disabling the path-is-inside check which would default to true so that it is backward compatible. @okonet Are we in agreement on this? TBH I still stand by the concerns I had raised in #425 (comment).

I agree, path-is-inside should default to true. I would need it false for our internal development testing. My use case is using drupal, we distribute a theme file per project that contains the package.json and gulpfile.js that helps us with our sass compiling, but recently I have added husky and lint-staged that runs eslint, stylelint and phpcs to keep our devs using the standards we define.

The one caveat is we usually do custom module development in PHP which I would like to run phpcs against, but those modules live in some parent directories as described in my OP.

To your comment in 425, our use case is the project is always organized the exact same way, but I would say the majority if projects you are correct in it should not assume out of scope organization.

My other option would be to move package.json to webroot, but that would require some initial changes to our gulpfile which is what I was trying to avoid.

awesome, thank you very much!

@sudo-suhas looking at your note:

Note that patterns like *.js, **/*.js will still only match the project files and not any of the files in parent or sibling directories.

Am I understanding that the change committed in #425 can't use pattern matching in the parent folders? If I am understanding that correctly, that means I would have to define exactly which file to lint? Can you confirm that my original question will work with this commit?

never mind, I understand your note now. You mean specifically *.js and **/*.js will be project level only. Makes sense. Thank you for the contribution!