New rule suggestion: prefer-fragment
See original GitHub issueAny time bare <div>
s with no attributes are used, a fragment <>...</>
should be used instead.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Rule suggestion: consistent usage of <React.Fragment> vs ...
Instead of preferring React.Fragment over <>, I think that it could be valuable to be enforce the usage of either one for consistency....
Read more >Best practice for instantiating a new Android Fragment
Best practice to instance fragments with arguments in android is to have static factory method in your fragment.
Read more >Communicating with fragments - Android Developers
To reuse fragments, build each as a completely self-contained component that defines its own layout and behavior.
Read more >Breaking Grammar Rules: Sentence Fragments - A.J. Hartley
Fragments look like sentences but aren't. They can be short, but don't have to be, while sentences can be short without being fragments....
Read more >fragment rule 'x' contains an action or command which can ...
Hi! I know the topic of actions in fragments have been discussed before, here and in a couple of issues on github.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hmm, I’m a little concerned with this rule, I’m not sure it will be generally applicable. Having a bare div is semantically quite different than a fragment, for example a
<div>
:display: block
whereas a fragment does notI’m also curious which of the following elements the rule would affect in the hypothetical situation below:
I had a related idea: what if there was an option for
jsx-wrap-multiline
that enforced the preference of wrapping with a fragment, rather than parenthesis.I currently have code like this:
I’m getting errors for the
jsx-wrap-multiline
rule, but I think in this case the fragment serves the purpose of the parenthesis. When there’s only one element parent in the multiline jsx, I would still want the error.I know this isn’t exactly the rule being described here, but I think this is useful in determining what exactly the rules are trying to enforce.