Skip to content

Rule: valid usage of messageId #57

Closed
@macklinu

Description

@macklinu

ESLint v4.15.0 introduced messageId. Looking at this code sample:

module.exports = {
  meta: {
    messages: {
      avoidName: "Avoid using variables named '{{ name }}'",
    },
  },
  create(context) {
    return {
      Identifier(node) {
        if (node.name === 'foo') {
          context.report({
            node,
            messageId: 'avoidName',
            data: {
              name: 'foo',
            },
          })
        }
      },
    }
  },
}

I would want a rule that:

  • ensures that the messageId used in context.report() matches a key in meta.messages (in this example, avoidName)
  • if meta.messages[messageId] contains a placeholder, it matches data[placeholderName] (in this example, {{ name }} matches data.name)

I'm wondering if the second bullet point should be added to eslint-plugin/no-unused-placeholders or as part of a new rule. I think the first case makes sense as its own rule.

What are your thoughts on this? I'd be happy to work on a pull request this week - looking for feedback on if this would be valuable and how to best include these features into this plugin. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions