Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'strict' rule is only partially overridden by `sourceType: module` #4936

Closed
nre opened this Issue Jan 13, 2016 · 4 comments

Comments

Projects
None yet
5 participants
@nre
Copy link
Contributor

commented Jan 13, 2016

v2.0.0-beta.1

The documentation does not cover the behaviour of the 'strict' rule when strict mode is imposed by a parser option: sourceType: module (and, hopefully one day, ecmaFeatures: impliedStrict #4832).

The behaviour is also inconsistent. The 'strict' option 'none' incorrectly implies that strict mode can be somehow disabled inside ES6 modules ('Strict mode is not permitted'):

{
    "parserOptions": {
        "sourceType": "module"
    }
}
/* eslint strict: [2, "never"] */
"use strict";
  2:1  error  Strict mode is not permitted  strict

✖ 1 problem (1 error, 0 warnings)

Whereas the 'strict' options 'global|function|safe' are overridden by the module configuration ("'use strict' is unnecessary inside of modules"):

{
    "parserOptions": {
        "sourceType": "module"
    }
}
/* eslint strict: [2, "global"] */
"use strict";
  2:1  error  'use strict' is unnecessary inside of modules  strict

✖ 1 problem (1 error, 0 warnings)

I would like to make a PR that:

  • Has ES6 modules override all 'strict' rule options. (This is not a breaking change. Only the message will change.)
  • Documents the behaviour of the 'strict' rule and ES6 modules.
  • Clarifies the docs to say that the 'strict' rule polices strict-mode directives and not strict mode itself. (The 'strict' rule only looks for directives—it does not use the data in escope. It is a third independent implementation of the strict-directive algorithm, in addition to the parser and escope.)

@gyandeeps gyandeeps added the triage label Jan 13, 2016

@ilyavolodin ilyavolodin added bug rule evaluating and removed triage labels Jan 13, 2016

@nzakas

This comment has been minimized.

Copy link
Member

commented Jan 13, 2016

What message would change? What would it change to?

@nzakas nzakas added enhancement and removed bug labels Jan 13, 2016

@nre

This comment has been minimized.

Copy link
Contributor Author

commented Jan 13, 2016

The message that I propose to change is the message that is shown for each strict-mode directive when sourceType: module and the 'strict' rule is set to 'never'.

The message would change from "Strict mode is not permitted" to "'use strict' is unnecessary inside of modules".

This change would make the behaviour of the 'strict' rule the same for all its options ('never|global|function|safe') when sourceType: module.

@michaelficarra

This comment has been minimized.

Copy link
Member

commented Jan 13, 2016

👍

nre added a commit to nre/eslint that referenced this issue Jan 13, 2016

@nzakas nzakas added accepted and removed evaluating labels Jan 13, 2016

@nzakas

This comment has been minimized.

Copy link
Member

commented Jan 13, 2016

Sounds good, let's do it.

nre added a commit to nre/eslint that referenced this issue Jan 14, 2016

nre added a commit to nre/eslint that referenced this issue Jan 15, 2016

@nzakas nzakas closed this in 05b8cb3 Jan 19, 2016

nzakas added a commit that referenced this issue Jan 19, 2016

Merge pull request #4948 from nre/issue4936
Update: Module overrides all 'strict' rule options (fixes #4936)

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.