Strict mode should be declared properly

  • BAD_USE_STRICT
  • Error
  • Medium
  • No tags

This rule applies when strict mode is not properly declared.

If not properly declared, strict mode is not applied, so debugging and runtime behaviors might be unexpected.

It can be applied to the following:

  1. 'use strict' directive is not at the beginning of function body or global code.
  2. Typing mistakes like 'use_strict'

Noncompliant Code Example

View with compliant examples side by side
function example1() {
    var x;

    'use strict'; // BAD_USE_STRICT alarm

    x = doSomething();
    return x;
}

function example2() {
    'use_strict'; // BAD_USE_STRICT alarm
}

Compliant Code Example

View with noncompliant examples side by side
function example1() {
    'use strict';

    var x;

    x = doSomething();
    return x;
}

function example2() {
    'use strict';
}

Version

This rule was introduced in DeepScan 1.0.0-alpha.

See

Was this documentation helpful?