mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Workaround/document edge case where node can't be found by token
This commit is contained in:
@@ -335,6 +335,69 @@ cy.get('ds-themeable');
|
|||||||
cy.get('#test > ds-themeable > #nest');
|
cy.get('#test > ds-themeable > #nest');
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'edge case: unable to find usage node through usage token, but import is still flagged and fixed',
|
||||||
|
code: `
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
import { Context } from '../../core/shared/context.model';
|
||||||
|
import { TestThemeableComponent } from '../test/test-themeable.component.ts';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'ds-admin-search-page',
|
||||||
|
templateUrl: './admin-search-page.component.html',
|
||||||
|
styleUrls: ['./admin-search-page.component.scss'],
|
||||||
|
standalone: true,
|
||||||
|
imports: [
|
||||||
|
TestThemeableComponent
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Component that represents a search page for administrators
|
||||||
|
*/
|
||||||
|
export class AdminSearchPageComponent {
|
||||||
|
/**
|
||||||
|
* The context of this page
|
||||||
|
*/
|
||||||
|
context: Context = Context.AdminSearch;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
messageId: Message.WRONG_IMPORT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
messageId: Message.WRONG_CLASS,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
output: `
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
import { Context } from '../../core/shared/context.model';
|
||||||
|
import { ThemedTestThemeableComponent } from '../test/themed-test-themeable.component.ts';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'ds-admin-search-page',
|
||||||
|
templateUrl: './admin-search-page.component.html',
|
||||||
|
styleUrls: ['./admin-search-page.component.scss'],
|
||||||
|
standalone: true,
|
||||||
|
imports: [
|
||||||
|
ThemedTestThemeableComponent
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Component that represents a search page for administrators
|
||||||
|
*/
|
||||||
|
export class AdminSearchPageComponent {
|
||||||
|
/**
|
||||||
|
* The context of this page
|
||||||
|
*/
|
||||||
|
context: Context = Context.AdminSearch;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -54,6 +54,7 @@ export function findUsages(context: AnyRuleContext, localNode: TSESTree.Identifi
|
|||||||
for (const token of source.ast.tokens) {
|
for (const token of source.ast.tokens) {
|
||||||
if (token.type === 'Identifier' && token.value === localNode.name && !match(token.range, localNode.range)) {
|
if (token.type === 'Identifier' && token.value === localNode.name && !match(token.range, localNode.range)) {
|
||||||
const node = source.getNodeByRangeIndex(token.range[0]);
|
const node = source.getNodeByRangeIndex(token.range[0]);
|
||||||
|
// todo: in some cases, the resulting node can actually be the whole program (!)
|
||||||
if (node !== null) {
|
if (node !== null) {
|
||||||
usages.push(node as TSESTree.Identifier);
|
usages.push(node as TSESTree.Identifier);
|
||||||
}
|
}
|
||||||
@@ -64,12 +65,9 @@ export function findUsages(context: AnyRuleContext, localNode: TSESTree.Identifi
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isPartOfTypeExpression(node: TSESTree.Identifier): boolean {
|
export function isPartOfTypeExpression(node: TSESTree.Identifier): boolean {
|
||||||
return node.parent.type.startsWith('TSType');
|
return node.parent?.type?.startsWith('TSType');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isPartOfClassDeclaration(node: TSESTree.Identifier): boolean {
|
export function isPartOfClassDeclaration(node: TSESTree.Identifier): boolean {
|
||||||
if (node.parent === undefined) {
|
return node.parent?.type === 'ClassDeclaration';
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return node.parent.type === 'ClassDeclaration';
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user