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

Support for multiple files/glob patterns on cli. #75

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ginman86
Copy link

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

@nisaacson
Copy link

👍

@ginman86 ginman86 mentioned this pull request Jan 4, 2016
@mdjnewman
Copy link

👍

mdjnewman added a commit to mdjnewman/jasmine-moment-matchers that referenced this pull request Jan 26, 2016
@dawsbot
Copy link

dawsbot commented Mar 6, 2016

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

@EvHaus
Copy link

EvHaus commented Apr 21, 2016

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.

@ginman86
Copy link
Author

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

@kopach
Copy link

kopach commented Mar 2, 2022

Any updates to this? This is really useful feature.

@callumgare
Copy link

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.

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

Successfully merging this pull request may close these issues.

9 participants