From 8ff5a23c40cdf5103febaaf15d9b6b4eb56746d2 Mon Sep 17 00:00:00 2001 From: Yury Bondarenko Date: Fri, 30 Aug 2024 12:11:45 +0200 Subject: [PATCH] 117616: Fix rule creator call & add structure test case --- lint/src/rules/ts/unique-decorators.ts | 8 ++++++-- lint/test/structure.spec.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lint/src/rules/ts/unique-decorators.ts b/lint/src/rules/ts/unique-decorators.ts index acbc3ab12b..17e4a547fb 100644 --- a/lint/src/rules/ts/unique-decorators.ts +++ b/lint/src/rules/ts/unique-decorators.ts @@ -1,5 +1,6 @@ import { AST_NODE_TYPES, + ESLintUtils, TSESLint, TSESTree, } from '@typescript-eslint/utils'; @@ -30,6 +31,9 @@ export const info: DSpaceESLintRuleInfo = { properties: { decorators: { type: 'array', + items: { + type: 'string', + }, }, }, }, @@ -44,7 +48,7 @@ export const info: DSpaceESLintRuleInfo = { ], }; -export const rule = { +export const rule = ESLintUtils.RuleCreator.withoutDocs({ ...info, create(context: TSESLint.RuleContext, options: any) { const decoratorCalls: Map> = new Map(); @@ -75,7 +79,7 @@ export const rule = { }, }; }, -}; +}); export const tests: NamedTests = { plugin: info.name, diff --git a/lint/test/structure.spec.ts b/lint/test/structure.spec.ts index 24e69e42d9..297ce8b5ac 100644 --- a/lint/test/structure.spec.ts +++ b/lint/test/structure.spec.ts @@ -6,6 +6,8 @@ * http://www.dspace.org/license/ */ +import { RuleMetaData } from '@typescript-eslint/utils/ts-eslint'; + import { default as html } from '../src/rules/html'; import { default as ts } from '../src/rules/ts'; @@ -69,6 +71,16 @@ describe('plugin structure', () => { expect(ruleExports.tests.valid.length).toBeGreaterThan(0); expect(ruleExports.tests.invalid.length).toBeGreaterThan(0); }); + + it('should contain a valid ESLint rule', () => { + // we don't have a better way to enforce this, but it's something at least + expect((ruleExports.rule as any).name).toBeUndefined( + 'Rules should be passed to RuleCreator, omitting info.name since it is not part of the RuleWithMeta interface', + ); + + expect(ruleExports.rule.create).toBeTruthy(); + expect(ruleExports.rule.meta).toEqual(ruleExports.info.meta as RuleMetaData); + }); }); } });