117616: Fix rule creator call & add structure test case

This commit is contained in:
Yury Bondarenko
2024-08-30 12:11:45 +02:00
committed by Alexandre Vryghem
parent 01c8c60624
commit 8ff5a23c40
2 changed files with 18 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { import {
AST_NODE_TYPES, AST_NODE_TYPES,
ESLintUtils,
TSESLint, TSESLint,
TSESTree, TSESTree,
} from '@typescript-eslint/utils'; } from '@typescript-eslint/utils';
@@ -30,6 +31,9 @@ export const info: DSpaceESLintRuleInfo = {
properties: { properties: {
decorators: { decorators: {
type: 'array', type: 'array',
items: {
type: 'string',
},
}, },
}, },
}, },
@@ -44,7 +48,7 @@ export const info: DSpaceESLintRuleInfo = {
], ],
}; };
export const rule = { export const rule = ESLintUtils.RuleCreator.withoutDocs({
...info, ...info,
create(context: TSESLint.RuleContext<Message, unknown[]>, options: any) { create(context: TSESLint.RuleContext<Message, unknown[]>, options: any) {
const decoratorCalls: Map<string, Set<string>> = new Map(); const decoratorCalls: Map<string, Set<string>> = new Map();
@@ -75,7 +79,7 @@ export const rule = {
}, },
}; };
}, },
}; });
export const tests: NamedTests = { export const tests: NamedTests = {
plugin: info.name, plugin: info.name,

View File

@@ -6,6 +6,8 @@
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
import { RuleMetaData } from '@typescript-eslint/utils/ts-eslint';
import { default as html } from '../src/rules/html'; import { default as html } from '../src/rules/html';
import { default as ts } from '../src/rules/ts'; 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.valid.length).toBeGreaterThan(0);
expect(ruleExports.tests.invalid.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<string, []>);
});
}); });
} }
}); });