From 1046c2bb60b2803e88caa9c2c2e1acbc0aa82b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sat, 18 Dec 2021 06:21:30 +0100 Subject: [PATCH] chore: fix ESLint errors --- lib/rules/arrow-parens.js | 12 ++++++++---- lib/rules/block-scoped-var.js | 16 +++++++++++----- lib/rules/no-instanceof-array.js | 7 +++++-- lib/rules/no-instanceof-wrapper.js | 7 +++++-- lib/rules/no-literal-call.js | 5 ++++- lib/rules/no-this-in-static.js | 5 ++++- lib/rules/no-use-ignored-vars.js | 7 +++++-- lib/rules/no-useless-rest-spread.js | 5 ++++- lib/rules/prefer-for-of.js | 10 ++++++---- 9 files changed, 52 insertions(+), 22 deletions(-) diff --git a/lib/rules/arrow-parens.js b/lib/rules/arrow-parens.js index ddc5100..f088c9b 100644 --- a/lib/rules/arrow-parens.js +++ b/lib/rules/arrow-parens.js @@ -34,6 +34,12 @@ module.exports = { "https://github.com/eslint-community/eslint-plugin-mysticatea/blob/HEAD/docs/rules/arrow-parens.md", }, fixable: "code", + messages: { + expectedParentheses: + "Expected to enclose this argument with parentheses.", + unexpectedParentheses: + "Unexpected parentheses enclosing this argument.", + }, schema: [], type: "suggestion", }, @@ -54,8 +60,7 @@ module.exports = { ) { context.report({ node, - message: - "Unexpected parentheses enclosing this argument.", + messageId: "unexpectedParentheses", fix(fixer) { const id = node.params[0] const begin = first.range[0] @@ -73,8 +78,7 @@ module.exports = { } else if (!isOpenParen(before) || !isSameLine(before, first)) { context.report({ node, - message: - "Expected to enclose this argument with parentheses.", + messageId: "expectedParentheses", fix(fixer) { const id = node.params[0] diff --git a/lib/rules/block-scoped-var.js b/lib/rules/block-scoped-var.js index 0d719c2..e0c7a20 100644 --- a/lib/rules/block-scoped-var.js +++ b/lib/rules/block-scoped-var.js @@ -200,6 +200,13 @@ module.exports = { "https://github.com/eslint-community/eslint-plugin-mysticatea/blob/HEAD/docs/rules/block-scoped-var.md", }, fixable: null, + messages: { + alreadyDefined: '"{{name}}" is already defined.', + definedInUpperScope: + '"{{name}}" is already defined in the upper scope.', + undefined: '"{{name}}" is not defined.', + unused: '"{{name}}" is defined but never used.', + }, schema: [], type: "suggestion", }, @@ -244,7 +251,7 @@ module.exports = { if (scope == null) { context.report({ node: reference.identifier, - message: '"{{name}}" is not defined.', + messageId: "undefined", data: { name: reference.identifier.name }, }) } @@ -255,7 +262,7 @@ module.exports = { for (const identifier of scope.redeclarations) { context.report({ node: identifier, - message: '"{{name}}" is already defined.', + messageId: "alreadyDefined", data: { name: identifier.name }, }) } @@ -263,8 +270,7 @@ module.exports = { if (scope.shadowing) { context.report({ node: scope.identifier, - message: - '"{{name}}" is already defined in the upper scope.', + messageId: "definedInUpperScope", data: { name: scope.identifier.name }, }) } @@ -272,7 +278,7 @@ module.exports = { if (hasReadRef && !scope.used) { context.report({ node: scope.identifier, - message: '"{{name}}" is defined but never used.', + messageId: "unused", data: { name: scope.identifier.name }, }) } diff --git a/lib/rules/no-instanceof-array.js b/lib/rules/no-instanceof-array.js index 5740db0..d800588 100644 --- a/lib/rules/no-instanceof-array.js +++ b/lib/rules/no-instanceof-array.js @@ -18,6 +18,10 @@ module.exports = { "https://github.com/eslint-community/eslint-plugin-mysticatea/blob/HEAD/docs/rules/no-instanceof-array.md", }, fixable: "code", + messages: { + noInstanceofArray: + "Unexpected 'instanceof' operator. Use 'Array.isArray' instead.", + }, schema: [], type: "problem", }, @@ -62,8 +66,7 @@ module.exports = { context.report({ node, loc: node.loc, - message: - "Unexpected 'instanceof' operator. Use 'Array.isArray' instead.", + messageId: "noInstanceofArray", fix: fixer => fixer.replaceText( node, diff --git a/lib/rules/no-instanceof-wrapper.js b/lib/rules/no-instanceof-wrapper.js index b7ff2dd..db8f5a0 100644 --- a/lib/rules/no-instanceof-wrapper.js +++ b/lib/rules/no-instanceof-wrapper.js @@ -18,6 +18,10 @@ module.exports = { "https://github.com/eslint-community/eslint-plugin-mysticatea/blob/HEAD/docs/rules/no-instanceof-wrapper.md", }, fixable: "code", + messages: { + noInstanceofWrapper: + "Unexpected 'instanceof' operator. Use 'typeof x === \"{{typeName}}\"' instead.", + }, schema: [], type: "problem", }, @@ -73,8 +77,7 @@ module.exports = { context.report({ node, loc: node.loc, - message: - "Unexpected 'instanceof' operator. Use 'typeof x === \"{{typeName}}\"' instead.", + messageId: "noInstanceofWrapper", data: { typeName }, fix: fixer => fixer.replaceText( diff --git a/lib/rules/no-literal-call.js b/lib/rules/no-literal-call.js index 0d70853..abfe735 100644 --- a/lib/rules/no-literal-call.js +++ b/lib/rules/no-literal-call.js @@ -25,6 +25,9 @@ module.exports = { "https://github.com/eslint-community/eslint-plugin-mysticatea/blob/HEAD/docs/rules/no-literal-call.md", }, fixable: null, + messages: { + noLiteralCall: "This is not a function.", + }, schema: [], type: "problem", }, @@ -41,7 +44,7 @@ module.exports = { if (pattern.test(callee.type)) { context.report({ node: callee, - message: "This is not a function.", + messageId: "noLiteralCall", }) } } diff --git a/lib/rules/no-this-in-static.js b/lib/rules/no-this-in-static.js index f6fa590..c024dda 100644 --- a/lib/rules/no-this-in-static.js +++ b/lib/rules/no-this-in-static.js @@ -18,6 +18,9 @@ module.exports = { "https://github.com/eslint-community/eslint-plugin-mysticatea/blob/HEAD/docs/rules/no-this-in-static.md", }, fixable: null, + messages: { + noThisInStatic: "Unexpected '{{type}}'.", + }, schema: [], type: "suggestion", }, @@ -73,7 +76,7 @@ module.exports = { context.report({ node, loc: node.loc, - message: "Unexpected '{{type}}'.", + messageId: "noThisInStatic", data: { type: sourceCode.getText(node) }, }) } diff --git a/lib/rules/no-use-ignored-vars.js b/lib/rules/no-use-ignored-vars.js index bbac67a..af80558 100644 --- a/lib/rules/no-use-ignored-vars.js +++ b/lib/rules/no-use-ignored-vars.js @@ -24,6 +24,10 @@ module.exports = { "https://github.com/eslint-community/eslint-plugin-mysticatea/blob/HEAD/docs/rules/no-use-ignored-vars.md", }, fixable: null, + messages: { + noUseIgnoredVars: + "Unexpected a use of '{{name}}'. This name is matched to ignored pattern.", + }, schema: [{ type: "string" }], type: "suggestion", }, @@ -65,8 +69,7 @@ module.exports = { context.report({ node: id, - message: - "Unexpected a use of '{{name}}'. This name is matched to ignored pattern.", + messageId: "noUseIgnoredVars", data: id, }) } diff --git a/lib/rules/no-useless-rest-spread.js b/lib/rules/no-useless-rest-spread.js index 5591a50..7eed0e0 100644 --- a/lib/rules/no-useless-rest-spread.js +++ b/lib/rules/no-useless-rest-spread.js @@ -101,6 +101,9 @@ module.exports = { "https://github.com/eslint-community/eslint-plugin-mysticatea/blob/HEAD/docs/rules/no-useless-rest-spread.md", }, fixable: "code", + messages: { + noUselessRestSpread: "Redundant {{type1}} {{type2}}.", + }, schema: [], type: "suggestion", }, @@ -139,7 +142,7 @@ module.exports = { context.report({ node, - message: "Redundant {{type1}} {{type2}}.", + messageId: "noUselessRestSpread", data: { type1, type2 }, fix: defineFixer(sourceCode, node), }) diff --git a/lib/rules/prefer-for-of.js b/lib/rules/prefer-for-of.js index 04fa77a..f3e8bae 100644 --- a/lib/rules/prefer-for-of.js +++ b/lib/rules/prefer-for-of.js @@ -16,7 +16,6 @@ const assert = require("assert") //------------------------------------------------------------------------------ const SENTINEL_TYPE = /(?:Declaration|Statement)$/u -const MESSAGE = "Expected for-of statement." /** * Checks whether the given outer node contains the given inner node. @@ -501,6 +500,9 @@ module.exports = { "https://github.com/eslint-community/eslint-plugin-mysticatea/blob/HEAD/docs/rules/prefer-for-of.md", }, fixable: "code", + messages: { + preferForOf: "Expected for-of statement.", + }, schema: [], type: "suggestion", }, @@ -547,7 +549,7 @@ module.exports = { const expressionStatementNode = funcInfo.node.parent.parent context.report({ node: expressionStatementNode, - message: MESSAGE, + messageId: "preferForOf", fix: fixArrayForEach.bind(null, context, funcInfo), }) } @@ -609,14 +611,14 @@ module.exports = { ) { context.report({ node, - message: MESSAGE, + messageId: "preferForOf", fix: fixForStatement.bind(null, context, node), }) } }, ForInStatement(node) { - context.report({ node, message: MESSAGE }) + context.report({ node, messageId: "preferForOf" }) }, } },