Skip to content

Change Reques: make custom rule meta.messages a required property #19861

Closed
@ren-yamanashi

Description

@ren-yamanashi

ESLint version

v9.28.0

What problem do you want to solve?

In the custom rule context.report, the messageId property is mandatory, but the meta.message property is not.

Here, specifying the messageId property without specifying meta.message (as in the following example) will result in the following error.

import { Rule } from 'eslint';

export const noClass: Rule.RuleModule = {
  meta: {
    type: 'suggestion',
  },
  create(context) {
    return {
      ClassDeclaration(node) {
        context.report({
          node,
          messageId: 'sampleId',
        });
      },
    };
  },
};

Error: Caught an error while linting
Caused by: TypeError: context.report() called with a messageId, but no messages were present in the rule metadata.

What do you think is the correct solution?

Make the meta.message property a required property

Participation

  • I am willing to submit a pull request for this change.

Additional comments

No response

Metadata

Metadata

Assignees

Labels

coreRelates to ESLint's core APIs and featuresenhancementThis change enhances an existing feature of ESLint

Type

No type

Projects

Status

Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy