Lint Rules

noExtraSemicolons (since v12.0.0)

Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. While not technically an error, extra semicolons can cause confusion when reading code.

This rule disallows unnecessary semicolons.

Examples

Invalid

  const x = 5;;
nursery/noExtraSemicolons.js:1:15 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

   Unnecessary semicolon.
  
  > 1 │   const x = 5;;
                 ^
    2 │ 
  
   Suggested fix: Remove unnecessary semicolon.
  
    1 │ ··const·x·=·5;;
                -
 function buzz() {
     const x = 10;;
 }
nursery/noExtraSemicolons.js:2:19 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

   Unnecessary semicolon.
  
    1 │  function buzz() {
  > 2 │      const x = 10;;
                     ^
    3 │  }
    4 │ 
  
   Suggested fix: Remove unnecessary semicolon.
  
    2 │ ·····const·x·=·10;;
                    -
  function foo() {
    // code
  };
nursery/noExtraSemicolons.js:3:4 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━

   Unnecessary semicolon.
  
    1 │   function foo() {
    2 │     // code
  > 3 │   };
      ^
    4 │ 
  
   Suggested fix: Remove unnecessary semicolon.
  
    3 │ ··};
     -
    class C {
      field;;

      method() {
          // code
      }

      static {
          // code
      }
    }
nursery/noExtraSemicolons.js:2:13 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

   Unnecessary semicolon.
  
    1 │     class C {
  > 2 │       field;;
               ^
    3 │ 
    4 │       method() {
  
   Suggested fix: Remove unnecessary semicolon.
  
    2 │ ······field;;
              -
   class C {
     field;

     method() {
         // code
     };

     static {
         // code
     }
   }
nursery/noExtraSemicolons.js:6:7 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━

   Unnecessary semicolon.
  
    4 │      method() {
    5 │          // code
  > 6 │      };
         ^
    7 │ 
    8 │      static {
  
   Suggested fix: Remove unnecessary semicolon.
  
    6 │ ·····};
        -
   class C {
     field;

     method() {
         // code
     }

     static {
         // code
     };
   }
nursery/noExtraSemicolons.js:10:7 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

   Unnecessary semicolon.
  
     8 │      static {
     9 │          // code
  > 10 │      };
          ^
    11 │    }
    12 │ 
  
   Suggested fix: Remove unnecessary semicolon.
  
    10 │ ·····};
        -
   class C {
     field;

     method() {
         // code
     }

     static {
         // code
     }
   };
nursery/noExtraSemicolons.js:11:5 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

   Unnecessary semicolon.
  
     9 │          // code
    10 │      }
  > 11 │    };
        ^
    12 │ 
  
   Suggested fix: Remove unnecessary semicolon.
  
    11 │ ···};
      -