Lint Rules

noRedundantUseStrict (since v11.0.0)

Prevents from having redundant "use strict".

Examples

Invalid

"use strict";
function foo() {
 	"use strict";
}
nursery/noRedundantUseStrict.js:3:3 lint/nursery/noRedundantUseStrict  FIXABLE  ━━━━━━━━━━━━━━━━━━━━

   Redundant use strict directive.
  
    1 │ "use strict";
    2 │ function foo() {
  > 3 │  	"use strict";
    	^^^^^^^^^^^^^
    4 │ }
    5 │ 
  
   This outer use strict directive already enables strict mode.
  
  > 1 │ "use strict";
   ^^^^^^^^^^^^^
    2 │ function foo() {
    3 │  	"use strict";
  
   Safe fix: Remove the redundant "use strict" directive
  
    1 1  "use strict";
    2 2  function foo() {
    3  - ·"use·strict";
    4 3  }
    5 4  
  
"use strict";
"use strict";

function foo() {

}
nursery/noRedundantUseStrict.js:2:1 lint/nursery/noRedundantUseStrict  FIXABLE  ━━━━━━━━━━━━━━━━━━━━

   Redundant use strict directive.
  
    1 │ "use strict";
  > 2 │ "use strict";
   ^^^^^^^^^^^^^
    3 │ 
    4 │ function foo() {
  
   This outer use strict directive already enables strict mode.
  
  > 1 │ "use strict";
   ^^^^^^^^^^^^^
    2 │ "use strict";
    3 │ 
  
   Safe fix: Remove the redundant "use strict" directive
  
    1 1  "use strict";
    2  - "use·strict";
    3 2  
    4 3  function foo() {
  
function foo() {
"use strict";
"use strict";
}
nursery/noRedundantUseStrict.js:3:1 lint/nursery/noRedundantUseStrict  FIXABLE  ━━━━━━━━━━━━━━━━━━━━

   Redundant use strict directive.
  
    1 │ function foo() {
    2 │ "use strict";
  > 3 │ "use strict";
   ^^^^^^^^^^^^^
    4 │ }
    5 │ 
  
   This outer use strict directive already enables strict mode.
  
    1 │ function foo() {
  > 2 │ "use strict";
   ^^^^^^^^^^^^^
    3 │ "use strict";
    4 │ }
  
   Safe fix: Remove the redundant "use strict" directive
  
    1 1  function foo() {
    2 2  "use strict";
    3  - "use·strict";
    4 3  }
    5 4  
  
class C1 {
	test() {
		"use strict";
	}
}
nursery/noRedundantUseStrict.js:3:3 lint/nursery/noRedundantUseStrict  FIXABLE  ━━━━━━━━━━━━━━━━━━━━

   Redundant use strict directive.
  
    1 │ class C1 {
    2 │ 	test() {
  > 3 │ 		"use strict";
   		^^^^^^^^^^^^^
    4 │ 	}
    5 │ }
  
   All parts of a class's body are already in strict mode.
  
  > 1 │ class C1 {
   ^^^^^^^^^^
  > 2 │ 	test() {
  > 3 │ 		"use strict";
  > 4 │ 	}
  > 5 │ }
   ^
    6 │ 
  
   Safe fix: Remove the redundant "use strict" directive
  
    1 1  class C1 {
    2 2  	test() {
    3  - "use·strict";
    4  - }
      3+ }
    5 4  }
    6 5  
  
const C2 = class {
	test() {
		"use strict";
	}
};
nursery/noRedundantUseStrict.js:3:3 lint/nursery/noRedundantUseStrict  FIXABLE  ━━━━━━━━━━━━━━━━━━━━

   Redundant use strict directive.
  
    1 │ const C2 = class {
    2 │ 	test() {
  > 3 │ 		"use strict";
   		^^^^^^^^^^^^^
    4 │ 	}
    5 │ };
  
   All parts of a class's body are already in strict mode.
  
  > 1 │ const C2 = class {
              ^^^^^^^
  > 2 │ 	test() {
  > 3 │ 		"use strict";
  > 4 │ 	}
  > 5 │ };
   ^
    6 │ 
  
   Safe fix: Remove the redundant "use strict" directive
  
    1 1  const C2 = class {
    2 2  	test() {
    3  - "use·strict";
    4  - }
      3+ }
    5 4  };
    6 5  
  

Valid

function foo() {

}
 function foo() {
    "use strict";
}
function bar() {
    "use strict";
}