jsonlint icon indicating copy to clipboard operation
jsonlint copied to clipboard

Support for multiple files/glob patterns on cli.

Open ginman86 opened this issue 8 years ago • 7 comments

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

ginman86 avatar Dec 15 '15 19:12 ginman86

:+1:

nisaacson avatar Dec 15 '15 19:12 nisaacson

:+1:

mdjnewman avatar Jan 26 '16 02:01 mdjnewman

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...

dawsbot avatar Mar 06 '16 19:03 dawsbot

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.

EvHaus avatar Apr 21 '16 16:04 EvHaus

Added a few updates that should address the comments. Almost 3 years to the day 🍾 Cheers.

ginman86 avatar Dec 17 '19 21:12 ginman86

Any updates to this? This is really useful feature.

kopach avatar Mar 02 '22 10:03 kopach

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.

callumgare avatar May 13 '22 01:05 callumgare