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

Print deprecation warning instead of crash on unknown rule #1549

Closed
andrewdeandrade opened this issue Dec 5, 2014 · 20 comments
Closed

Print deprecation warning instead of crash on unknown rule #1549

andrewdeandrade opened this issue Dec 5, 2014 · 20 comments
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
Milestone

Comments

@andrewdeandrade
Copy link
Contributor

Recently the "space-unary-word-ops" rule was changed to "space-unary-ops". When the name of a rule is changed, eslint encounters an unknown key and crashes hard. Instead of crashing, printing an error like: "unknown rule: {{ error.ruleId }}. Please check to see if this rule exists or has been deprecated" to stderr would be more instructive.

Along with this message could be a link to a document that is nothing more than a rule changelog, that states what rules were added, removed or modified in each release, so that users can just check that document to see what's new, what they should remove from their config file and what additional options might now be available for rules they are currently using.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@nzakas nzakas added accepted There is consensus among the team that this change meets the criteria for inclusion enhancement This change enhances an existing feature of ESLint core Relates to ESLint's core APIs and features labels Dec 5, 2014
@nzakas
Copy link
Member

nzakas commented Dec 5, 2014

100% agree. We need to come up with a strategy for deprecating rules as well as for dealing with unknown rules. At one point we assumed that rules would never change, but clearly we've disproved that theory.

@gcochard
Copy link
Contributor

gcochard commented Dec 5, 2014

I would suggest aliasing the old rule name to the new rule, and if it's invoked with the old name try to mimic the behavior of the old rule. Somewhat similar in nature to how vim mimics vi if it is launched as vi, and it opens the file read only if launched as view. Print the deprecation warning and a suggestion to migrate to the new rule name, with the new rule's (hopefully expanded) options.

On the next major release (or the release called out in the deprecation warning) remove all the deprecated rules.

@nzakas
Copy link
Member

nzakas commented Dec 6, 2014

Aliasing doesn't really work because old rules and new rules don't necessarily have a one-to-one mapping. Sometimes rules are merged, sometimes split apart.

I'm thinking the best strategy is:

  1. If the old rule is on my default, turn it off. Also, turn on new rule by default with a setting that mimics the old rule.
  2. Add a deprecation notice to the old rule. Not sure if this should be via context.report() or console.error().
  3. Wait one minor release before removing the old rule.

@gcochard
Copy link
Contributor

gcochard commented Dec 6, 2014

I'd be averse to removing rules (making a breaking change) in a minor release. Consider the way npm install --save handles the versions now. If I install a package at v1.2.3 it will save at ^1.2.3 in my package.json.

If a rule is deprecated at 1.2.4 and then removed at 1.3.0 then a subsequent npm install will install 1.3.0 and I am broken. If you're using semver like all npm packages do, you should stick to that contract and only remove rules at a major release.

@nzakas
Copy link
Member

nzakas commented Dec 6, 2014

Chances are that we simply won't remove rules once we hit 1.0.0. Prior to that, I think two minor releases are more than enough time to fix such an issue in your project. Especially if we change the behavior of unknown rules so that it warns instead of crashes.

@gcochard
Copy link
Contributor

gcochard commented Dec 8, 2014

With pre-1.x, I'd be completely OK with this behavior. npm fixes the minor release number when you install at 0.x. It will not install 0.11.x when the package.json specifies ^0.10.0.

@bedney
Copy link

bedney commented May 2, 2015

Ran into this as well. Whichever way we jump on deprecating rules, can we fix the bug where eslint crashes, rather than produce a warning, on unknown rules? The problem is that different members of the development team may have an different versions of eslint that don't know about newer rules and so they experience crashes when they pull a new .eslint file referencing newer rules.

@andrewdeandrade
Copy link
Contributor Author

I recently created a new rule and one of the really nice features of the test suite is the thoroughness that it guarantees

Sent from my iPhone

On May 2, 2015, at 1:21 PM, William J. Edney notifications@github.com wrote:

Ran into this as well. Whichever way we jump on deprecating rules, can we fix the bug where eslint crashes, rather than produce a warning, on unknown rules? The problem is that different members of the development team may have an different versions of eslint that don't know about newer rules and so they experience crashes when they pull a new .eslint file referencing newer rules.


Reply to this email directly or view it on GitHub.

@gyandeeps
Copy link
Member

I was planning to work on it but before I actually started I wanted to know if it would be good to have this functionality inside config-validator. Since its already validating the rule.

@nzakas
Copy link
Member

nzakas commented Jun 20, 2015

Config validator throws an error when it finds a problem, which would be the same as current behavior.

I think what we are talking about here is using a stub rule that just outputs "This rule had been removed in favor of x" as a normal rule error.

@gyandeeps
Copy link
Member

Yes, what I meant was that it will not throw an error rather display the deprecation message.
My ask is that if we should add that logic inside config-validator functions?
Since its the gatekeeper for all the rules.

@nzakas
Copy link
Member

nzakas commented Jun 20, 2015

Sorry, I wasn't clear. No, this should not be in config-validator, as validation always throws an error. @btmills do you agree?

@welwood08
Copy link

How would using stub rules solve the problem of older code encountering a newer unknown rule?

@nzakas
Copy link
Member

nzakas commented Jun 20, 2015

@welwood08 any unknown rule would be assigned to the stub. The message can always be different depending on if the rule was deprecated, removed, or unknown.

@btmills
Copy link
Member

btmills commented Jun 20, 2015

No, this should not be in config-validator, as validation always throws an error.

@nzakas Yep, totally. Validation errors cause ESLint to bail before linting because any results would be bogus anyway if rules are configured anyway. I very much like the idea of a stub rule for this.

@IanVS
Copy link
Member

IanVS commented Jul 2, 2015

Based on #1898 (comment), should this issue have a v1.0.0 milestone assignment?

@ilyavolodin ilyavolodin added this to the v1.0.0 milestone Jul 2, 2015
@ilyavolodin
Copy link
Member

Yes, thanks for noticing

@IanVS
Copy link
Member

IanVS commented Jul 2, 2015

I'd be happy to take a crack at it. However, I'm not so familiar with the concept of a stub rule. Could someone give a basic overview of what needs to be done, so I know I'm going down the right path?

@nzakas
Copy link
Member

nzakas commented Jul 3, 2015

Basically, you'd create something like this:

function createStubRule(warning) {
    return {
        Program: function(node) {
            context.report(node, warning);
        }
    };
}

// called as
var rule = createStubRule("Unknown rule");

And whenever a rule isn't found or is deprecated (probably need to add deprecated.json into /config that maps while rules are deprecated), create a stub rule in its place.

@IanVS
Copy link
Member

IanVS commented Jul 4, 2015

@nzakas, thanks for the hints. If you have a chance, please review what I have so far, and then I will tackle deprecations (which will use much of the same infrastructure).

@nzakas nzakas closed this as completed in 08c928d Jul 10, 2015
nzakas added a commit that referenced this issue Jul 10, 2015
Add: Warn on missing rule definition or deprecation (fixes #1549)
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 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 Feb 7, 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
None yet
Development

No branches or pull requests

9 participants