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

Fix: Make rule-tester strictly check messageId. (ref #9890) #9908

Merged

Conversation

betaorbust
Copy link
Contributor

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

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

This PR:

  • Makes RuleTester compare messageId in the test to messageId in the runtime error.
  • Fixes an issue with tests/lib/rules/no-fallthrough.js where the wrong message and type data was being passed through.

What changes did you make? (Give an overview)
Currently, when RuleTester is used with a messageId property in the error section, the underlying implementation looks up the raw message string from rule.meta.messages[messageId] and compares it with the runtime error string produced by the rule.
All other properties checked in RuleTester's error section (message, type, line, column, endLine, endColumn) are direct comparisons to the resulting data, which makes the behavior of messageId an unexpected and confusing developer experience.

This PR addresses this by changing messageId checks in RuleTester to be direct comparisons.

Is there anything you'd like reviewers to focus on?
This partially addresses #9890, fixing the DX of messageId without dealing with the more contentious issue of surfacing data in the public API.

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

Just one small message suggestion, otherwise this looks good to me. (N.B. I still need to check to make sure this does what we agreed on in the issue.)

assert.strictEqual(
error.messageId,
message.messageId,
`messageId mismatch saw '${message.messageId}' and expected '${error.messageId}'.`
Copy link
Member

Choose a reason for hiding this comment

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

This message feels like a run-on sentence. I would suggest something like:

messageId '${message.messageId}' does not match expected messageId '${error.messageId}'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Will do.

@aladdin-add aladdin-add added bug ESLint is working incorrectly enhancement This change enhances an existing feature of ESLint core Relates to ESLint's core APIs and features evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed bug ESLint is working incorrectly labels Feb 3, 2018
@betaorbust betaorbust changed the title Fix: Make rule-tester strictly check messageId. (ref #9890) WIP: Make rule-tester strictly check messageId. (ref #9890) Feb 25, 2018
@betaorbust betaorbust force-pushed the make-message-id-direct-compare--jf branch from 9ca36d8 to fa2ca54 Compare February 25, 2018 18:37
@betaorbust betaorbust changed the title WIP: Make rule-tester strictly check messageId. (ref #9890) Fix: Make rule-tester strictly check messageId. (ref #9890) Feb 25, 2018
@betaorbust
Copy link
Contributor Author

@platinumazure The code now aligns with what we discussed in #9890 (comment) and I think it's ready for the fix to go in.

@betaorbust betaorbust force-pushed the make-message-id-direct-compare--jf branch from fa2ca54 to 59437bf Compare February 25, 2018 23:12
@betaorbust
Copy link
Contributor Author

betaorbust commented Feb 26, 2018

Looks like there’s some issues with older versions of node and assert.fail 😓
I’ll get a fix in.

This change makes rule-tester check messageId directly by value provided instead
of the current behavior, which is to check the messageId's message value against
the message returned from the rule at runtime.
@betaorbust
Copy link
Contributor Author

Ok, all fixed up and ready for review.

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

LGTM, but would like to wait for other team members to review. Thanks for contributing!

@platinumazure
Copy link
Member

Closing and reopening to make sure Travis/AppVeyor still pass with this change against latest master. Then I'll merge this in if all goes well.

@platinumazure platinumazure reopened this Mar 22, 2018
@platinumazure platinumazure merged commit 0bc4a38 into eslint:master Mar 22, 2018
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Sep 19, 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 Sep 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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 evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants