mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +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',
|
selector: 'ds-base-test-themable',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
})
|
})
|
||||||
class TestThemeableTomponent {
|
class TestThemeableComponent {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ Filename: `lint/test/fixture/src/app/test/themed-test-themeable.component.ts`
|
|||||||
TestThemeableComponent,
|
TestThemeableComponent,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
class ThemedTestThemeableTomponent extends ThemedComponent<TestThemeableComponent> {
|
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@@ -180,7 +180,7 @@ class Something {
|
|||||||
selector: 'ds-base-test-themable',
|
selector: 'ds-base-test-themable',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
})
|
})
|
||||||
class TestThemeableTomponent {
|
class TestThemeableComponent {
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
@@ -195,7 +195,7 @@ class TestThemeableTomponent {
|
|||||||
TestThemeableComponent,
|
TestThemeableComponent,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
class ThemedTestThemeableTomponent extends ThemedComponent<TestThemeableComponent> {
|
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
@@ -15,6 +15,8 @@ export enum Message {
|
|||||||
DUPLICATE_DECORATOR_CALL = 'duplicateDecoratorCall',
|
DUPLICATE_DECORATOR_CALL = 'duplicateDecoratorCall',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const decoratorCalls: Map<string, Set<string>> = new Map();
|
||||||
|
|
||||||
export const info: DSpaceESLintRuleInfo = {
|
export const info: DSpaceESLintRuleInfo = {
|
||||||
name: 'unique-decorators',
|
name: 'unique-decorators',
|
||||||
meta: {
|
meta: {
|
||||||
@@ -51,10 +53,9 @@ export const info: DSpaceESLintRuleInfo = {
|
|||||||
export const rule = ESLintUtils.RuleCreator.withoutDocs({
|
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();
|
|
||||||
|
|
||||||
return {
|
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)) {
|
if (isTestFile(context)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -64,13 +65,7 @@ export const rule = ESLintUtils.RuleCreator.withoutDocs({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: can we fold this into the selector actually?
|
if (!isUnique(node)) {
|
||||||
if (!(options[0].decorators as string[]).includes(node.callee.name)) {
|
|
||||||
// We don't care about this decorator
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isUnique(node, decoratorCalls)) {
|
|
||||||
context.report({
|
context.report({
|
||||||
messageId: Message.DUPLICATE_DECORATOR_CALL,
|
messageId: Message.DUPLICATE_DECORATOR_CALL,
|
||||||
node: node,
|
node: node,
|
||||||
@@ -168,7 +163,7 @@ function callKey(node: TSESTree.CallExpression): string {
|
|||||||
return key;
|
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;
|
const decorator = (node.callee as TSESTree.Identifier).name;
|
||||||
|
|
||||||
if (!decoratorCalls.has(decorator)) {
|
if (!decoratorCalls.has(decorator)) {
|
||||||
|
Reference in New Issue
Block a user