Resolve lint issues due to new default rules

We could turn these rules off, but it seems that they indicate some important inconsistencies.

A few cases have been ignored inline because they should be investigated in more detail, which is out of scope for this PR:
- Metadata representation components compare `BrowseByDataType` to a `ResourceType`. Could be related to #2949.
- We assume that dynamic form dates are always represented by strings, but they can also be `Date` or `object` according to the library (see da1742ce05/projects/ng-dynamic-forms/core/src/lib/model/dynamic-date-control.model.ts (L5))
This commit is contained in:
Yury Bondarenko
2024-04-18 10:11:56 +02:00
parent 14a19b2000
commit dc1053e3f9
33 changed files with 64 additions and 42 deletions

View File

@@ -43,7 +43,7 @@ function isAngularComponentDecorator(node: ts.Node) {
const method = decorator.expression as ts.CallExpression;
if (method.expression.kind === ts.SyntaxKind.Identifier) {
return (method.expression as Identifier).escapedText === 'Component';
return (method.expression as Identifier).text === 'Component';
}
}
}
@@ -60,7 +60,7 @@ function findImportDeclaration(source: ts.SourceFile, identifierName: string): t
const namedImports = importDeclaration.importClause?.namedBindings as ts.NamedImports;
for (const element of namedImports.elements) {
if (element.name.escapedText === identifierName) {
if (element.name.text === identifierName) {
return importDeclaration;
}
}

View File

@@ -52,7 +52,7 @@ export function findUsages(context: AnyRuleContext, localNode: TSESTree.Identifi
const usages: TSESTree.Identifier[] = [];
for (const token of source.ast.tokens) {
if (token.type === 'Identifier' && token.value === localNode.name && !match(token.range, localNode.range)) {
if (token.type === TSESTree.AST_TOKEN_TYPES.Identifier && token.value === localNode.name && !match(token.range, localNode.range)) {
const node = source.getNodeByRangeIndex(token.range[0]);
// todo: in some cases, the resulting node can actually be the whole program (!)
if (node !== null) {
@@ -70,7 +70,7 @@ export function findUsagesByName(context: AnyRuleContext, identifier: string): T
const usages: TSESTree.Identifier[] = [];
for (const token of source.ast.tokens) {
if (token.type === 'Identifier' && token.value === identifier) {
if (token.type === TSESTree.AST_TOKEN_TYPES.Identifier && token.value === identifier) {
const node = source.getNodeByRangeIndex(token.range[0]);
// todo: in some cases, the resulting node can actually be the whole program (!)
if (node !== null) {
@@ -83,11 +83,11 @@ export function findUsagesByName(context: AnyRuleContext, identifier: string): T
}
export function isPartOfTypeExpression(node: TSESTree.Identifier): boolean {
return node.parent?.type?.startsWith('TSType');
return node.parent?.type?.valueOf().startsWith('TSType');
}
export function isPartOfClassDeclaration(node: TSESTree.Identifier): boolean {
return node.parent?.type === 'ClassDeclaration';
return node.parent?.type === TSESTree.AST_NODE_TYPES.ClassDeclaration;
}
function fromSrc(path: string): string {
@@ -134,7 +134,7 @@ export function findImportSpecifier(context: AnyRuleContext, identifier: string)
const usages: TSESTree.Identifier[] = [];
for (const token of source.ast.tokens) {
if (token.type === 'Identifier' && token.value === identifier) {
if (token.type === TSESTree.AST_TOKEN_TYPES.Identifier && token.value === identifier) {
const node = source.getNodeByRangeIndex(token.range[0]);
// todo: in some cases, the resulting node can actually be the whole program (!)
if (node && node.parent && node.parent.type === TSESTree.AST_NODE_TYPES.ImportSpecifier) {