mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
117616: Fixed unique-decorators rule to work across multiple files
Also moved the logic to filter out unwanted decorators to the ESLint's selector and fixed a typo
This commit is contained in:
@@ -34,7 +34,7 @@ class Something {
|
||||
selector: 'ds-base-test-themable',
|
||||
standalone: true,
|
||||
})
|
||||
class TestThemeableTomponent {
|
||||
class TestThemeableComponent {
|
||||
}
|
||||
```
|
||||
|
||||
@@ -50,7 +50,7 @@ Filename: `lint/test/fixture/src/app/test/themed-test-themeable.component.ts`
|
||||
TestThemeableComponent,
|
||||
],
|
||||
})
|
||||
class ThemedTestThemeableTomponent extends ThemedComponent<TestThemeableComponent> {
|
||||
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
|
||||
}
|
||||
```
|
||||
|
||||
|
@@ -180,7 +180,7 @@ class Something {
|
||||
selector: 'ds-base-test-themable',
|
||||
standalone: true,
|
||||
})
|
||||
class TestThemeableTomponent {
|
||||
class TestThemeableComponent {
|
||||
}
|
||||
`,
|
||||
},
|
||||
@@ -195,7 +195,7 @@ class TestThemeableTomponent {
|
||||
TestThemeableComponent,
|
||||
],
|
||||
})
|
||||
class ThemedTestThemeableTomponent extends ThemedComponent<TestThemeableComponent> {
|
||||
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
|
||||
}
|
||||
`,
|
||||
},
|
||||
|
@@ -15,6 +15,8 @@ export enum Message {
|
||||
DUPLICATE_DECORATOR_CALL = 'duplicateDecoratorCall',
|
||||
}
|
||||
|
||||
const decoratorCalls: Map<string, Set<string>> = new Map();
|
||||
|
||||
export const info: DSpaceESLintRuleInfo = {
|
||||
name: 'unique-decorators',
|
||||
meta: {
|
||||
@@ -51,10 +53,9 @@ export const info: DSpaceESLintRuleInfo = {
|
||||
export const rule = ESLintUtils.RuleCreator.withoutDocs({
|
||||
...info,
|
||||
create(context: TSESLint.RuleContext<Message, unknown[]>, options: any) {
|
||||
const decoratorCalls: Map<string, Set<string>> = new Map();
|
||||
|
||||
return {
|
||||
'ClassDeclaration > Decorator > CallExpression': (node: TSESTree.CallExpression) => { // todo: limit to class decorators
|
||||
[`ClassDeclaration > Decorator > CallExpression[callee.name=/^(${options[0].decorators.join('|')})$/]`]: (node: TSESTree.CallExpression) => {
|
||||
if (isTestFile(context)) {
|
||||
return;
|
||||
}
|
||||
@@ -64,13 +65,7 @@ export const rule = ESLintUtils.RuleCreator.withoutDocs({
|
||||
return;
|
||||
}
|
||||
|
||||
// todo: can we fold this into the selector actually?
|
||||
if (!(options[0].decorators as string[]).includes(node.callee.name)) {
|
||||
// We don't care about this decorator
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isUnique(node, decoratorCalls)) {
|
||||
if (!isUnique(node)) {
|
||||
context.report({
|
||||
messageId: Message.DUPLICATE_DECORATOR_CALL,
|
||||
node: node,
|
||||
@@ -168,7 +163,7 @@ function callKey(node: TSESTree.CallExpression): string {
|
||||
return key;
|
||||
}
|
||||
|
||||
function isUnique(node: TSESTree.CallExpression, decoratorCalls: Map<string, Set<string>>): boolean {
|
||||
function isUnique(node: TSESTree.CallExpression): boolean {
|
||||
const decorator = (node.callee as TSESTree.Identifier).name;
|
||||
|
||||
if (!decoratorCalls.has(decorator)) {
|
||||
|
Reference in New Issue
Block a user