Skip to content

noUselessFragments (since v1.0.0)

Diagnostic Category: lint/complexity/noUselessFragments

Sources:

Disallow unnecessary fragments

<>
foo
</>
complexity/noUselessFragments.js:1:1 lint/complexity/noUselessFragments  FIXABLE  ━━━━━━━━━━━━━━━━━━

   Avoid using unnecessary Fragment.
  
  > 1 │ <>
   ^^
  > 2 │ foo
  > 3 │ </>
   ^^^
    4 │ 
  
   A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
  
   Unsafe fix: Remove the Fragment
  
    1  - <>
    2  - foo
    3  - </>
      1+ "foo"
    4 2  
  
<React.Fragment>
foo
</React.Fragment>
complexity/noUselessFragments.js:1:1 lint/complexity/noUselessFragments  FIXABLE  ━━━━━━━━━━━━━━━━━━

   Avoid using unnecessary Fragment.
  
  > 1 │ <React.Fragment>
   ^^^^^^^^^^^^^^^^
  > 2 │ foo
  > 3 │ </React.Fragment>
   ^^^^^^^^^^^^^^^^^
    4 │ 
  
   A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
  
   Unsafe fix: Remove the Fragment
  
    1  - <React.Fragment>
    2  - foo
    3  - </React.Fragment>
      1+ "foo"
    4 2  
  
<>
<>foo</>
<SomeComponent />
</>
complexity/noUselessFragments.js:2:5 lint/complexity/noUselessFragments  FIXABLE  ━━━━━━━━━━━━━━━━━━

   Avoid using unnecessary Fragment.
  
    1 │ <>
  > 2 │     <>foo</>
       ^^^^^^^^
    3 │     <SomeComponent />
    4 │ </>
  
   A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
  
   Unsafe fix: Remove the Fragment
  
    2 │ ····<>foo</>
      --   ---
<></>
complexity/noUselessFragments.js:1:1 lint/complexity/noUselessFragments ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Avoid using unnecessary Fragment.
  
  > 1 │ <></>
   ^^^^^
    2 │ 
  
   A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
  
<>
<Foo />
<Bar />
</>
<>foo {bar}</>