git-validate
git-validate copied to clipboard
Finding extra package.json files
In my project we run all the code through a build process that dumps the output into a build directory off the project root. This directory is happily git ignored and all.
However, if I'm reading it right, because find is recursive (https://github.com/nlf/git-validate/blob/master/bin/validate.sh#L339), it picks up this other package.json and tries to run the validations from within that build directory. This leads to failures due to missing dependencies, which I expect. I don't want to run the validations against the build directory.
I'm not entirely sure what the best approach to fixing this would be. I assume there's a reason why max-depth of 1 wouldn't be appropriate, but at the same time, I'd rather not delete my build just to lint my project. I'm not sure this is even a "bug" with git-validate.
Do you have any guidance on this? I'd hate to add another config file to the project's root. I suppose I could move the build directory outside of the project, but I like everything being self-contained as well.
what if i added a config field to package.json so you could do something like
{
'git-validate': {
ignore: 'build'
}
}
and any packages found in the 'build' directory (which would be a direct child of the current directory, i'd just use path.join with the root) would be ignored. sound ok?
That sounds like a great solution. Thank you!
This solution would only be suboptimal. Since I git-validate is used to create modules that configure your project to use hooks, the module can't know upfront what to ignore.
IMO a better approach would be to limit the search scope to .git/../
My suggestion to look for package.json:
local projects;
projects=$(find . -maxdepth 1 -name package.json -print 2>/dev/null)
if [[ $? -ne 0 ]]; then
projects=$(find . -not -iwholename '*node_modules*' -not -iwholename '*bower_components*' -maxdepth 3 -name package.json -print 2>/dev/null)
fi
if [[ $? -ne 0 ]]; then
projects=$(find . -not -ipath '*node_modules*' -not -ipath '*bower_components*' -maxdepth 3 -name package.json -print 2>/dev/null)
fi
If you don't find a package.json at the root level continue to dig deeper.
thinking about using git ls-files instead so that anything that's not committed to the repo won't be found, this solves the problem of node_modules and of things that are .gitignored
thoughts?
noting that i'll still filter out node_modules since some people commit those
@nlf Any update on this issue?