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

New Rule: require-test-suggestions #189

Closed
bmish opened this issue Sep 25, 2021 · 1 comment
Closed

New Rule: require-test-suggestions #189

bmish opened this issue Sep 25, 2021 · 1 comment

Comments

@bmish
Copy link
Member

bmish commented Sep 25, 2021

It would require invalid test cases to assert what suggestions are provided for each violation (using suggestions: [] if the violation provides no assertions).

Why?

  • Currently, it's easy to forget to assert what suggestions a test case yields, or that a test case yields no assertions. As a result, this can be an area of poor test coverage.
new RuleTester().run('example-rule', rule, {
  valid: [],
  invalid: [
    {
      code: `foo();`,
      output: null,
      errors: [
        {
          messageId: 'bar',
          type: 'Property',
          suggestions: [], // or array of suggestions if rule offers them
        },
      ],
    },
  ]
});

This rule would have a consistent option (enabled by default), which would only require the suggestions assertion if at least one test case in the file has it (similar to eslint-plugin/consistent-output).

I hope that a future major version of ESLint will require test cases that yield suggestions to assert what they are, so that this lint rule wouldn't be as necessary as it is now. Here is the issue I file about this: eslint/eslint#15104

@bmish bmish changed the title New Rule: require-suggestions-assertion New Rule: require-test-suggestions Sep 25, 2021
@bmish
Copy link
Member Author

bmish commented Oct 16, 2021

Closing because I plan to pursue an improvement in ESLint v9 (eslint/eslint#15104) that will result in this rule being no longer needed.

@bmish bmish closed this as completed Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant