jsonlint
jsonlint copied to clipboard
Support for multiple files/glob patterns on cli.
What does this PR do?
This PR allows for a list of files, or a glob pattern to be used on the jsonlint cli.
Ex.
jsonlint app/**/*.json
or jsonlint somefile.json someotherfile.json
How to test this PR?
Pull this fork locally, and create a symlink using npm link
inside the directory.
Create a few json files and run a command similar to
jsonlint app/**/*.json
or jsonlint somefile.json someotherfile.json
or jsonlint *.json
You can also pull the fork into an existing project via
npm install ginman86/jsonlint --save-dev
:+1:
:+1:
Fix this and get it live? Seems critical to the functionality of jsonlint
. For now this is a tool that operations on files but doesn't support file globbing...
Thanks for this fork. There is an issue however. If one of your glob patterns finds no matches the CLI breaks with:
> jsonlint html/js/**/*.json
fs.js:584
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT: no such file or directory, open 'html/js/**/*.json'
I think unmatched directories should simply be ignored instead of thrown.
Added a few updates that should address the comments. Almost 3 years to the day 🍾 Cheers.
Any updates to this? This is really useful feature.
I'd also love to see this implemented! For anyone wanting a workaround in the mean time here's what I went with:
find . -iname '*.json' -not -path './.git/*' -not -path './node_modules/*' | xargs -L 1 jsonlint -q -c
Broken down:
find . -iname '*.json'
gets a list of all json files recursively in the current directory.
-not -path './.git/*'
and -not -path './node_modules/*'
excludes any json files in the .git dir or the node_modules dir.
| xargs
pipes stdout (in this case our list of json file paths) and execules a given command with the stdout as an argument to that command.
-L 1
tell xargs to break the stdout into sperate lines and execute the given command once for each line (rather than once with all the lines as sepreate arguments to that single command). If you have a lot of json files this prevents the possibility of hitting command length limits.
jsonlint -q -c
is the command we give to xargs to execute for each json file path with that path append to the end of the command. The -q flag tells jsonlint not to print the contents of the file and -c gives us more readable error messages.