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

Breaking: make no-redeclare stricter (fixes #11370, fixes #11405) #11509

Merged
merged 17 commits into from Apr 25, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

update documents

  • Loading branch information...
mysticatea committed Mar 15, 2019
commit 2fc6a2d1ecccaf1b03c4b29f9d83471ef424af1a
@@ -169,6 +169,13 @@ This method returns the scope which has the following types:
**※2** Only if the `for` statement defines the iteration variable as a block-scoped variable (E.g., `for (let i = 0;;) {}`).<br>
**※3** The scope of the closest ancestor node which has own scope. If the closest ancestor node has multiple scopes then it chooses the innermost scope (E.g., the `Program` node has a `global` scope and a `module` scope if `Program#sourceType` is `"module"`. The innermost scope is the `module` scope.).

The returned value is a `Scope` object that [`eslint-scope` package defined](scope-manager-interface.md). The `Variable` objects of global variables have some additional properties.
This conversation was marked as resolved by mysticatea

This comment has been minimized.

Copy link
@platinumazure

platinumazure Mar 28, 2019

Member

Possible wording improvement:

Suggested change
The returned value is a `Scope` object that [`eslint-scope` package defined](scope-manager-interface.md). The `Variable` objects of global variables have some additional properties.
The returned value is a [`Scope` object](scope-manager-interface.md) defined by the `eslint-scope` package. The `Variable` objects of global variables have some additional properties.

- `variable.writeable` (`boolean`) ... If `true`, this global variable can be assigned arbitrary value. Otherwise, this global variable is read-only.
- `variable.eslintExplicitGlobal` (`boolean`) ... If `true`, this global variable was defined by a `/* globals */` directive comment in the source code file.
- `variable.eslintExplicitGlobalComments` (`Comment[]`) ... The array of `/* globals */` directive comments which defined this global variable in the source code file.
- `variable.eslintImplicitGlobalSetting` (`"readonly" | "writable" | undefined`) ... The configured value in config files. This can be different from `variable.writeable` if there are `/* globals */` directive comments.

### context.report()

The main method you'll use is `context.report()`, which publishes a warning or error (depending on the configuration being used). This method accepts a single argument, which is an object containing the following properties:
@@ -27,7 +27,7 @@ a = 10;

## Options

This rule takes one optional argument, an object with a boolean property `"builtinGlobals"`. It defaults to `false`.
This rule takes one optional argument, an object with a boolean property `"builtinGlobals"`. It defaults to `true`.
If set to `true`, this rule also checks redeclaration of built-in globals, such as `Object`, `Array`, `Number`...

### builtinGlobals
@@ -0,0 +1,52 @@
# Migrating to v6.0.0

ESLint v6.0.0 is the fifth major version release. We have made a few breaking changes in this release, but we expect that most users will be able to upgrade without any modifications to their build. This guide is intended to walk you through the breaking changes.

The lists below are ordered roughly by the number of users each change is expected to affect, where the first items are expected to affect the most users.

### Breaking changes for users

- [`no-redeclare` rule now checks the redeclarations by `/* globals */` directive comments](#no-redeclare-and-comments)
- [`no-redeclare` rule now checks the redeclarations with built-in globals by default](#no-redeclare-and-builtins)
This conversation was marked as resolved by mysticatea

This comment has been minimized.

Copy link
@not-an-aardvark

not-an-aardvark Mar 15, 2019

Member

To avoid merge conflicts, I was thinking it might be better to create the migration guide separately rather than adding an entry in each breaking commit.

This comment has been minimized.

Copy link
@mysticatea

mysticatea Mar 15, 2019

Author Member

I got it. I will remove the migration guide.


### Breaking changes for plugin/custom rule developers

- [`variable.eslintExplicitGlobalComment` property was removed](#remove-variable-explicit-global-comment)

### Breaking changes for integration developers

---

<!-- Breaking changes for users -->

## <a id="no-redeclare-and-comments"></a> `no-redeclare` rule now checks the redeclarations by `/* globals */` directive comments

[no-redeclare] rule reports the following cases newly:

- Your config file defined a global variable but there is `/* globals */` directive comment of the defined global variable in your source code.
- There are multiple `/* globals */` directive comments for the same variable.

**To address:** Please remove the redundant `/* globals */` directive comments.

## <a id="no-redeclare-and-builtins"></a> `no-redeclare` rule now checks the redeclarations with built-in globals by default

The `builtinGlobals` option of [no-redeclare] rule is `true` by default. Previously, it was `false` by default.

**To address:** Please remove the redundant declarations or disable `builtinGlobals` option manually.

---

<!-- Breaking changes for plugin/custom rule developers -->

## <a id="remove-variable-explicit-global-comment"></a> `variable.eslintExplicitGlobalComment` property was removed

Undocumented `variable.eslintExplicitGlobalComment` property, only [no-unused-vars] rule had used it, was removed.

**To address:** Please use [`variable.eslintExplicitGlobalComments` property](../working-with-rules.md#contextgetscope) instead.

---

<!-- Breaking changes for integration developers -->

[no-redeclare]: https://eslint.org/docs/rules/no-redeclare
[no-unused-vars]: https://eslint.org/docs/rules/no-unused-vars
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.