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

Throw an error if a rule reports a problem without supplying a message #10011

Closed
not-an-aardvark opened this Issue Feb 23, 2018 · 2 comments

Comments

Projects
1 participant
@not-an-aardvark
Member

not-an-aardvark commented Feb 23, 2018

Problem

As of ESLint v4.18.1, rules can do something like this:

context.report({ node }); // no report message

This results in the message property being undefined on the report object. This has the following effects:

  • The default formatter (stylish) crashes with a TypeError.
  • The json formatter omits the message property.
  • RuleTester works as normal, except that the message assertions are compared against the string "undefined".

This is almost certainly not desirable for rule authors. It's also not a very good development experience because RuleTester might seem to work as expected if a test case only asserts the number of errors, but the actual output will cause the formatter to crash at runtime with a confusing error message.

Proposal

We should make context.report throw an error if no report message is supplied.

@not-an-aardvark

This comment has been minimized.

Member

not-an-aardvark commented Mar 1, 2018

TSC Summary: This issue proposes throwing an error when a rule reports a problem without providing a report message. The current behavior is to give the problem a message of undefined, which crashes several formatters.
TSC Question: Should we accept this proposal?

@not-an-aardvark

This comment has been minimized.

Member

not-an-aardvark commented Mar 1, 2018

In today's TSC meeting, the TSC decided to accept this as a breaking change.

@not-an-aardvark not-an-aardvark moved this from Needs discussion to Accepted, ready to implement in v5.0.0 Mar 1, 2018

not-an-aardvark added a commit that referenced this issue Mar 4, 2018

Breaking: require rules to provide report messages (fixes #10011)
This updates ESLint core to throw an error when a rule reports a problem without providing a report message. It is unlikely that many users were relying on the previous behavior, because a reported problem without a message would crash several formatters, including the default formatter. However, it is possible that someone was relying on this with the `json` formatter.

@not-an-aardvark not-an-aardvark moved this from Accepted, ready to implement to Ready to merge in v5.0.0 Mar 4, 2018

v5.0.0 automation moved this from Ready to merge to Done Mar 22, 2018

@eslint eslint bot locked and limited conversation to collaborators Sep 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.