Closed MikeMcC399 closed 6 months ago
Thanks for the suggestion. Would you like to submit a PR to add this?
@nzakas
Would you like to submit a PR to add this?
I'm very new to ESLint and at this time I don't feel that I have the skills and experience to implement the suggestion. Sorry!
I just noticed the issue as I was working on resolving a lot of eslint-plugin-cypress upgrade issues which I started on one month ago.
So you want to add messages: {}
with an empty object I assume? I'm open to this if there's interest, since most new rules should be using this property for at least one violation message.
The template is here: https://github.com/eslint/generator-eslint/blob/92a44afb6bb04bd7b247111aa9d0f2c2b07558b2/rule/templates/_rule.js#L13-L22
@bmish
So you want to add
messages: {}
with an empty object I assume?
That would be a minimum and just adding that to the template would be easy to implement.
What I wasn't sure about is how far this should be extended, and if it should be expanded to a dialog which asks for a messageID
and a message or assumes some default messageID
and adds a dummy message. That's where my lack of experience in this area breaks down!
I don't think the generator needs to fill in any actual messages. The rule creator probably doesn't have specific messages ready yet when they're just trying to create the barebones rule skeleton.
@bmish
So I suggest to add:
messages: {} // Add messageId and message
to the template. The linting message will stay the same, however adding the above line into the template means that rule creators should be able to find the place faster, where they need to add a message. No additional information is requested at rule creation time with yo eslint:rule
.
Linting error:
error
meta.messages
must contain at least one violation message eslint-plugin/prefer-message-ids
If that sounds good, then I will submit a PR for this change.
That sounds reasonable.
@bmish
Should this be a chore
(no release), fix
(patch release) or feat
(minor release)?
It doesn't change any error message, so from that point of view it could be a chore
. On the other hand it won't get used unless there is a release.
feat
should be fine. It's not fixing anything, but it is a possible usability improvement.
Suggestion
Support the recommended rule eslint-plugin/prefer-message-ids by providing a
meta.messages
property using a MessageId. Currently, runningyo eslint:rule
does not add this property to the generatedlib/rules/<rule-id>.js
rule.Background
Documentation