-
Notifications
You must be signed in to change notification settings - Fork 27
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
fix(sort-collections): avoid sorting exports
by default
#918
Open
GeorgeTaveras1231
wants to merge
6
commits into
JoshuaKGoldberg:main
Choose a base branch
from
GeorgeTaveras1231:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0c1858f
Remove `exports` from default
GeorgeTaveras1231 6b43325
Update tests and documentation
GeorgeTaveras1231 426a390
Add .tool-versions file for asdf users
GeorgeTaveras1231 4a6e755
Revert "Add .tool-versions file for asdf users"
GeorgeTaveras1231 f4821f4
Add a valid test
GeorgeTaveras1231 23e9afe
Remove unnecessary keys from valid test
GeorgeTaveras1231 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,8 +103,7 @@ Defaults: | |
"dependencies", | ||
"peerDependencies", | ||
"overrides", | ||
"config", | ||
"exports" | ||
"config" | ||
] | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Testing] Oh, sorry, I wasn't clear in what I meant to ask for - could you please add a
valid
test too?I think there are really two points of logic that are relevant+important to test for this change:
"exports"
options
,"exports"
does get sortedThis test checks the latter but not the former.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoshuaKGoldberg about this - should we consider warning developers or requiring a separate flag to enable dangerous keys? I think there is an opportunity here to educate people on the dangers of sorting
exports
andimports
alphabetically (while still giving them the choice if this is what they want to do).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe as a quick mention in the docs file that links to the first-party package.json docs? I don't think a separate flag is justified yet. Someone who reads through the docs to know about the option is probably pretty high intent anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hahaha that is fair
I'm laughing because I'm realizing I have a cynical tendency to think people will not read the documentation lol
No worries, I will add a note in the docs 👍🏽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoshuaKGoldberg I think this is my last alignment question.
I was working on the docs and realized that this rule only does a top-level sort (not recursively) so at the moment, it only causes problems if you have a condition object at the top level.
i.e.
This breaks when auto-fixed
This is ok
Since the error case is easily distinguishable, it made me think we are putting too much responsibility on the consumer to know wether its safe or not safe to sort.
What do you think about just adding a check to the sorter? - to only sort if its not a condition object (the heuristic per the standards is to check if the keys start with
.
)It would be a totally different approach, we may be able to leave
exports
in the list of defaults but make it safer.I'm ok with putting this in a separate PR and closing this one, or repurposing this one. What do you think?