diff --git a/CHANGELOG.md b/CHANGELOG.md index aaaaeb78d..ec6dc2c13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ # Changelog All notable changes to this project will be documented in this file. Dates are displayed in UTC. +# [7.3.0](https://github.com/eslint-functional/eslint-plugin-functional/compare/v7.2.2...v7.3.0) (2025-01-14) + + +### Bug Fixes + +* **prefer-tacit:** improve suggestion message ([59194b2](https://github.com/eslint-functional/eslint-plugin-functional/commit/59194b25291f8a9db54370540cc0a07f05633c75)) + + +### Features + +* **type-declaration-immutability:** allow defining custom suggestion messages ([037a3c7](https://github.com/eslint-functional/eslint-plugin-functional/commit/037a3c704628d4a16cb00b9b890a0055557906b4)) + ## [7.2.2](https://github.com/eslint-functional/eslint-plugin-functional/compare/v7.2.1...v7.2.2) (2025-01-14) ## [7.2.1](https://github.com/eslint-functional/eslint-plugin-functional/compare/v7.2.0...v7.2.1) (2025-01-06) diff --git a/src/rules/prefer-tacit.ts b/src/rules/prefer-tacit.ts index b154d63bb..801192166 100644 --- a/src/rules/prefer-tacit.ts +++ b/src/rules/prefer-tacit.ts @@ -76,6 +76,7 @@ const defaultOptions: RawOptions = [ */ const errorMessages = { generic: "Potentially unnecessary function wrapper.", + genericSuggestion: "Remove unnecessary function wrapper.", } as const; /** @@ -154,7 +155,7 @@ function buildSuggestions( ): ReportSuggestionArray { return [ { - messageId: "generic", + messageId: "genericSuggestion", fix: (fixer) => { const functionCallToReference = fixFunctionCallToReference(context, fixer, node, caller); if (functionCallToReference === null) { diff --git a/src/rules/type-declaration-immutability.ts b/src/rules/type-declaration-immutability.ts index e4890c7b8..18b6f9dd3 100644 --- a/src/rules/type-declaration-immutability.ts +++ b/src/rules/type-declaration-immutability.ts @@ -44,11 +44,13 @@ export enum RuleEnforcementComparator { type FixerConfigRaw = { pattern: string; replace: string; + message?: string; }; type FixerConfig = { pattern: RegExp; replace: string; + message?: string; }; type SuggestionsConfig = FixerConfig[]; @@ -188,6 +190,7 @@ const errorMessages = { Exactly: 'This type is declare to have an immutability of exactly "{{ expected }}" (actual: "{{ actual }}").', AtMost: 'This type is declare to have an immutability of at most "{{ expected }}" (actual: "{{ actual }}").', More: 'This type is declare to have an immutability more than "{{ expected }}" (actual: "{{ actual }}").', + userDefined: "{{ message }}", } as const; /** @@ -313,7 +316,6 @@ function getConfiguredSuggestions( node: T, context: Readonly>, configs: ReadonlyArray, - messageId: keyof typeof errorMessages, ): NonNullable | null { const text = context.sourceCode.getText(node); const matchingConfig = configs.filter((c) => c.pattern.test(text)); @@ -322,7 +324,10 @@ function getConfiguredSuggestions( } return matchingConfig.map((config) => ({ fix: (fixer) => fixer.replaceText(node, text.replace(config.pattern, config.replace)), - messageId, + messageId: "userDefined", + data: { + message: config.message ?? `Replace with: ${text.replace(config.pattern, config.replace)}`, + }, })); } @@ -376,7 +381,7 @@ function getResults( const suggest = rule.suggestions === false || isTSInterfaceDeclaration(node) ? null - : getConfiguredSuggestions(node.typeAnnotation, context, rule.suggestions, messageId); + : getConfiguredSuggestions(node.typeAnnotation, context, rule.suggestions); return { context, diff --git a/tests/rules/__snapshots__/prefer-tacit.test.ts.snap b/tests/rules/__snapshots__/prefer-tacit.test.ts.snap index f04d9d2c9..53e339684 100644 --- a/tests/rules/__snapshots__/prefer-tacit.test.ts.snap +++ b/tests/rules/__snapshots__/prefer-tacit.test.ts.snap @@ -14,7 +14,7 @@ exports[`prefer-tacit > typescript > options > checkMemberExpressions > report m "severity": 2, "suggestions": [ { - "desc": "Potentially unnecessary function wrapper.", + "desc": "Remove unnecessary function wrapper.", "fix": { "range": [ 46, @@ -22,7 +22,7 @@ exports[`prefer-tacit > typescript > options > checkMemberExpressions > report m ], "text": "const foo = a.b.bind(a);", }, - "messageId": "generic", + "messageId": "genericSuggestion", }, ], }, @@ -43,7 +43,7 @@ exports[`prefer-tacit > typescript > options > checkMemberExpressions > report m "severity": 2, "suggestions": [ { - "desc": "Potentially unnecessary function wrapper.", + "desc": "Remove unnecessary function wrapper.", "fix": { "range": [ 12, @@ -51,7 +51,7 @@ exports[`prefer-tacit > typescript > options > checkMemberExpressions > report m ], "text": "/a/.test.bind(/a/)", }, - "messageId": "generic", + "messageId": "genericSuggestion", }, ], }, @@ -72,7 +72,7 @@ exports[`prefer-tacit > typescript > reports functions that are just instantiati "severity": 2, "suggestions": [ { - "desc": "Potentially unnecessary function wrapper.", + "desc": "Remove unnecessary function wrapper.", "fix": { "range": [ 26, @@ -80,7 +80,7 @@ exports[`prefer-tacit > typescript > reports functions that are just instantiati ], "text": "const foo = f;", }, - "messageId": "generic", + "messageId": "genericSuggestion", }, ], }, @@ -101,7 +101,7 @@ exports[`prefer-tacit > typescript > reports functions that can "safely" be chan "severity": 2, "suggestions": [ { - "desc": "Potentially unnecessary function wrapper.", + "desc": "Remove unnecessary function wrapper.", "fix": { "range": [ 29, @@ -109,7 +109,7 @@ exports[`prefer-tacit > typescript > reports functions that can "safely" be chan ], "text": "f", }, - "messageId": "generic", + "messageId": "genericSuggestion", }, ], }, @@ -130,7 +130,7 @@ exports[`prefer-tacit > typescript > reports functions that can "safely" be chan "severity": 2, "suggestions": [ { - "desc": "Potentially unnecessary function wrapper.", + "desc": "Remove unnecessary function wrapper.", "fix": { "range": [ 26, @@ -138,7 +138,7 @@ exports[`prefer-tacit > typescript > reports functions that can "safely" be chan ], "text": "Boolean", }, - "messageId": "generic", + "messageId": "genericSuggestion", }, ], },