-
-
Notifications
You must be signed in to change notification settings - Fork 724
fix(linter): Fix the react/jsx-fragments rule config to take a string argument
#16175
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
Open
connorshea
wants to merge
7
commits into
main
Choose a base branch
from
react-fragment-string-arg
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.
+67
−45
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7aab353
fix(linter): react/jsx-fragments rule should take string argument.
connorshea 82c876f
Update the diagnostics to use backticks.
connorshea 266e081
Allow a string arg or an object argument for backwards-compatibility.
connorshea 84426a7
Clean up the from_configuration method a bit.
connorshea 28d356a
Refactor to use an enum.
connorshea 65f8344
Update to use DefaultRuleConfig for configuration parsing
connorshea 5379f68
[autofix.ci] apply automated fixes
autofix-ci[bot] 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,23 +1,30 @@ | ||
| --- | ||
| source: crates/oxc_linter/src/tester.rs | ||
| --- | ||
| ⚠ eslint-plugin-react(jsx-fragments): Shorthand form for React fragments is preferred | ||
| ⚠ eslint-plugin-react(jsx-fragments): Shorthand form for React fragments is preferred. | ||
| ╭─[jsx_fragments.tsx:1:2] | ||
| 1 │ <Fragment><Foo /></Fragment> | ||
| · ──────── | ||
| ╰──── | ||
| help: Use <></> instead of <React.Fragment></React.Fragment> | ||
| help: Use `<></>` instead of `<React.Fragment></React.Fragment>`. | ||
|
|
||
| ⚠ eslint-plugin-react(jsx-fragments): Shorthand form for React fragments is preferred | ||
| ⚠ eslint-plugin-react(jsx-fragments): Shorthand form for React fragments is preferred. | ||
| ╭─[jsx_fragments.tsx:1:2] | ||
| 1 │ <React.Fragment><Foo /></React.Fragment> | ||
| · ────────────── | ||
| ╰──── | ||
| help: Use <></> instead of <React.Fragment></React.Fragment> | ||
| help: Use `<></>` instead of `<React.Fragment></React.Fragment>`. | ||
|
|
||
| ⚠ eslint-plugin-react(jsx-fragments): Standard form for React fragments is preferred | ||
| ⚠ eslint-plugin-react(jsx-fragments): Standard form for React fragments is preferred. | ||
| ╭─[jsx_fragments.tsx:1:1] | ||
| 1 │ <><Foo /></> | ||
| · ── | ||
| ╰──── | ||
| help: Use <React.Fragment></React.Fragment> instead of <></> | ||
| help: Use `<React.Fragment></React.Fragment>` instead of `<></>`. | ||
|
|
||
| ⚠ eslint-plugin-react(jsx-fragments): Standard form for React fragments is preferred. | ||
| ╭─[jsx_fragments.tsx:1:1] | ||
| 1 │ <><Foo /></> | ||
| · ── | ||
| ╰──── | ||
| help: Use `<React.Fragment></React.Fragment>` instead of `<></>`. |
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.
you can support both by doing an enum, something like this i think
Uh oh!
There was an error while loading. Please reload this page.
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.
This almost works, but not quite, as it breaks the
self.modethroughout the file. I can do it like this and it compiles, but unwrapping in from_configuration apparently panics in some cases.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.
unwrap_or_defaultin from_configuration fixes the panic! Although I have apparently broken the behavior in the tests somehow. 🤔Uh oh!
There was an error while loading. Please reload this page.
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.
ah hm didn't consider that it makes the code weird, might need a helper function to convert the mode from the enum to the fragment mode
edit: oh i see that's what you did
Uh oh!
There was an error while loading. Please reload this page.
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.
hm
unwrapwould be preferable i think to enforce that the config they pass in is correct. panicking is a bit harsh but that's a separate problemThere 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 pushed up a commit to use this pattern, although I'm not really sure it's particularly better than the previous version. I'll probably let cam decide on whatever is preferred.
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.
imo it's better because it codifies the config in the type rather than some adhoc deserialization code
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.
also you can get config doc generation hopefully that describes these two options if you put this enum in the
configvalueThere 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.
Unfortunately we'll need to make it possible to serialize a value of this type for the website to generate it, right now it can't handle an enum that is more than just simple types.
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.
DefaultRuleConfig definitely makes it better: 65f8344