Skip to content

Rule Change: support i18n attributes for rule's meta.message template #19210

Open
@gweesin

Description

What rule do you want to change?

every rule's meta.message attribute

What change do you want to make?

Implement suggestions

How do you think the change should be implemented?

A new default behavior

Example code

// eslint.config.js
module.exports = [
  /* ... */
]

// convert to new structure
module.exports = {
  language: 'en-US', // en-US as default, and also if not exist rule's language configuration as provided 
  rules: [ /* ... */ ] // the original rules array
}

What does the rule currently do for this code?

module.exports = {
    meta: {
        type: "suggestion",

        docs: {
            description: "Require braces around arrow function bodies",
            recommended: false,
            url: "https://eslint.org/docs/latest/rules/arrow-body-style"
        },

        messages: {
            unexpectedOtherBlock: "Unexpected block statement surrounding arrow body",
            unexpectedEmptyBlock: "Unexpected block statement surrounding arrow body; put a value of `undefined` immediately after the `=>`.",
            unexpectedObjectBlock: "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`.",
            unexpectedSingleBlock: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`.",
            expectedBlock: "Expected block statement surrounding arrow body."
        }
    }
}

What will the rule do after it's changed?

module.exports = {
    meta: {
        type: "suggestion",

        docs: {
            description: "Require braces around arrow function bodies",
            recommended: false,
            url: "https://eslint.org/docs/latest/rules/arrow-body-style"
        },

        messages: {
            // support reading i18n object
            unexpectedOtherBlock: {
               "en-US": "Unexpected block statement surrounding arrow body",
               "zh-CN": "不期望箭头函数包裹块语句"
            },
            unexpectedEmptyBlock: "Unexpected block statement surrounding arrow body; put a value of `undefined` immediately after the `=>`.",
            unexpectedObjectBlock: "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`.",
            unexpectedSingleBlock: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`.",
            expectedBlock: "Expected block statement surrounding arrow body."
        }
    }
}

Participation

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

Additional comments

No response

Activity

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

Metadata

Assignees

No one assigned

    Labels

    enhancementThis change enhances an existing feature of ESLintevaluatingThe team will evaluate this issue to decide whether it meets the criteria for inclusionruleRelates to ESLint's core rules

    Type

    No type

    Projects

    • Status

      RFC Opened

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions