diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eea00da..d623be9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,24 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [v4.0.1](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/compare/v4.0.1...v4.0.1) + +#### [v4.0.1](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/compare/v4.0.0...v4.0.1) + +> 15 October 2021 + +- Fix: Handle `meta: {} as const` for TypeScript rules [`#219`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/pull/219) +- Docs: Add missing date in changelog [`#218`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/pull/218) +- Fix: Avoid crash when provided suggestions array has non-object [`#216`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/pull/216) +- Docs: Improve CHANGELOG for v4 [`#217`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/pull/217) +- Release 4.0.1 [`258bc5e`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/commit/258bc5e0f9c7165126d3c082579749c2fdd17057) + #### [v4.0.0](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/compare/v4.0.0-3...v4.0.0) +> 15 October 2021 + +- Release 4.0.0 [`fe4bca3`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/commit/fe4bca3b73405428c566760069cbf338db2b9202) + #### [v4.0.0-3](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/compare/v4.0.0-2...v4.0.0-3) > 15 October 2021 @@ -198,22 +214,16 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - Build: update package.json and changelog for v3.0.1 [`0b4bcaf`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/commit/0b4bcaf8a168bd747f2334015ef42d8f169c1dcb) - chore: fix failing tests [`e6aa71f`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/commit/e6aa71f8b018c109ab86ca887f70b253a3e312a3) -### [v3.0.0](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/compare/v2.3.1...v3.0.0) +### [v3.0.0](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/compare/v2.3.0...v3.0.0) > 8 April 2021 - Breaking: change test-case-property-ordering default options (fixes #79) [`#93`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/pull/93) - Breaking: drop eslint < 7 & node.js < 10 [`#95`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/pull/95) +- Docs: Grammar in `require-meta-schema.md` [`#103`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/pull/103) - Breaking: change test-case-property-ordering default options (fixes #79) (#93) [`#79`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/79) - Build: update package.json and changelog for v3.0.0 [`02c1f34`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/commit/02c1f347f2f0881e364724a4fce69e9da2ce9313) -#### [v2.3.1](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/compare/v2.3.0...v2.3.1) - -> 8 April 2021 - -- Docs: Grammar in `require-meta-schema.md` [`#103`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/pull/103) -- Build: update package.json and changelog for v2.3.1 [`d95a1a6`](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/commit/d95a1a666be795d7b0e117c34c591559c512ae03) - #### [v2.3.0](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/compare/v2.2.2...v2.3.0) > 22 June 2020 diff --git a/lib/utils.js b/lib/utils.js index 77779e7c..3b27af1d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -97,7 +97,8 @@ function collectInterestingProperties (properties, interestingKeys) { return properties.reduce((parsedProps, prop) => { const keyValue = module.exports.getKeyName(prop); if (interestingKeys.has(keyValue)) { - parsedProps[keyValue] = prop.value; + // In TypeScript, unwrap any usage of `{} as const`. + parsedProps[keyValue] = prop.value.type === 'TSAsExpression' ? prop.value.expression : prop.value; } return parsedProps; }, {}); @@ -467,14 +468,17 @@ module.exports = { // Suggestion messages ...((reportInfo.suggest && reportInfo.suggest.elements) || []) .map(suggestObjNode => { + if (suggestObjNode.type !== 'ObjectExpression') { + // Ignore non-objects (like variables or function calls). + return null; + } return { messageId: findObjectPropertyValueByKeyName(suggestObjNode, 'messageId'), message: findObjectPropertyValueByKeyName(suggestObjNode, 'desc'), // Note: suggestion message named `desc` data: findObjectPropertyValueByKeyName(suggestObjNode, 'data'), fix: findObjectPropertyValueByKeyName(suggestObjNode, 'fix'), }; - } - ), + }).filter(item => item !== null), ]; }, diff --git a/package.json b/package.json index 7d768b41..b3783e58 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-eslint-plugin", - "version": "4.0.0", + "version": "4.0.1", "description": "An ESLint plugin for linting ESLint plugins", "author": "Teddy Katz", "main": "lib/index.js", diff --git a/tests/lib/utils.js b/tests/lib/utils.js index e4d9240e..bca41252 100644 --- a/tests/lib/utils.js +++ b/tests/lib/utils.js @@ -139,6 +139,13 @@ describe('utils', () => { isNewStyle: true, }, + // Util function with "{} as const". + 'export default createESLintRule({ create() {}, meta: {} as const });': { + create: { type: 'FunctionExpression' }, + meta: { type: 'ObjectExpression' }, + isNewStyle: true, + }, + // Util function from util object 'export default util.createRule({ create() {}, meta: {} });': { create: { type: 'FunctionExpression' }, @@ -626,6 +633,7 @@ describe('utils', () => { describe('collectReportViolationAndSuggestionData', () => { const CASES = [ { + // One suggestion. code: ` context.report({ node: {}, @@ -656,6 +664,68 @@ describe('utils', () => { }, ], }, + { + // Suggestions using an array variable. + code: ` + context.report({ + node: {}, + message: "message1", + messageId: "messageId1", + data: { foo: 'hello' }, + fix(fixer) {}, + suggest: SUGGESTIONS + }); + `, + shouldMatch: [ + { + message: { type: 'Literal', value: 'message1' }, + messageId: { type: 'Literal', value: 'messageId1' }, + data: { type: 'ObjectExpression', properties: [{ key: { name: 'foo' } }] }, + fix: { type: 'FunctionExpression' }, + }, + ], + }, + { + // Suggestions using array item variables. + code: ` + context.report({ + node: {}, + message: "message1", + messageId: "messageId1", + data: { foo: 'hello' }, + fix(fixer) {}, + suggest: [ SUGGEST_1, SUGGEST_2 ] + }); + `, + shouldMatch: [ + { + message: { type: 'Literal', value: 'message1' }, + messageId: { type: 'Literal', value: 'messageId1' }, + data: { type: 'ObjectExpression', properties: [{ key: { name: 'foo' } }] }, + fix: { type: 'FunctionExpression' }, + }, + ], + }, + { + // No suggestions. + code: ` + context.report({ + node: {}, + message: "message1", + messageId: "messageId1", + data: { foo: 'hello' }, + fix(fixer) {}, + }); + `, + shouldMatch: [ + { + message: { type: 'Literal', value: 'message1' }, + messageId: { type: 'Literal', value: 'messageId1' }, + data: { type: 'ObjectExpression', properties: [{ key: { name: 'foo' } }] }, + fix: { type: 'FunctionExpression' }, + }, + ], + }, ]; it('behaves correctly', () => {