-
Notifications
You must be signed in to change notification settings - Fork 40
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: prettier run on newText #353
Open
dylanarmstrong
wants to merge
4
commits into
statelyai:main
Choose a base branch
from
dylanarmstrong:fix/prettier-new-edits
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 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@xstate/cli': patch | ||
--- | ||
|
||
fix: prettier runs on edited files now |
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
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.
Ideally, I'd like to remove the dependency on Prettier altogether. I'd much more prefer to detect the preferred quotes style and just use that within the edit.
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.
Simplest (and hackiest) way I can think of is a check in newFile for number of double quotes vs. number of single quotes and go with whichever is more common. That would remove requirement for prettier, but would be quite ugly.
If prettier was kept, we could check for quotes by using something like:
This all has a downside of ignoring non-quote prettier features that we may violate like line length and trailing commas.
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.
It's rather a safe bet to assume that there is some import statement in the file and we could piggy-back our quotes detection based on that with smth like
/import\s(.|\n)*(['"])/
.I understand the concern but we are not quite in the code formatting business. There are multiple formatters available out there and it would be great to use some pretty generic code that could play well with all of them. I think it's fine that sometimes an additional formatting edit might be required after we insert something into the file, the goal is to minimize the chances of that happening.
Prettier is, of course, vastly popular so we could try to special-case it but I think that this should be done by treating is an optional peer dependency~ whereas right now we always fall back to the local version installed with the CLI if we can't load Prettier relative to
cwd
.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.
I've updated the PR to match this on the CLI, but I'm not able to update the vscode extension to do the same.
I kept the prettify method because It's a useful abstraction that can be removed in the future if prettier is entirely removed.