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

Update: re-enable experimentalObjectRestSpread (fixes #9990) #10230

Merged
merged 8 commits into from Apr 28, 2018

Conversation

mysticatea
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[X] Other, please explain: fixes #9990

What changes did you make? (Give an overview)

  1. If parserOptions.ecmaFeatures.experimentalObjectRestSpread is given and parserOptions.ecmaVersion is less than 9, linter enables parserOptions.ecmaVersion: 9 for backward compatibility.
  2. If parserOptions.ecmaFeatures.experimentalObjectRestSpread is given, linter generates a deprecation warning to show the deprecation.

Is there anything you'd like reviewers to focus on?

I make the deprecation warning is as a message with severity: 1. Should it be with another way?

And it generates a deprecation warning to show that the option has been
deprecated.
@mysticatea mysticatea added enhancement This change enhances an existing feature of ESLint core Relates to ESLint's core APIs and features accepted There is consensus among the team that this change meets the criteria for inclusion labels Apr 16, 2018
@mysticatea mysticatea added this to Ready to merge in v5.0.0 Apr 16, 2018
@not-an-aardvark
Copy link
Member

Thanks for working on this!

  • It seems like it could be useful to print the filename of the config file that contains experimentalObjectRestSpread. As a result, I had been thinking it would be better to put the check somewhere around here (similar to the top-level ecmaFeatures check), rather than in Linter.
  • With this check, it seems like a warning would be generated for every file, which seems annoying.

@mysticatea
Copy link
Member Author

Thank you for the good suggestion!

I moved the warning to config-validator and make using process.emitWarning().

Code which enables parserOptions.ecmaVersion: 9 is still in Linter since Linter is a public API.

lib/linter.js Outdated
@@ -996,13 +1006,15 @@ module.exports = class Linter {
throw err;
}

return applyDisableDirectives({
lintingProblems = applyDisableDirectives({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Could this just be return applyDisableDirectives({ // ... again since lintingProblems is no longer being modified afterwards?

lib/linter.js Outdated
parserOptions.ecmaFeatures &&
parserOptions.ecmaFeatures.experimentalObjectRestSpread &&
(!parserOptions.ecmaVersion || parserOptions.ecmaVersion < 9)
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Could this logic be moved to the resolveParserOptions function?

let warning = null;

function onWarning(w) { // eslint-disable-line require-jsdoc
warning = w;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do something like this instead?

function onWarning(w) {
    if (w.code === 'ESLint') {
        warning = w;
    }
}

That way, the test won't break if a warning happens for an unrelated reason (e.g. a deprecation in a dependency).


process.emitWarning(
`${message} (found in "${rel}")`,
{ code: "ESLint", type: "DeprecationWarning" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code property of a warning is generally supposed to be unique for a given type of warning, so that tools can filter warnings reliably even if the message changes. Maybe it would be better to do something like { code: 'ESLINT_EXPERIMENTAL_OBJECT_REST_SPREAD' } instead, to make sure it's distinguished from other warnings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Today I leaned the meaning of the code property.

However, I feel reluctant to make code longer since the string will be printed for users. To be clear, Node.js prints this message such as:

(node:10736) [ESLint] DeprecationWarning: The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead. (found in "tests\fixtures\config-file\experimental-object-rest-spread\extends\common.yml")

The first [ESLint] is the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could make it something like ESLINT_EORS?

@mysticatea
Copy link
Member Author

mysticatea commented Apr 18, 2018

@not-an-aardvark Thank you for the review! Eventually, I followed your suggestion about the error code.

EDIT: In the following screenshot, I think that this progress bar can surprise contributors. The --no-deprecation flag can disable stderr outputs, but it seems to disable warning events at same time. 🤔

image

@mysticatea
Copy link
Member Author

https://nodejs.org/api/process.html#process_process_emitwarning_warning_type_code_ctor

This third parameter code doesn't seem to exist in Node.js 6.x 🤔

@aladdin-add
Copy link
Member

seems this should use tag Breaking, instead of Update. Hope the bot can check the labels of corresponding issue.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Oct 26, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Oct 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint
Projects
No open projects
v5.0.0
  
Done
Development

Successfully merging this pull request may close these issues.

Proposal: removing parserOptions.experimentalObjectRestSpread option
4 participants