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

feature request: Check if a file is sorted already #6

Open
tylerbutler opened this issue Mar 19, 2024 · 1 comment · May be fixed by #7
Open

feature request: Check if a file is sorted already #6

tylerbutler opened this issue Mar 19, 2024 · 1 comment · May be fixed by #7

Comments

@tylerbutler
Copy link
Contributor

Thanks for the great library! I am using it to add some determinism to our tsconfig files in our monorepo. One thing that would be helpful for us is a faster way to check if a file is already sorted. We run checks in CI to verify that files are in the right state, and while we can just "always sort" it is a little slow compared to our other "checks."

I was thinking that it would be easiest to implement something like this in the core library. I am willing to open a PR if you have suggestions for where and how to implement this.

There should probably be a corresponding flag on the CLI package, too.

@duniul
Copy link
Owner

duniul commented Mar 19, 2024

Hey!

I think an isSorted() export could make sense, with e.g. a --check flag on the CLI 👍 The simplest way I can think of would be to basically go through the parsed data like the sorter does, but only comparing fields with their next sibling. If we encounter a value that should be before it's sibling, we exit early.

Since the comments are irrelevant to the order of the fields, there is a possibility that it would be faster to just strip all comments and use a regular JSON.parse, but I'm not sure if that would be worth it.

If you're keen then a PR is of course super welcome! ⭐

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