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: Allow testing Suggestions with data in RuleTester (fixes #12606) #12635

Merged
merged 2 commits into from Mar 18, 2020

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Dec 3, 2019

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

[X] Add something to the core

fixes #12606

What changes did you make? (Give an overview)

RuleTester now allows testing Suggestions with data.

Example:

{
    code: "var foo;",
    errors: [{
        suggestions: [{
            messageId: "renameFoo",
            data: { newName: "bar" },
            output: "var bar;"
        }, {
            messageId: "renameFoo",
            data: { newName: "baz" },
            output: "var baz;"
        }]
    }]
}

Also, RuleTester documentation was missing messageId and data for errors.

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

To avoid breaking change, as noted in #12606 (comment), it's still allowed to specify both desc and messageId for the same suggestion. This combination is now removed from the example in the docs, but it still works and both values would be tested.

Also, there are still some differences when compared to what can be used in error tests. This would probably require additional discussion and it seems better to make separate PRs (if needed):

  • suggestions cannot be a number, e.g., suggestions: 2 to just test that there are 2 suggestions and nothing more. A workaround is suggestions: [{}, {}].
  • A suggestion as an element of the suggestions array can't be just a string that would be treated as desc.
  • desc can't be a regex.
  • there is no check whether the suggestion's fix produces a valid code or a parsing error.
  • RuleTester doesn't seem to support suggestions that don't have a fix. This raises a question, is a suggestion that doesn't include a fix allowed by the API?

@mdjermanovic mdjermanovic 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 Dec 3, 2019
@ilyavolodin
Copy link
Member

  • suggestions cannot be a number, e.g., suggestions: 2 to just test that there are 2 suggestions and nothing more. A workaround is suggestions: [{}, {}].

Sounds good to me. There was even talk about removing ints from errors at some point.

  • A suggestion as an element of the suggestions array can't be just a string that would be treated as desc.

👍

  • desc can't be a regex.

I guess that's fine. Not sure why we need to check for that.

  • there is no check whether the suggestion's fix produces a valid code or a parsing error.
    RuleTester doesn't seem to support suggestions that don't have a fix. This raises a question, is a suggestion that doesn't include a fix allowed by the API?

Good question. I think we should not allow suggestions without fixes. The whole point of suggestions is to provide multiple ways of working around a problem. Providing them without code changes doesn't make sense to me.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@kaicataldo kaicataldo merged commit e90b29b into master Mar 18, 2020
@kaicataldo kaicataldo deleted the issue12606 branch March 18, 2020 01:38
anikethsaha pushed a commit to anikethsaha/eslint that referenced this pull request Mar 23, 2020
…nt#12606) (eslint#12635)

* Update: Allow testing Suggestions with data in RuleTester (fixes eslint#12606)

* Add data to suggestionObjectParameters
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Sep 16, 2020
@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 Sep 16, 2020
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

Successfully merging this pull request may close these issues.

Suggestion data
4 participants