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: add helpful message when test case has non-string code/name #15425

Merged
merged 1 commit into from Dec 14, 2021

Conversation

bmish
Copy link
Sponsor Member

@bmish bmish commented Dec 14, 2021

Prerequisites checklist

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

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

What changes did you make? (Give an overview)

Instead of crashing with an unhelpful message when encountering a test case that is missing code, or has a non-string value for code / name:

text.replace is not a function 
  at ​​​sanitize​​​ ​./node_modules/eslint/lib/rule-tester/rule-tester.js:207

We are adding asserts with helpful output:

AssertionError [ERR_ASSERTION]: Test case must specify a string value for 'code'
AssertionError [ERR_ASSERTION]: Optional test case property 'name' must be a string

As discussed in the issue, this is not a breaking change since any affected test cases are already failing.

Fixes #13917.

Note that separately, I have an RFC open for some additional test validations that are breaking changes: eslint/rfcs#84

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

@eslint-github-bot eslint-github-bot bot added the triage An ESLint team member will look at this issue soon label Dec 14, 2021
@eslint-github-bot
Copy link

Hi @bmish!, thanks for the Pull Request

The first commit message isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.

  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by running git commit --amend, editing your commit message, and then running git push -f to update this pull request.

Read more about contributing to ESLint here

@bmish bmish force-pushed the code-name-string-test-assert branch from b5c4281 to f458c3c Compare December 14, 2021 05:14
@eslint-github-bot eslint-github-bot bot added the bug ESLint is working incorrectly label Dec 14, 2021
@bmish bmish changed the title fix: add helpful message when test case code is missing or code/name is not a string fix: add helpful message when test case has non-string code/name Dec 14, 2021
@bmish bmish changed the title fix: add helpful message when test case has non-string code/name fix: add helpful message when test case has non-string code/name Dec 14, 2021
Copy link
Member

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

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

LGTM.

@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion core Relates to ESLint's core APIs and features and removed triage An ESLint team member will look at this issue soon labels Dec 14, 2021
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mdjermanovic mdjermanovic merged commit f4559a0 into eslint:main Dec 14, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jun 13, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jun 13, 2022
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 bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RuleTester] Test case validation
3 participants