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

Why filter on file name? #50

Open
Ghostbird opened this issue May 23, 2024 · 0 comments
Open

Why filter on file name? #50

Ghostbird opened this issue May 23, 2024 · 0 comments

Comments

@Ghostbird
Copy link

const files = argv._.filter(arg => arg.endsWith('.json') || arg.endsWith('.rc'));

Due to this line, if I run npx sort-json client-generation.nswag nothing happens. Even though I have explicitly stated that I want to sort the JSON of that file.

In our case, the lint-staged tooling passes a list of files (based on configuration) to sort-json, but we found out some of them never get sorted, because they don't end in .json or .rc. In fact, we have no JSON files ending in .rc at all, but we have some JSON files with other extensions.

Was this added to support stuff like npx sort-json *? Because I think that kind of laziness shouldn't be supported in such a way.

  • One philosophy is that the user of the tool should not feed it invalid data. It's not that much harder to write a proper statement such as: npx sort-json $(ls *.{json,rc}) (bash example).
    Exmple: If you accidentally run sudo rm -rf /* instead of sudo rm -rf ./*, you can go and reinstall your OS, and hope you backed up your files.
  • Another philosophy is that if the tool can handle it, it must be forgiving. It might be an idea to not abort on an unparseable file, maybe write a warning to stderr. E.g. Skipping because it doesn't contain valid JSON and just continue with the next file.
    Example: If you run sudo rm -rf / most rm implementations will refuse.

Option two runs the risk of performing poorly in some situations, but only if the user doesn't obey the first philosophy and feeds it a large number of non-JSON files. I think either option is superior to the current implementation.

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

No branches or pull requests

1 participant