diff --git a/linter-4.2/docs/rules/recipe118.md b/linter-4.2/docs/rules/recipe118.md deleted file mode 100644 index f625bc3e982353617c9dd28f7c6d67ff886e1e6d..0000000000000000000000000000000000000000 --- a/linter-4.2/docs/rules/recipe118.md +++ /dev/null @@ -1,39 +0,0 @@ -# Special import type declarations are not supported - -Rule ``arkts-no-special-imports`` - -**Severity: error** - -ArkTS does not have a special notation for importing types. -Use ordinary import instead. - - -## TypeScript - - -``` - - // Re-using the same import - import { APIResponseType } from "api" - - // Explicitly use import type - import type { APIResponseType } from "api" - -``` - -## ArkTS - - -``` - - import { APIResponseType } from "api" - -``` - -## See also - -- Recipe 119: Importing a module for side-effects only is not supported (``arkts-no-side-effects-imports``) -- Recipe 120: ``import default as ...`` is not supported (``arkts-no-import-default-as``) -- Recipe 121: ``require`` and ``import`` assignment are not supported (``arkts-no-require``) - - diff --git a/linter-4.2/docs/rules/recipe127.md b/linter-4.2/docs/rules/recipe127.md deleted file mode 100644 index c89d24fbac4b50b1e68937ea99e7e979ae8c1452..0000000000000000000000000000000000000000 --- a/linter-4.2/docs/rules/recipe127.md +++ /dev/null @@ -1,48 +0,0 @@ -# Special ``export type`` declarations are not supported - -Rule ``arkts-no-special-exports`` - -**Severity: error** - -ArkTS does not have a special notation for exporting types through -``export type ...``. Use ordinary export instead. - - -## TypeScript - - -``` - - // Explicitly exported class: - export class Class1 { - // ... - } - - // Declared class later exported through export type ... - class Class2 { - // ... - } - - // This is not supported: - export type { Class2 } - -``` - -## ArkTS - - -``` - - // Explicitly exported class: - export class Class1 { - // ... - } - - // Explicitly exported class: - export class Class2 { - // ... - } - -``` - - diff --git a/linter-4.2/docs/rules/recipe144.md b/linter-4.2/docs/rules/recipe144.md index 28acf4a49c2d12c132c77f1e840a1d5de12e0f0d..ec36a4ffbf2f7a833502932ffc2010f44f6e2d24 100644 --- a/linter-4.2/docs/rules/recipe144.md +++ b/linter-4.2/docs/rules/recipe144.md @@ -29,8 +29,6 @@ Properties and functions of the global object: ``eval`` ``handler.has()``, ``handler.isExtensible()``, ``handler.ownKeys()``, ``handler.preventExtensions()``, ``handler.set()``, ``handler.setPrototypeOf()`` -``ArrayBuffer``: ``isView`` - ## See also diff --git a/linter-4.2/docs/rules/recipe151.md b/linter-4.2/docs/rules/recipe151.md index 0b00ba64328b8da460cba56c63a6dd63fd050e23..2e7fd2d46a7c1a86d1c9ac02edd38945f5cfd0b1 100644 --- a/linter-4.2/docs/rules/recipe151.md +++ b/linter-4.2/docs/rules/recipe151.md @@ -1,17 +1,18 @@ # Usage of ``ESObject`` type is restricted -Rule ``arkts-limited-esobject`` +Rule ``arkts-limited-esobj`` **Severity: warning** -ArkTS does not allow using ``ESObject`` type in some cases. The most part of limitations -are put in place in order to prevent spread of dynamic objects in the static codebase. -The only scenario where it is permited to use ``ESObject`` as type specifier is in local -variable declaration. Initialization of variables with ``ESObject`` type is also limited. -Such variables can only be initialized with values that originate from interop: -other ``ESObject`` typed variables, any, unknown, variables with anonymous type, etc. -It is prohibited to initialize ``ESObject`` typed variable with statically typed value. -Varaible of type ``ESObject`` can only be passed to interop calls and assigned to other +ArkTS does not allow using ``ESObject`` type in some cases. The most part of +limitations are put in place in order to prevent spread of dynamic objects in +the static codebase. The only scenario where it is permited to use ``ESObject`` +as type specifier is in local variable declaration. Initialization of variables +with ``ESObject`` type is also limited. Such variables can only be initialized +with values that originate from interop: other ``ESObject`` typed variables, +any, unknown, variables with anonymous type, etc. It is prohibited to +initialize ``ESObject`` typed variable with statically typed value. Varaible +of type ``ESObject`` can only be passed to interop calls and assigned to other variables of type ``ESObject``. @@ -32,12 +33,13 @@ variables of type ``ESObject``. let e3: ESObject = {}; // CTE - can't initialize ESObject with not dynamic values let e4: ESObject = []; // CTE - can't initialize ESObject with not dynamic values let e5: ESObject = ""; // CTE - can't initialize ESObject with not dynamic values + e5['prop'] // CTE - can't access dynamic properties of ESObject + e5[1] // CTE - can't access dynamic properties of ESObject + e5.prop // CTE - can't access dynamic properties of ESObject + let e6: ESObject = foo(); // OK - explicitly annotaded as ESObject let e7 = e6; // OK - initialize ESObject with ESObject - e6['prop'] // CTE - can't access dynamic properties of ESObject - e6[1] // CTE - can't access dynamic properties of ESObject - e6.prop // CTE - can't access dynamic properties of ESObject - bar(e6) // OK - ESObject is passed to interop call + bar(e7) // OK - ESObject is passed to interop call } ``` @@ -51,4 +53,3 @@ variables of type ``ESObject``. - Recipe 066: ``in`` operator is not supported (``arkts-no-in``) - Recipe 137: ``globalThis`` is not supported (``arkts-no-globalthis``) - diff --git a/linter-4.2/docs/rules/recipe29.md b/linter-4.2/docs/rules/recipe29.md index c7be978d6962ce635842df26f13c20591f59b060..7af61c43e6cc5976617e17be86598978444d8ebe 100644 --- a/linter-4.2/docs/rules/recipe29.md +++ b/linter-4.2/docs/rules/recipe29.md @@ -10,9 +10,13 @@ that are either declared in the class, or accessible via inheritance. Accessing any other fields is prohibited, and causes compile-time errors. To access a field, use ``obj.field`` syntax, indexed access (``obj["field"]``) -is not supported. An exception are all typed arrays from the standard library -(for example, ``Int32Array``), which support access to their elements through -``container[index]`` syntax. +is not supported. An exception are: + +- All typed arrays from the standard library (for example, ``Int32Array``), which +support access to their elements through ``container[index]`` syntax. +- Tuples. +- Records. +- Enums. ## TypeScript diff --git a/linter-4.2/scripts/update-test-results.mjs b/linter-4.2/scripts/update-test-results.mjs index dc579e42453a4416215504af7d0e3133221a4f33..45029c37eb3f2858d3a3848b5eebc2453598d268 100644 --- a/linter-4.2/scripts/update-test-results.mjs +++ b/linter-4.2/scripts/update-test-results.mjs @@ -37,7 +37,7 @@ const RESULTS_DIR = 'results' let testDirs = []; // forces to update all tests regardless of whether there was diff in a test result -const force_update = false; +let force_update = false; for (let arg of process.argv.slice(2)) { if (arg === '--force') @@ -72,33 +72,37 @@ function readTestFile(filePath) { function updateTest(testDir, testFile, mode) { let resultExt = RESULT_EXT[mode]; - let testFileWithExt = testFile + resultExt; + let resultFileWithExt = testFile + resultExt; + let resultFilePath = path.join(testDir, resultFileWithExt); // Do not update autofix result if test is skipped - if (mode === Mode.AUTOFIX && fs.existsSync(path.join(testDir, testFileWithExt + AUTOFIX_SKIP_EXT))) { + if (mode === Mode.AUTOFIX && fs.existsSync(path.join(testDir, testFile + AUTOFIX_SKIP_EXT))) { return; } - // Update test result when 'diff' exists or the 'force' option is enabled. - if (!fs.existsSync(path.join(testDir, RESULTS_DIR, testFileWithExt + DIFF_EXT)) && !force_update) { + // Update test result when: + // - '.diff' exists + // - expected '.json' doesn't exist + // - 'force' option is enabled + if (fs.existsSync(resultFilePath) && !fs.existsSync(path.join(testDir, RESULTS_DIR, resultFileWithExt + DIFF_EXT)) && !force_update) { return; } - let expectedResult = readTestFile(path.join(testDir, testFileWithExt)); + let expectedResult = readTestFile(resultFilePath); const copyright = expectedResult?.copyright ?? DEFAULT_COPYRIGHT; - let actualResult = readTestFile(path.join(testDir, RESULTS_DIR, testFileWithExt)); + let actualResult = readTestFile(path.join(testDir, RESULTS_DIR, resultFileWithExt)); if (!actualResult || !actualResult.nodes) { - console.log(`Failed to update ${testFileWithExt}: couldn't read ACTUAL result file.`); + console.log(`Failed to update ${resultFileWithExt}: couldn't read ACTUAL result file.`); return; } // Write file with actual test results. let newResultJSON = JSON.stringify({ copyright, nodes: actualResult.nodes }, null, 4); - fs.writeFileSync(path.join(testDir, testFileWithExt), newResultJSON); + fs.writeFileSync(resultFilePath, newResultJSON); - console.log(`Updated ${testFileWithExt}`); + console.log(`Updated ${resultFileWithExt}`); } for (let testDir of testDirs) { diff --git a/linter-4.2/src/CookBookMsg.ts b/linter-4.2/src/CookBookMsg.ts index c097345da5b47ffe0f98b7215329933df4889a14..e505f59a8b627c612a0313735ea504974a93f052 100644 --- a/linter-4.2/src/CookBookMsg.ts +++ b/linter-4.2/src/CookBookMsg.ts @@ -16,7 +16,7 @@ export const cookBookMsg: string[] = []; export const cookBookTag: string[] = []; -for (let i = 0; i <= 150; i++) { +for (let i = 0; i <= 151; i++) { cookBookMsg[i] = ''; } @@ -135,7 +135,7 @@ cookBookTag[112] = ''; cookBookTag[113] = '"enum" declaration merging is not supported (arkts-no-enum-merging)'; cookBookTag[114] = 'Namespaces cannot be used as objects (arkts-no-ns-as-obj)'; cookBookTag[115] = ''; -cookBookTag[116] = 'Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)'; +cookBookTag[116] = 'Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)'; cookBookTag[117] = ''; cookBookTag[118] = 'Special import type declarations are not supported (arkts-no-special-imports)'; cookBookTag[119] = 'Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)'; @@ -170,4 +170,4 @@ cookBookTag[147] = 'No dependencies on TypeScript code are currently allowed (ar cookBookTag[148] = 'No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)'; cookBookTag[149] = 'Classes cannot be used as objects (arkts-no-classes-as-obj)'; cookBookTag[150] = '"import" statements after other statements are not allowed (arkts-no-misplaced-imports)'; -cookBookTag[151] = 'Usage of "ESObject" type is restricted (arkts-limited-esobject)'; +cookBookTag[151] = 'Usage of "ESObject" type is restricted (arkts-limited-esobj)'; diff --git a/linter-4.2/src/Problems.ts b/linter-4.2/src/Problems.ts index 98bd4701b9054be916c8f229cada1cde816e8dad..61d08d5cb247a8194b204c836b50aa4e0d2c4d4f 100644 --- a/linter-4.2/src/Problems.ts +++ b/linter-4.2/src/Problems.ts @@ -27,14 +27,15 @@ export enum FaultID { ConditionalType, MappedType, NamespaceAsObject, ClassAsObject, NonDeclarationInNamespace, GeneratorFunction, FunctionContainsThis, PropertyAccessByIndex, JsxElement, EnumMemberNonConstInit, ImplementsClass, MethodReassignment, MultipleStaticBlocks, ThisType, - IntefaceExtendDifProps, StructuralIdentity, TypeOnlyImport, TypeOnlyExport, DefaultImport, + IntefaceExtendDifProps, StructuralIdentity, DefaultImport, ExportAssignment, ImportAssignment, GenericCallNoTypeArgs, ParameterProperties, InstanceofUnsupported, ShorthandAmbientModuleDecl, WildcardsInModuleName, UMDModuleDefinition, NewTarget, DefiniteAssignment, Prototype, GlobalThis, UtilityType, PropertyDeclOnFunction, FunctionApplyBindCall, ConstAssertion, ImportAssertion, SpreadOperator, LimitedStdLibApi, ErrorSuppression, StrictDiagnostic, UnsupportedDecorators, ImportAfterStatement, - EsObjectType, LAST_ID, // this should always be last enum + EsObjectType, + LAST_ID, // this should always be last enum` } export class FaultAttributs { @@ -107,11 +108,9 @@ faultsAttrs[FaultID.EnumMerging] = {cookBookRef: '113',}; faultsAttrs[FaultID.NamespaceAsObject] = {cookBookRef: '114',}; faultsAttrs[FaultID.NonDeclarationInNamespace] = {cookBookRef: '116',}; faultsAttrs[FaultID.ImportFromPath] = {cookBookRef: '119',}; -faultsAttrs[FaultID.TypeOnlyImport] = {migratable: true, cookBookRef: '118',}; faultsAttrs[FaultID.DefaultImport] = {migratable: true, cookBookRef: '120',}; faultsAttrs[FaultID.ImportAssignment] = {cookBookRef: '121',}; faultsAttrs[FaultID.ExportAssignment] = {cookBookRef: '126',}; -faultsAttrs[FaultID.TypeOnlyExport] = {migratable: true, cookBookRef: '127',}; faultsAttrs[FaultID.ShorthandAmbientModuleDecl] = {cookBookRef: '128',}; faultsAttrs[FaultID.WildcardsInModuleName] = {cookBookRef: '129',}; faultsAttrs[FaultID.UMDModuleDefinition] = {cookBookRef: '130',}; @@ -130,4 +129,4 @@ faultsAttrs[FaultID.ErrorSuppression] = {cookBookRef: '146',}; faultsAttrs[FaultID.UnsupportedDecorators] = {warning: true, cookBookRef: '148',}; faultsAttrs[FaultID.ClassAsObject] = {cookBookRef: '149',}; faultsAttrs[FaultID.ImportAfterStatement] = {cookBookRef: '150',}; -faultsAttrs[FaultID.EsObjectType] = {warning: true, cookBookRef: '151',}; +faultsAttrs[FaultID.EsObjectType] = {warning: true, cookBookRef: '151'}; diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index 27442da9f6353270955b0c54de49988c6273e5b3..b83c5eba8e0e689b7472e48d4bdd5c612ea237fa 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -61,6 +61,7 @@ export class TypeScriptLinter { currentErrorLine: number; currentWarningLine: number; staticBlocks: Set; + walkedComments: Set; libraryTypeCallDiagnosticChecker: LibraryTypeCallDiagnosticChecker; private sourceFile?: ts.SourceFile; @@ -83,6 +84,7 @@ export class TypeScriptLinter { this.currentErrorLine = 0; this.currentWarningLine = 0; this.staticBlocks = new Set(); + this.walkedComments = new Set(); this.libraryTypeCallDiagnosticChecker = new LibraryTypeCallDiagnosticChecker(TypeScriptLinter.filteredDiagnosticMessages); for (let i = 0; i < FaultID.LAST_ID; i++) { @@ -136,7 +138,6 @@ export class TypeScriptLinter { [ts.SyntaxKind.ElementAccessExpression, this.handleElementAccessExpression], [ts.SyntaxKind.EnumMember, this.handleEnumMember], [ts.SyntaxKind.TypeReference, this.handleTypeReference], - [ts.SyntaxKind.ExportDeclaration, this.handleExportDeclaration], [ts.SyntaxKind.ExportAssignment, this.handleExportAssignment], [ts.SyntaxKind.CallExpression, this.handleCallExpression], [ts.SyntaxKind.MetaProperty, this.handleMetaProperty], @@ -148,6 +149,7 @@ export class TypeScriptLinter { [ts.SyntaxKind.SetAccessor, this.handleSetAccessor], [ts.SyntaxKind.ConstructSignature, this.handleConstructSignature], [ts.SyntaxKind.ExpressionWithTypeArguments, this.handleExpressionWithTypeArguments], + [ts.SyntaxKind.ComputedPropertyName, this.handleComputedPropertyName], ]); public incrementCounters( @@ -254,7 +256,12 @@ export class TypeScriptLinter { } } - ts.forEachChild(node, visitTSNodeImpl); + // #13972: The 'ts.forEachChild' doesn't iterate over in-between punctuation tokens. + // As result, we can miss comment directives attached to those. Instead, use 'node.getChildren()'. + // to traverse child nodes. + for (const child of node.getChildren()) { + visitTSNodeImpl(child); + } } } @@ -610,7 +617,7 @@ export class TypeScriptLinter { ); if ( !throwExprType.isClassOrInterface() || - !this.tsUtils.isDerivedFrom(throwExprType, CheckType.Error) + !this.tsUtils.isOrDerivedFrom(throwExprType, this.tsUtils.isStdErrorType) ) { this.incrementCounters(node, FaultID.ThrowStatement, false, undefined); } @@ -668,18 +675,25 @@ export class TypeScriptLinter { } private handlePropertyAccessExpression(node: ts.Node) { + if (ts.isCallExpression(node.parent) && node == node.parent.expression) { + return; + } + let propertyAccessNode = node as ts.PropertyAccessExpression; const exprSym = this.tsUtils.trueSymbolAtLocation(propertyAccessNode); const baseExprSym = this.tsUtils.trueSymbolAtLocation(propertyAccessNode.expression); const baseExprType = this.tsTypeChecker.getTypeAtLocation(propertyAccessNode.expression); + if (this.isPrototypePropertyAccess(propertyAccessNode, exprSym, baseExprSym, baseExprType)) { + this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); + } + if (!!exprSym && this.tsUtils.isSymbolAPI(exprSym) && !TsUtils.ALLOWED_STD_SYMBOL_API.includes(exprSym.getName())) { + this.incrementCounters(propertyAccessNode, FaultID.SymbolType); + } if (!!baseExprSym && this.tsUtils.symbolHasEsObjectType(baseExprSym)) { this.incrementCounters(propertyAccessNode, FaultID.EsObjectType); } - if (this.isPrototypePropertyAccess(propertyAccessNode, exprSym, baseExprSym, baseExprType)) { - this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); - } } private handlePropertyAssignmentOrDeclaration(node: ts.Node) { @@ -693,20 +707,16 @@ export class TypeScriptLinter { ) { // We can use literals as property names only when creating Record or any interop instances. let isRecordObjectInitializer = false; - let isDynamicLiteralInitializer = false; + let isDynamic = false; if (ts.isPropertyAssignment(node)) { - let objectLiteralType = this.tsTypeChecker.getContextualType( - node.parent - ); - isRecordObjectInitializer = - !!objectLiteralType && - this.tsUtils.isStdRecordType(objectLiteralType); - isDynamicLiteralInitializer = this.tsUtils.isDynamicLiteralInitializer( - node.parent - ); + let objectLiteralType = this.tsTypeChecker.getContextualType(node.parent); + if (objectLiteralType) { + isRecordObjectInitializer = this.tsUtils.isStdRecordType(objectLiteralType); + isDynamic = this.tsUtils.isLibraryType(objectLiteralType) || this.tsUtils.isDynamicLiteralInitializer(node.parent); + } } - if (!isRecordObjectInitializer && !isDynamicLiteralInitializer) { + if (!isRecordObjectInitializer && !isDynamic) { let autofix: Autofix[] | undefined = Autofixer.fixLiteralAsPropertyName(node); let autofixable = autofix != undefined; @@ -759,7 +769,7 @@ export class TypeScriptLinter { ts.isIdentifier(x.expression.expression) ) decoratorName = x.expression.expression.text; - + // special case for property of type CustomDialogController of the @CustomDialog-decorated class if (expectedDecorators.includes(TsUtils.NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS[0])) { return expectedDecorators.includes(decoratorName) && propType === 'CustomDialogController' @@ -1181,6 +1191,8 @@ export class TypeScriptLinter { ) { this.incrementCounters(node, FaultID.InstanceofUnsupported); } + } else if (tsBinaryExpr.operatorToken.kind === ts.SyntaxKind.InKeyword) { + this.incrementCounters(tsBinaryExpr.operatorToken, FaultID.InOperator); } else if (tsBinaryExpr.operatorToken.kind === ts.SyntaxKind.EqualsToken) { if (this.tsUtils.needToDeduceStructuralIdentity(leftOperandType, rightOperandType, tsRhsExpr)) { this.incrementCounters(tsBinaryExpr, FaultID.StructuralIdentity); @@ -1249,6 +1261,7 @@ export class TypeScriptLinter { if (node.initializer) { this.handleEsObjectAssignment(node, node.type, node.initializer); + return; } } @@ -1411,13 +1424,6 @@ export class TypeScriptLinter { ); } } - - if (tsImportClause.isTypeOnly) { - let autofix: Autofix[] | undefined; - if (this.autofixesInfo.shouldAutofix(node, FaultID.TypeOnlyImport)) - autofix = [Autofixer.dropTypeOnlyFlag(tsImportClause)]; - this.incrementCounters(node, FaultID.TypeOnlyImport, true, autofix); - } } private handleImportSpecifier(node: ts.Node) { @@ -1477,19 +1483,20 @@ export class TypeScriptLinter { } private handleIdentifier(node: ts.Node) { - let tsIdentifier = node as ts.Identifier; - let tsIdentSym = this.tsUtils.trueSymbolAtLocation(tsIdentifier); + const tsIdentifier = node as ts.Identifier; + const tsIdentSym = this.tsUtils.trueSymbolAtLocation(tsIdentifier); + if (!tsIdentSym) { return; } + if ( (tsIdentSym.flags & ts.SymbolFlags.Module) !== 0 && (tsIdentSym.flags & ts.SymbolFlags.Transient) !== 0 && - tsIdentifier.text === 'globalThis' + tsIdentifier.text === "globalThis" ) { - this.incrementCounters(tsIdentifier, FaultID.GlobalThis); + this.incrementCounters(node, FaultID.GlobalThis); } else { - this.checkLimitedStdLib(tsIdentifier, tsIdentSym); this.handleRestrictedValues(tsIdentifier, tsIdentSym); } } @@ -1508,7 +1515,9 @@ export class TypeScriptLinter { if (ts.isCallExpression(ctx.parent) || ts.isNewExpression(ctx.parent)) { let callee = ctx.parent.expression; - if (callee != ctx && this.tsUtils.hasLibraryType(callee)) { + const isAny = this.tsUtils.isAnyType(this.tsTypeChecker.getTypeAtLocation(callee)); + const isDynamic = isAny || this.tsUtils.hasLibraryType(callee); + if (callee != ctx && isDynamic) { return true; } } @@ -1559,8 +1568,7 @@ export class TypeScriptLinter { // treat TypeQuery as valid because it's already forbidden (FaultID.TypeQuery) (ts.isTypeNode(parent) && !ts.isTypeOfExpression(parent)) || // ElementAccess is allowed for enum types - (ts.isElementAccessExpression(parent) - && (parent as ts.ElementAccessExpression).expression == ident && (tsSym.flags & ts.SymbolFlags.Enum)) || + this.isEnumPropAccess(ident, tsSym, parent) || ts.isExpressionWithTypeArguments(parent) || ts.isExportAssignment(parent) || ts.isExportSpecifier(parent) || @@ -1584,44 +1592,34 @@ export class TypeScriptLinter { ); } + private isEnumPropAccess(ident: ts.Identifier, tsSym: ts.Symbol, context: ts.Node): boolean { + return ts.isElementAccessExpression(context) && !!(tsSym.flags & ts.SymbolFlags.Enum) && + (context.expression == ident || + (ts.isPropertyAccessExpression(context.expression) && context.expression.name == ident)); + } + private handleElementAccessExpression(node: ts.Node) { const tsElementAccessExpr = node as ts.ElementAccessExpression; - const tsElemAccessBaseExprType = this.tsTypeChecker.getTypeAtLocation( - tsElementAccessExpr.expression - ); + const tsElemAccessBaseExprType = this.tsUtils.getTypeOrTypeConstraintAtLocation(tsElementAccessExpr.expression); const tsElemAccessBaseExprTypeNode = this.tsTypeChecker.typeToTypeNode( tsElemAccessBaseExprType, undefined, ts.NodeBuilderFlags.None ); - const checkClassOrInterface = tsElemAccessBaseExprType.isClassOrInterface() && - !this.tsUtils.isGenericArrayType(tsElemAccessBaseExprType) && - !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); - const checkThisOrSuper = this.tsUtils.isThisOrSuperExpr(tsElementAccessExpr.expression) && - !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); - - // if (this.tsUtils.isEnumType(tsElemAccessBaseExprType)) { - // implement argument expression type check - // let argType = this.tsTypeChecker.getTypeAtLocation(tsElementAccessExpr.argumentExpression); - // if (argType.aliasSymbol == this.tsUtils.trueSymbolAtLocation(tsElementAccessExpr.expression)) { - // return; - // } - // check if constant EnumMember inferred ... - // this.incrementCounters(node, FaultID.PropertyAccessByIndex, autofixable, autofix); - // } if ( !this.tsUtils.isLibraryType(tsElemAccessBaseExprType) && - !this.tsUtils.isTypedArray(tsElemAccessBaseExprTypeNode) && - ( checkClassOrInterface || - this.tsUtils.isObjectLiteralType(tsElemAccessBaseExprType) || checkThisOrSuper) + !ts.isArrayLiteralExpression(tsElementAccessExpr.expression) && + !this.tsUtils.isOrDerivedFrom(tsElemAccessBaseExprType, this.tsUtils.isArray) && + !this.tsUtils.isOrDerivedFrom(tsElemAccessBaseExprType, this.tsUtils.isTuple) && + !this.tsUtils.isOrDerivedFrom(tsElemAccessBaseExprType, this.tsUtils.isStdRecordType) && + !this.tsUtils.isEnumType(tsElemAccessBaseExprType) && + !this.tsUtils.isEsObjectType(tsElemAccessBaseExprTypeNode) ) { let autofix = Autofixer.fixPropertyAccessByIndex(node); const autofixable = autofix != undefined; - if ( - !this.autofixesInfo.shouldAutofix(node, FaultID.PropertyAccessByIndex) - ) + if (!this.autofixesInfo.shouldAutofix(node, FaultID.PropertyAccessByIndex)) { autofix = undefined; - + } this.incrementCounters( node, FaultID.PropertyAccessByIndex, @@ -1673,16 +1671,6 @@ export class TypeScriptLinter { } } - private handleExportDeclaration(node: ts.Node) { - let tsExportDecl = node as ts.ExportDeclaration; - if (tsExportDecl.isTypeOnly) { - let autofix: Autofix[] | undefined; - if (this.autofixesInfo.shouldAutofix(node, FaultID.TypeOnlyExport)) - autofix = [Autofixer.dropTypeOnlyFlag(tsExportDecl)]; - this.incrementCounters(node, FaultID.TypeOnlyExport, true, autofix); - } - } - private handleExportAssignment(node: ts.Node) { const exportAssignment = node as ts.ExportAssignment; if (exportAssignment.isExportEquals) { @@ -1699,22 +1687,25 @@ export class TypeScriptLinter { this.handleImportCall(tsCallExpr); this.handleRequireCall(tsCallExpr); - if (!!calleeSym) { + // NOTE: Keep handleFunctionApplyBindPropCall above handleGenericCallWithNoTypeArgs here!!! + if (calleeSym !== undefined) { + this.handleStdlibAPICall(tsCallExpr, calleeSym); + this.handleFunctionApplyBindPropCall(tsCallExpr, calleeSym); if (this.tsUtils.symbolHasEsObjectType(calleeSym)) { this.incrementCounters(tsCallExpr, FaultID.EsObjectType); } - // need to process Symbol call separatey in order to not report two times when using Symbol API - if (this.tsUtils.isStdSymbol(calleeSym)) { - this.incrementCounters(tsCallExpr, FaultID.SymbolType); - } } - if (!!callSignature) { + if (callSignature !== undefined) { if (!this.tsUtils.isLibrarySymbol(calleeSym)) { this.handleGenericCallWithNoTypeArgs(tsCallExpr, callSignature); } this.handleStructIdentAndUndefinedInArgs(tsCallExpr, callSignature); } this.handleLibraryTypeCall(tsCallExpr, calleeType); + + if (ts.isPropertyAccessExpression(tsCallExpr.expression) && this.tsUtils.hasEsObjectType(tsCallExpr.expression.expression)) { + this.incrementCounters(node, FaultID.EsObjectType); + } } private handleImportCall(tsCallExpr: ts.CallExpression) { @@ -1784,6 +1775,22 @@ export class TypeScriptLinter { } } + + private static listApplyBindCallApis = [ + "Function.apply", + "Function.call", + "Function.bind", + "CallableFunction.apply", + "CallableFunction.call", + "CallableFunction.bind" + ]; + private handleFunctionApplyBindPropCall(tsCallExpr: ts.CallExpression, calleeSym: ts.Symbol) { + const exprName = this.tsTypeChecker.getFullyQualifiedName(calleeSym); + if (TypeScriptLinter.listApplyBindCallApis.includes(exprName)) { + this.incrementCounters(tsCallExpr, FaultID.FunctionApplyBindCall); + } + } + private handleStructIdentAndUndefinedInArgs(tsCallOrNewExpr: ts.CallExpression | ts.NewExpression, callSignature: ts.Signature) { if (!tsCallOrNewExpr.arguments) { return; @@ -1823,17 +1830,35 @@ export class TypeScriptLinter { } } - private checkLimitedStdLib(node: ts.Node, symbol: ts.Symbol) { - const parName = this.tsUtils.getParentSymbolName(symbol); - const res = parName ? TsUtils.LIMITED_STD_API.get(parName) : undefined; - if (res && res.arr.includes(symbol.name)) { - this.incrementCounters(node, res.fault); + + // let re = new RegExp("^(" + arr.reduce((acc, v) => ((acc ? (acc + "|") : "") + v)) +")$") + private static LimitedApis = new Map | null, fault: FaultID}> ([ + ["global", {arr: TsUtils.LIMITED_STD_GLOBAL_FUNC, fault: FaultID.LimitedStdLibApi}], + ["Object", {arr: TsUtils.LIMITED_STD_OBJECT_API, fault: FaultID.LimitedStdLibApi}], + ["ObjectConstructor", {arr: TsUtils.LIMITED_STD_OBJECT_API, fault: FaultID.LimitedStdLibApi}], + ["Reflect", {arr: TsUtils.LIMITED_STD_REFLECT_API, fault: FaultID.LimitedStdLibApi}], + ["ProxyHandler", {arr: TsUtils.LIMITED_STD_PROXYHANDLER_API, fault: FaultID.LimitedStdLibApi}], + ["Symbol", {arr: null, fault: FaultID.SymbolType}], + ["SymbolConstructor", {arr: null, fault: FaultID.SymbolType}], + ]) + + private handleStdlibAPICall(callExpr: ts.CallExpression, calleeSym: ts.Symbol) { + const name = calleeSym.getName(); + const parName = this.tsUtils.getParentSymbolName(calleeSym); + if (parName === undefined) { + if (TsUtils.LIMITED_STD_GLOBAL_FUNC.includes(name)) { + this.incrementCounters(callExpr, FaultID.LimitedStdLibApi); + return; + } + let escapedName = calleeSym.escapedName; + if (escapedName === 'Symbol' || escapedName === 'SymbolConstructor') { + this.incrementCounters(callExpr, FaultID.SymbolType); + } return; } - const name = this.tsTypeChecker.getFullyQualifiedName(symbol); - if (TsUtils.LIMITED_STD_GLOBAL_API.includes(name)) { - this.incrementCounters(node, FaultID.LimitedStdLibApi) - return; + let lookup = TypeScriptLinter.LimitedApis.get(parName); + if (lookup !== undefined && (lookup.arr === null || lookup.arr.includes(name))) { + this.incrementCounters(callExpr, lookup.fault); } } @@ -1861,24 +1886,24 @@ export class TypeScriptLinter { let rangesToFilter: { begin: number, end: number }[] = []; if (nonFilteringRanges.length !== 0) { let rangesSize = nonFilteringRanges.length; - rangesToFilter.push({ begin: callExpr.pos, end: nonFilteringRanges[0].begin }) - rangesToFilter.push({ begin: nonFilteringRanges[rangesSize - 1].end, end: callExpr.end }) + rangesToFilter.push({ begin: callExpr.arguments.pos, end: nonFilteringRanges[0].begin }) + rangesToFilter.push({ begin: nonFilteringRanges[rangesSize - 1].end, end: callExpr.arguments.end }) for (let i = 0; i < rangesSize - 1; i++) { rangesToFilter.push({ begin: nonFilteringRanges[i].end, end: nonFilteringRanges[i + 1].begin }) } } else { - rangesToFilter.push({ begin: callExpr.pos, end: callExpr.end }) + rangesToFilter.push({ begin: callExpr.arguments.pos, end: callExpr.arguments.end }) } this.filterStrictDiagnostics({ - [ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE]: (pos: number) => { - return this.checkInRange(rangesToFilter, pos); - }, - [TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE]: (pos: number) => { - return this.checkInRange(rangesToFilter, pos); - } + [ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE]: (pos: number) => { + return this.checkInRange(rangesToFilter, pos); }, - this.libraryTypeCallDiagnosticChecker + [TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE]: (pos: number) => { + return this.checkInRange(rangesToFilter, pos); + } + }, + this.libraryTypeCallDiagnosticChecker ); for (const msgChain of diagnosticMessages) { @@ -1924,7 +1949,6 @@ export class TypeScriptLinter { this.incrementCounters(node, FaultID.EsObjectType); return; } - const typeName = this.tsUtils.entityNameToString(typeRef.typeName); const isStdUtilityType = TsUtils.LIMITED_STANDARD_UTILITY_TYPES.includes(typeName); if (isStdUtilityType) { @@ -1966,21 +1990,8 @@ export class TypeScriptLinter { spreadElemNode.expression ); if (spreadExprType) { - const spreadExprTypeNode = this.tsTypeChecker.typeToTypeNode( - spreadExprType, - undefined, - ts.NodeBuilderFlags.None - ); - if ( - spreadExprTypeNode !== undefined && - (ts.isCallLikeExpression(node.parent) || - ts.isArrayLiteralExpression(node.parent)) - ) { - if ( - ts.isArrayTypeNode(spreadExprTypeNode) || - this.tsUtils.isTypedArray(spreadExprTypeNode) || - this.tsUtils.isDerivedFrom(spreadExprType, CheckType.Array) - ) { + if (ts.isCallLikeExpression(node.parent) || ts.isArrayLiteralExpression(node.parent)) { + if (this.tsUtils.isOrDerivedFrom(spreadExprType, this.tsUtils.isArray)) { return; } } @@ -2016,7 +2027,12 @@ export class TypeScriptLinter { ); if (leadingComments) { for (const comment of leadingComments) { - this.checkErrorSuppressingAnnotation(comment, srcText); + // In the real-time linter comment from the first line is double proccessed. + // It may be caused by tsc, but it should be investigated. This is a workaround + if (!this.walkedComments.has(comment.pos) && comment.pos !== comment.end) { + this.walkedComments.add(comment.pos); + this.checkErrorSuppressingAnnotation(comment, srcText); + } } } } @@ -2028,20 +2044,34 @@ export class TypeScriptLinter { ); if (trailingComments) { for (const comment of trailingComments) { - this.checkErrorSuppressingAnnotation(comment, srcText); + // In the real-time linter comment from the first line is double proccessed. + // It may be caused by tsc, but it should be investigated. This is a workaround + if (!this.walkedComments.has(comment.pos) && comment.pos !== comment.end) { + this.walkedComments.add(comment.pos); + this.checkErrorSuppressingAnnotation(comment, srcText); + } } } } } private handleExpressionWithTypeArguments(node: ts.Node) { - let tsTypeExpr = node as ts.ExpressionWithTypeArguments; - let symbol = this.tsUtils.trueSymbolAtLocation(tsTypeExpr.expression); + const tsTypeExpr = node as ts.ExpressionWithTypeArguments; + const symbol = this.tsUtils.trueSymbolAtLocation(tsTypeExpr.expression); if (!!symbol && this.tsUtils.isEsObjectSymbol(symbol)) { this.incrementCounters(tsTypeExpr, FaultID.EsObjectType); } } + private handleComputedPropertyName(node: ts.Node) { + const computedProperty = node as ts.ComputedPropertyName; + const symbol = this.tsUtils.trueSymbolAtLocation(computedProperty.expression); + if (!!symbol && this.tsUtils.isSymbolIterator(symbol)) { + return + } + this.incrementCounters(node, FaultID.ComputedPropertyName); + } + private checkErrorSuppressingAnnotation( comment: ts.CommentRange, srcText: string @@ -2050,7 +2080,9 @@ export class TypeScriptLinter { comment.kind === ts.SyntaxKind.MultiLineCommentTrivia ? srcText.slice(comment.pos + 2, comment.end - 2) : srcText.slice(comment.pos + 2, comment.end); - + // if comment is multiline end closing '*/' is not at the same line as '@ts-xxx' - do nothing (see #13851) + if (commentContent.endsWith('\n')) + return; let trimmedContent = commentContent.trim(); if ( trimmedContent.startsWith("@ts-ignore") || @@ -2174,9 +2206,7 @@ export class TypeScriptLinter { if (type.aliasSymbol != undefined) { return; } - const isObject = type.flags & ts.TypeFlags.Object; - const isReference = (type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference; - if (isObject && isReference) { + if (this.tsUtils.isObjectType(type) && !!(type.objectFlags & ts.ObjectFlags.Reference)) { this.handleInferredObjectreference(type, decl); return; } @@ -2197,6 +2227,7 @@ export class TypeScriptLinter { } public lint(sourceFile: ts.SourceFile) { + this.walkedComments.clear(); this.sourceFile = sourceFile; this.visitTSNode(this.sourceFile); } diff --git a/linter-4.2/src/TypeScriptLinterConfig.ts b/linter-4.2/src/TypeScriptLinterConfig.ts index 1639e5664f9758c32dc413580caf9e94ec5956d9..f549a87180081804dd9b25fc775af05d968b7b11 100644 --- a/linter-4.2/src/TypeScriptLinterConfig.ts +++ b/linter-4.2/src/TypeScriptLinterConfig.ts @@ -92,8 +92,6 @@ export class LinterConfig { LinterConfig.nodeDesc[FaultID.ThisType] = '"this" type'; LinterConfig.nodeDesc[FaultID.IntefaceExtendDifProps] = 'Extends same properties with different types'; LinterConfig.nodeDesc[FaultID.StructuralIdentity] = 'Use of type structural identity'; - LinterConfig.nodeDesc[FaultID.TypeOnlyImport] = 'Type-only imports'; - LinterConfig.nodeDesc[FaultID.TypeOnlyExport] = 'Type-only exports'; LinterConfig.nodeDesc[FaultID.DefaultImport] = 'Default import declarations'; LinterConfig.nodeDesc[FaultID.ExportAssignment] = 'Export assignments (export = ..)'; LinterConfig.nodeDesc[FaultID.ImportAssignment] = 'Import assignments (import = ..)'; @@ -166,14 +164,13 @@ export class LinterConfig { static incrementOnlyTokens: Map = new Map([ [ts.SyntaxKind.AnyKeyword, FaultID.AnyType], [ts.SyntaxKind.SymbolKeyword, FaultID.SymbolType], [ts.SyntaxKind.ThisType, FaultID.ThisType], - [ts.SyntaxKind.ComputedPropertyName, FaultID.ComputedPropertyName], [ts.SyntaxKind.TypeQuery, FaultID.TypeQuery], [ts.SyntaxKind.DeleteExpression, FaultID.DeleteOperator], [ts.SyntaxKind.RegularExpressionLiteral, FaultID.RegexLiteral], [ts.SyntaxKind.TypePredicate, FaultID.IsOperator], [ts.SyntaxKind.YieldExpression, FaultID.YieldExpression], [ts.SyntaxKind.IndexSignature, FaultID.IndexMember], [ts.SyntaxKind.WithStatement, FaultID.WithStatement], [ts.SyntaxKind.IndexedAccessType, FaultID.IndexedAccessType],[ts.SyntaxKind.UnknownKeyword, FaultID.UnknownType], - [ts.SyntaxKind.InKeyword, FaultID.InOperator], [ts.SyntaxKind.CallSignature, FaultID.CallSignature], + [ts.SyntaxKind.CallSignature, FaultID.CallSignature], [ts.SyntaxKind.IntersectionType, FaultID.IntersectionType], [ts.SyntaxKind.TypeLiteral, FaultID.ObjectTypeLiteral], [ts.SyntaxKind.ConstructorType, FaultID.ConstructorFuncs], [ts.SyntaxKind.PrivateIdentifier, FaultID.PrivateIdentifier], diff --git a/linter-4.2/src/Utils.ts b/linter-4.2/src/Utils.ts index 03674b19e96459a3e9915e7d392180fe2561becc..c2f32b89a37d00409d77cf95485f2d7db085366a 100644 --- a/linter-4.2/src/Utils.ts +++ b/linter-4.2/src/Utils.ts @@ -18,7 +18,6 @@ import * as ts from 'typescript'; import { ProblemInfo } from './ProblemInfo'; import { AutofixInfo } from './AutofixInfo'; import { LinterConfig } from './TypeScriptLinterConfig' -import { FaultID } from "./Problems"; export function logTscDiagnostic(diagnostics: readonly ts.Diagnostic[], log: (message: any, ...args: any[]) => void) { diagnostics.forEach((diagnostic) => { @@ -95,135 +94,30 @@ export function isAssignmentOperator(tsBinOp: ts.BinaryOperatorToken): boolean { return tsBinOp.kind >= ts.SyntaxKind.FirstAssignment && tsBinOp.kind <= ts.SyntaxKind.LastAssignment; } -export enum CheckType { - Array, - String = "String", - Set = "Set", - Map = "Map", - Error = "Error", -}; +export type CheckType = ((t: ts.Type) => boolean); export class TsUtils { static readonly ES_OBJECT = 'ESObject' - private static readonly LIMITED_STD_ARRAYBUFFER_API = [ - // properties - // methods - 'isView' + static readonly LIMITED_STD_GLOBAL_FUNC = [ + 'eval' ]; - - private static readonly LIMITED_STD_OBJECT_API = [ - // properties - '__proto__', - // methods - '__defineGetter__', - '__defineSetter__', - '__lookupGetter__', - '__lookupSetter__', - 'assign', - 'create', - 'defineProperties', - 'defineProperty', - 'freeze', - 'fromEntries', - 'getOwnPropertyDescriptor', - 'getOwnPropertyDescriptors', - 'getOwnPropertySymbols', - 'getPrototypeOf', - 'hasOwnProperty', - 'is', - 'isExtensible', - 'isFrozen', - 'isPrototypeOf', - 'isSealed', - 'preventExtensions', - 'propertyIsEnumerable', - 'seal', - 'setPrototypeOf', - ]; - - private static readonly LIMITED_STD_PROXYHANDLER_API = [ - // properties - // methods - 'apply', - 'construct', - 'defineProperty', - 'deleteProperty', - 'get', - 'getOwnPropertyDescriptor', - 'getPrototypeOf', - 'has', - 'isExtensible', - 'ownKeys', - 'preventExtensions', - 'set', - 'setPrototypeOf' - ]; - - private static readonly LIMITED_STD_REFLECT_API = [ - // properties - // methods - 'apply', - 'construct', - 'defineProperty', - 'deleteProperty', - 'getOwnPropertyDescriptor', - 'getPrototypeOf', - 'isExtensible', - 'preventExtensions', - 'setPrototypeOf', - ]; - - private static readonly LIMITED_STD_SYMBOL_API = [ - 'Symbol', - // properties - 'asyncIterator', - 'description', - 'hasInstance', - 'isConcatSpreadable', - 'match', - 'matchAll', - 'replace', - 'search', - 'species', - 'split', - 'toPrimitive', - 'toStringTag', - 'unscopables', - // methods - 'for', - 'keyFor', - 'toString', - 'valueOf', + static readonly LIMITED_STD_OBJECT_API = [ + '__proto__', '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'assign', 'create', + 'defineProperties', 'defineProperty', 'freeze', 'fromEntries', 'getOwnPropertyDescriptor', + 'getOwnPropertyDescriptors', 'getOwnPropertySymbols', 'getPrototypeOf', 'hasOwnProperty', 'is', + 'isExtensible', 'isFrozen', 'isPrototypeOf', 'isSealed', 'preventExtensions', 'propertyIsEnumerable', + 'seal', 'setPrototypeOf' ]; - - private static readonly LIMITED_STD_FUNCTION_API = [ - // properties - // methods - 'apply', - 'bind', - 'call', + static readonly LIMITED_STD_REFLECT_API = [ + 'apply', 'construct', 'defineProperty', 'deleteProperty', 'getOwnPropertyDescriptor', 'getPrototypeOf', + 'isExtensible', 'preventExtensions', 'setPrototypeOf' ]; - - static readonly LIMITED_STD_GLOBAL_API = [ - // properties - // methods - 'eval', + static readonly LIMITED_STD_PROXYHANDLER_API = [ + 'apply', 'construct', 'defineProperty', 'deleteProperty', 'get', 'getOwnPropertyDescriptor', 'getPrototypeOf', + 'has', 'isExtensible', 'ownKeys', 'preventExtensions', 'set', 'setPrototypeOf' ]; - static readonly LIMITED_STD_API = new Map, fault: FaultID}> ([ - ['Object', {arr: TsUtils.LIMITED_STD_OBJECT_API, fault: FaultID.LimitedStdLibApi}], - ['ObjectConstructor', {arr: TsUtils.LIMITED_STD_OBJECT_API, fault: FaultID.LimitedStdLibApi}], - ['Reflect', {arr: TsUtils.LIMITED_STD_REFLECT_API, fault: FaultID.LimitedStdLibApi}], - ['ProxyHandler', {arr: TsUtils.LIMITED_STD_PROXYHANDLER_API, fault: FaultID.LimitedStdLibApi}], - ['ArrayBuffer', {arr: TsUtils.LIMITED_STD_ARRAYBUFFER_API, fault: FaultID.LimitedStdLibApi}], - ['ArrayBufferConstructor', {arr: TsUtils.LIMITED_STD_ARRAYBUFFER_API, fault: FaultID.LimitedStdLibApi}], - ['Symbol', {arr: TsUtils.LIMITED_STD_SYMBOL_API, fault: FaultID.SymbolType}], - ['SymbolConstructor', {arr: TsUtils.LIMITED_STD_SYMBOL_API, fault: FaultID.SymbolType}], - ['Function', {arr: TsUtils.LIMITED_STD_FUNCTION_API, fault: FaultID.FunctionApplyBindCall}], - ['CallableFunction', {arr: TsUtils.LIMITED_STD_FUNCTION_API, fault: FaultID.FunctionApplyBindCall}], - ]) - static readonly NON_INITIALIZABLE_PROPERTY_DECORATORS = ['Link', 'Consume', 'ObjectLink', 'Prop', 'BuilderParam']; static readonly NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS = ['CustomDialog'] @@ -240,6 +134,8 @@ export class TsUtils { 'ThisType', 'Uppercase', 'Lowercase', 'Capitalize', 'Uncapitalize', ]; + static readonly ALLOWED_STD_SYMBOL_API = ['iterator'] + static readonly ARKUI_DECORATORS = [ 'AnimatableExtend', 'Builder', @@ -303,13 +199,6 @@ export class TsUtils { constructor(private tsTypeChecker: ts.TypeChecker, private testMode: boolean) { } - public isTypedArray(tsType: ts.TypeNode | undefined): boolean { - if (tsType === undefined || !ts.isTypeReferenceNode(tsType)) { - return false; - } - return TsUtils.TYPED_ARRAYS.includes(this.entityNameToString(tsType.typeName)); - } - public isType(tsType: ts.TypeNode | undefined, checkType: string): boolean { if (tsType === undefined || !ts.isTypeReferenceNode(tsType)) { return false; @@ -549,24 +438,48 @@ export class TsUtils { ); } + public isTypedArray(tsType: ts.Type): boolean { + const symbol = tsType.symbol; + if (!symbol) { + return false; + } + const name = this.tsTypeChecker.getFullyQualifiedName(symbol); + return this.isGlobalSymbol(symbol) && TsUtils.TYPED_ARRAYS.includes(name); + } + + public isArray(tsType: ts.Type): boolean { + return this.isGenericArrayType(tsType) || this.isTypedArray(tsType); + } + + public isTuple(tsType: ts.Type): boolean { + return this.isTypeReference(tsType) && !!(tsType.objectFlags & ts.ObjectFlags.Tuple); + } + // does something similar to relatedByInheritanceOrIdentical function - public isDerivedFrom(tsType: ts.Type, checkType: CheckType): tsType is ts.TypeReference { - if (this.isTypeReference(tsType) && tsType.target !== tsType) tsType = tsType.target; + public isOrDerivedFrom(tsType: ts.Type, checkType: CheckType): tsType is ts.TypeReference { + if (this.isTypeReference(tsType) && tsType.target !== tsType) { + tsType = tsType.target; + } - const tsTypeNode = this.tsTypeChecker.typeToTypeNode(tsType, undefined, ts.NodeBuilderFlags.None); - if (checkType == CheckType.Array && (this.isGenericArrayType(tsType) || this.isTypedArray(tsTypeNode))) + if (checkType.call(this, tsType)) { return true; - if (checkType != CheckType.Array && this.isType(tsTypeNode, checkType.toString())) - return true; - if (!tsType.symbol || !tsType.symbol.declarations) return false; + } - for (let tsTypeDecl of tsType.symbol.declarations) { - if ( - (!ts.isClassDeclaration(tsTypeDecl) && !ts.isInterfaceDeclaration(tsTypeDecl)) || - !tsTypeDecl.heritageClauses - ) continue; + if (!tsType.symbol || !tsType.symbol.declarations) { + return false; + } + + for (const tsTypeDecl of tsType.symbol.declarations) { + if (!ts.isClassDeclaration(tsTypeDecl) && !ts.isInterfaceDeclaration(tsTypeDecl)) { + continue; + } + if (!tsTypeDecl.heritageClauses) { + continue; + } for (let heritageClause of tsTypeDecl.heritageClauses) { - if (this.processParentTypesCheck(heritageClause.types, checkType)) return true; + if (this.processParentTypesCheck(heritageClause.types, checkType)) { + return true; + } } } @@ -869,10 +782,14 @@ export class TsUtils { } private processParentTypesCheck(parentTypes: ts.NodeArray, checkType: CheckType): boolean { - for (let baseTypeExpr of parentTypes) { + for (const baseTypeExpr of parentTypes) { let baseType = this.tsTypeChecker.getTypeAtLocation(baseTypeExpr); - if (this.isTypeReference(baseType) && baseType.target !== baseType) baseType = baseType.target; - if (baseType && this.isDerivedFrom(baseType, checkType)) return true; + if (this.isTypeReference(baseType) && baseType.target !== baseType) { + baseType = baseType.target; + } + if (baseType && this.isOrDerivedFrom(baseType, checkType)) { + return true; + } } return false; } @@ -1194,39 +1111,18 @@ export class TsUtils { return !parentName || parentName === 'global'; } - public isStdObjectAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'Object'); - } - - public isStdReflectAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'Reflect'); - } - - public isStdProxyHandlerAPI(symbol: ts.Symbol): boolean { + public isSymbolAPI(symbol: ts.Symbol): boolean { let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'ProxyHandler'); - } - - public isStdArrayAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'Array'); - } - - public isStdArrayBufferAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'ArrayBuffer'); + return !!parentName && (parentName === 'Symbol' || parentName === 'SymbolConstructor'); } public isStdSymbol(symbol: ts.Symbol): boolean { const name = this.tsTypeChecker.getFullyQualifiedName(symbol) - return name === 'Symbol'; + return name === 'Symbol' && this.isGlobalSymbol(symbol); } - public isStdSymbolAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && parentName === 'Symbol'; + public isSymbolIterator(symbol: ts.Symbol): boolean { + return this.isSymbolAPI(symbol) && symbol.name === 'iterator' } public isDefaultImport(importSpec: ts.ImportSpecifier): boolean { @@ -1260,6 +1156,15 @@ export class TsUtils { return false; } + public isStdErrorType(type: ts.Type): boolean { + const symbol = type.symbol; + if (!symbol) { + return false; + } + const name = this.tsTypeChecker.getFullyQualifiedName(symbol); + return name === 'Error' && this.isGlobalSymbol(symbol); + } + public isStdPartialType(type: ts.Type): boolean { const sym = type.aliasSymbol; return !!sym && sym.getName() === 'Partial' && this.isGlobalSymbol(sym); @@ -1310,11 +1215,11 @@ export class TsUtils { const isEts = (ext === '.ets'); const isTs = (ext === '.ts' && !srcFile.isDeclarationFile); const isStatic = (isEts || (isTs && this.testMode)) && !isThirdPartyCode; + const isStdLib = TsUtils.STANDARD_LIBRARIES.includes(path.basename(fileName).toLowerCase()); // We still need to confirm support for certain API from the // TypeScript standard library in ArkTS. Thus, for now do not // count standard library modules. - return !isStatic && - !TsUtils.STANDARD_LIBRARIES.includes(path.basename(srcFile.fileName).toLowerCase()); + return !isStatic && !isStdLib; } return false; @@ -1472,8 +1377,8 @@ export class TsUtils { return false; } - public isEsObjectType(typeNode: ts.TypeNode): boolean { - return ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName) && + public isEsObjectType(typeNode: ts.TypeNode | undefined): boolean { + return !!typeNode && ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName) && typeNode.typeName.text == TsUtils.ES_OBJECT; } @@ -1614,4 +1519,15 @@ export class TsUtils { visitNode(funcExpr); return found; } + + public getTypeOrTypeConstraintAtLocation(expr: ts.Expression): ts.Type { + let type = this.tsTypeChecker.getTypeAtLocation(expr); + if (type.isTypeParameter()) { + let constraint = type.getConstraint(); + if (constraint) { + return constraint; + } + } + return type; + } } diff --git a/linter-4.2/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts b/linter-4.2/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts index 0d5106dd9f116531b356ca406fc9f4fff8ef053a..89380f130488617551e54b2f6f080d120b104535 100644 --- a/linter-4.2/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts +++ b/linter-4.2/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts @@ -25,7 +25,7 @@ export class TypeScriptDiagnosticsExtractor { public getStrictDiagnostics(fileName: string): ts.Diagnostic[] { // applying filter is a workaround for tsc bug const strict = getAllDiagnostics(this.strictProgram, fileName) - .filter(diag => !(diag.length === 0 && diag.start === 0)); + .filter(diag => !(diag.length === 0 && diag.start === 0)); const nonStrict = getAllDiagnostics(this.nonStrictProgram, fileName); // collect hashes for later easier comparison diff --git a/linter-4.2/test/ambient_module.ts.relax.json b/linter-4.2/test/ambient_module.ts.relax.json index a02ca7fc8935464e83947500d0dfc1e6558752dd..543d0a12ae515b61dfce8f85cf2bb8a33b955d0f 100644 --- a/linter-4.2/test/ambient_module.ts.relax.json +++ b/linter-4.2/test/ambient_module.ts.relax.json @@ -26,7 +26,7 @@ "column": 3, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 20, @@ -47,7 +47,7 @@ "column": 3, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 25, diff --git a/linter-4.2/test/ambient_module.ts.strict.json b/linter-4.2/test/ambient_module.ts.strict.json index a02ca7fc8935464e83947500d0dfc1e6558752dd..543d0a12ae515b61dfce8f85cf2bb8a33b955d0f 100644 --- a/linter-4.2/test/ambient_module.ts.strict.json +++ b/linter-4.2/test/ambient_module.ts.strict.json @@ -26,7 +26,7 @@ "column": 3, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 20, @@ -47,7 +47,7 @@ "column": 3, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 25, diff --git a/linter-4.2/test/class_as_object.ts b/linter-4.2/test/class_as_object.ts index 302432975cbb76c7c446fa410aad9b6220153f5d..195c076eca476d678de2b42436dfc076ab07f54b 100644 --- a/linter-4.2/test/class_as_object.ts +++ b/linter-4.2/test/class_as_object.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { Something, SomethingFactory, SomethingBar, Bar } from "./oh_modules/ohos_factory"; +import { Something, SomethingFactory, SomethingBar, Bar, Select } from "./oh_modules/ohos_factory"; class C { static a = 5; @@ -91,3 +91,28 @@ for (let item = 0; item < Object.keys(Color).length; item++) { foo2(() => C); export { C as H }; + +// #14228 +let data = new Select().from(C).eq('key').query(C); // Ok +invalid_func(C); // Ok +let a: any; +a.foo(C); // Ok + +let col = 'WHITE'; +console.log(Color[col]) + +// #14184 +namespace NS { + export enum E { + A = 'A', + B = 'B', + C = 'C' + } +} + +let s: string = 'B'; +let s2: string = NS.E[s]; + +for (let item = 0; item < Object.keys(NS.E).length; item++) { + console.log(item); +} \ No newline at end of file diff --git a/linter-4.2/test/class_as_object.ts.relax.json b/linter-4.2/test/class_as_object.ts.relax.json index fbae23bf5543a366a545d54810c03be11b97a304..87b0d7889dcea4ea46095d741c38bf3a6555c40e 100644 --- a/linter-4.2/test/class_as_object.ts.relax.json +++ b/linter-4.2/test/class_as_object.ts.relax.json @@ -15,72 +15,121 @@ { "line": 27, "column": 9, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 28, "column": 5, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 29, "column": 11, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 30, "column": 7, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 38, "column": 20, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 39, "column": 6, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 42, "column": 10, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 45, "column": 20, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 46, "column": 8, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 49, "column": 12, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 58, "column": 20, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 60, "column": 7, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 87, "column": 39, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 91, "column": 12, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + }, + { + "line": 96, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 98, + "column": 8, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 116, + "column": 42, + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" } ] } \ No newline at end of file diff --git a/linter-4.2/test/class_as_object.ts.strict.json b/linter-4.2/test/class_as_object.ts.strict.json index fbae23bf5543a366a545d54810c03be11b97a304..87b0d7889dcea4ea46095d741c38bf3a6555c40e 100644 --- a/linter-4.2/test/class_as_object.ts.strict.json +++ b/linter-4.2/test/class_as_object.ts.strict.json @@ -15,72 +15,121 @@ { "line": 27, "column": 9, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 28, "column": 5, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 29, "column": 11, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 30, "column": 7, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 38, "column": 20, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 39, "column": 6, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 42, "column": 10, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 45, "column": 20, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 46, "column": 8, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 49, "column": 12, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 58, "column": 20, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 60, "column": 7, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 87, "column": 39, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 91, "column": 12, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + }, + { + "line": 96, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 98, + "column": 8, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 116, + "column": 42, + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" } ] } \ No newline at end of file diff --git a/linter-4.2/test/dynamic_lib.d.ts b/linter-4.2/test/dynamic_lib.d.ts index e3da589b5418ec259aa310a41fea0f454f17ede3..843931397eaf4c1fce6ff89f458826d49642771c 100644 --- a/linter-4.2/test/dynamic_lib.d.ts +++ b/linter-4.2/test/dynamic_lib.d.ts @@ -93,3 +93,7 @@ declare class B { } export declare function bad_func(): A & B; + +export type IndexedSignatureType = { + [key: string]: string; +} \ No newline at end of file diff --git a/linter-4.2/test/dynamic_object_literals.ts b/linter-4.2/test/dynamic_object_literals.ts index ea7f9759a2e8cf76d1eb0dd81536959bfcf1beeb..fae9413ea1d4ccb581327bddbdda25cb9c805912 100644 --- a/linter-4.2/test/dynamic_object_literals.ts +++ b/linter-4.2/test/dynamic_object_literals.ts @@ -24,7 +24,8 @@ import { dynamic_array, padding, margin, - position + position, + IndexedSignatureType } from "./dynamic_lib" function main(): void { @@ -84,4 +85,13 @@ dynamic_array.splice(2, 0, {a: 1, b: '2'}); // #13550 - allow literals as property names in dynamic context padding({'top': '0px', 'right': '5px', 'bottom': '10px', 'left': '15px'}); margin({'top': '10px', 'right': '20px', 'bottom': '30px', 'left': '40px'}); -position({'x': '20', 'y': '40'}); \ No newline at end of file +position({'x': '20', 'y': '40'}); + +// allow literal as property name for type aliases that come from interop +function typeAliasLitAsPropName(): IndexedSignatureType { + return { + 'a': '1', + 'b': '2', + 'c': '3' + } +} \ No newline at end of file diff --git a/linter-4.2/test/es_object.ts b/linter-4.2/test/es_object.ts index 445b5c0c07e1db8eb18c4006d860e3476659f6ae..8b62f20f81b12743f1c4fb4aa2025ee6c99cd454 100644 --- a/linter-4.2/test/es_object.ts +++ b/linter-4.2/test/es_object.ts @@ -145,7 +145,7 @@ foo4([2, 3]) foo5([2, 3]) foo4(["str1", "str2"]) foo5(["str1", "str2"]) -let n = new ESObject[0] +let n: ESObject; n = null foo4(n) diff --git a/linter-4.2/test/es_object.ts.relax.json b/linter-4.2/test/es_object.ts.relax.json index f3d5acdb48589622baa499e265b74a732fa003f6..5bab1a3eee7a781b35c0996be116badfe9617820 100644 --- a/linter-4.2/test/es_object.ts.relax.json +++ b/linter-4.2/test/es_object.ts.relax.json @@ -26,231 +26,231 @@ "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 21, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 22, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 25, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 26, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 27, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 21, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 35, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 53, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 60, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 63, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 63, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 65, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 60, @@ -271,175 +271,175 @@ "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 64, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 64, "column": 50, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 66, "column": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 67, "column": 17, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 70, "column": 13, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 71, "column": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 77, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 78, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 79, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 80, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 82, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 83, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 85, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 86, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 87, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 88, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 90, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 91, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 93, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 94, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 95, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 96, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 98, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 99, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 103, @@ -453,28 +453,28 @@ "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 106, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 108, "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 109, "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 114, @@ -488,105 +488,112 @@ "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 119, "column": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 119, "column": 36, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 136, "column": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 136, "column": 38, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 148, "column": 5, - "problem": "AnyType", + "problem": "EsObjectType", "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + }, + { + "line": 149, + "column": 1, + "problem": "EsObjectType", + "suggest": "", + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 45, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 47, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 60, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 170, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 172, "column": 22, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 174, "column": 30, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 176, @@ -600,21 +607,21 @@ "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 178, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 179, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 181, @@ -628,49 +635,49 @@ "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 183, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 184, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 185, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 188, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 189, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 190, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" } ] } \ No newline at end of file diff --git a/linter-4.2/test/es_object.ts.strict.json b/linter-4.2/test/es_object.ts.strict.json index 5c869e41f36b202e2f7537f9bfa7a312c7073b8a..c0ef7ba377f3807ea65571da92fd87b60f274619 100644 --- a/linter-4.2/test/es_object.ts.strict.json +++ b/linter-4.2/test/es_object.ts.strict.json @@ -26,231 +26,231 @@ "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 21, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 22, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 25, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 26, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 27, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 21, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 35, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 53, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 60, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 63, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 63, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 65, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 60, @@ -271,175 +271,182 @@ "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 64, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 64, "column": 50, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 66, "column": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 67, "column": 17, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 70, "column": 13, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 71, "column": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 77, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 78, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + }, + { + "line": 79, + "column": 5, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" }, { "line": 79, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 80, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 82, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 83, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 85, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 86, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 87, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 88, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 90, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 91, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 93, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 94, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 95, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 96, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 98, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 99, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 103, @@ -453,28 +460,28 @@ "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 106, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 108, "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 109, "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 114, @@ -488,105 +495,112 @@ "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 119, "column": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 119, "column": 36, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 136, "column": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 136, "column": 38, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 148, "column": 5, - "problem": "AnyType", + "problem": "EsObjectType", "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + }, + { + "line": 149, + "column": 1, + "problem": "EsObjectType", + "suggest": "", + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 45, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 47, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 60, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 170, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 172, "column": 22, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 174, "column": 30, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 176, @@ -600,21 +614,21 @@ "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 178, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 179, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 181, @@ -628,49 +642,63 @@ "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 183, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 184, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 185, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + }, + { + "line": 188, + "column": 5, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" }, { "line": 188, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + }, + { + "line": 189, + "column": 5, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" }, { "line": 189, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 190, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" } ] } \ No newline at end of file diff --git a/linter-4.2/test/function_expression.ts.autofix.json b/linter-4.2/test/function_expression.ts.autofix.json index 90e6f3f3b1843e1b27a91717ae8ec47ced32aeaa..e005781ad91e4c1a3c375d88874c9f64811e06bb 100644 --- a/linter-4.2/test/function_expression.ts.autofix.json +++ b/linter-4.2/test/function_expression.ts.autofix.json @@ -267,6 +267,14 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 82, + "column": 19, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, { "line": 82, "column": 19, @@ -335,6 +343,14 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 102, + "column": 15, + "problem": "FunctionApplyBindCall", + "autofixable": false, + "suggest": "", + "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" + }, { "line": 102, "column": 15, @@ -350,14 +366,6 @@ "suggest": "", "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" }, - { - "line": 104, - "column": 7, - "problem": "FunctionApplyBindCall", - "autofixable": false, - "suggest": "", - "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" - }, { "line": 108, "column": 16, diff --git a/linter-4.2/test/function_expression.ts.relax.json b/linter-4.2/test/function_expression.ts.relax.json index 8e60772364f880a2b1734887f006e79ab0075cdd..48f6e1a27f9cde8a9f97bd009fcf972843b37619 100644 --- a/linter-4.2/test/function_expression.ts.relax.json +++ b/linter-4.2/test/function_expression.ts.relax.json @@ -57,8 +57,8 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { - "line": 104, - "column": 7, + "line": 102, + "column": 15, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" diff --git a/linter-4.2/test/function_expression.ts.strict.json b/linter-4.2/test/function_expression.ts.strict.json index 1233c4e7db472396252e3157aac380db56d8e583..48723e4cddfa69f67dde850ebe2d3b944276fb9e 100644 --- a/linter-4.2/test/function_expression.ts.strict.json +++ b/linter-4.2/test/function_expression.ts.strict.json @@ -168,6 +168,13 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 82, + "column": 19, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, { "line": 82, "column": 19, @@ -206,16 +213,16 @@ { "line": 102, "column": 15, - "problem": "FunctionExpression", + "problem": "FunctionApplyBindCall", "suggest": "", - "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" + "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { - "line": 104, - "column": 7, - "problem": "FunctionApplyBindCall", + "line": 102, + "column": 15, + "problem": "FunctionExpression", "suggest": "", - "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" }, { "line": 108, diff --git a/linter-4.2/test/function_object_methods.ts.relax.json b/linter-4.2/test/function_object_methods.ts.relax.json index 790856d4f7ac64e42723ba8be5a20b7ae18f32a2..96e3fcaf15c33d5b989eb091c20e1961ab3994b9 100644 --- a/linter-4.2/test/function_object_methods.ts.relax.json +++ b/linter-4.2/test/function_object_methods.ts.relax.json @@ -23,7 +23,7 @@ }, { "line": 29, - "column": 35, + "column": 21, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -37,21 +37,21 @@ }, { "line": 30, - "column": 45, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 37, - "column": 37, + "column": 23, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 38, - "column": 40, + "column": 21, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -65,7 +65,7 @@ }, { "line": 68, - "column": 44, + "column": 22, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -79,42 +79,42 @@ }, { "line": 70, - "column": 35, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 75, - "column": 48, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 78, - "column": 48, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 81, - "column": 31, + "column": 9, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 82, - "column": 31, + "column": 9, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 87, - "column": 32, + "column": 16, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -128,7 +128,7 @@ }, { "line": 94, - "column": 37, + "column": 20, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -142,42 +142,42 @@ }, { "line": 96, - "column": 30, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 101, - "column": 42, + "column": 25, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 104, - "column": 42, + "column": 25, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 107, - "column": 20, + "column": 3, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 108, - "column": 20, + "column": 3, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 113, - "column": 21, + "column": 10, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -226,35 +226,35 @@ }, { "line": 136, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 137, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 138, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 139, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 141, - "column": 5, + "column": 1, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" diff --git a/linter-4.2/test/function_object_methods.ts.strict.json b/linter-4.2/test/function_object_methods.ts.strict.json index 2a7c8ccd943aded4391752c20d2e26ecc66b4c29..e90572ea9fa1ff6f639076c45d74320d7d9469d6 100644 --- a/linter-4.2/test/function_object_methods.ts.strict.json +++ b/linter-4.2/test/function_object_methods.ts.strict.json @@ -23,7 +23,7 @@ }, { "line": 29, - "column": 35, + "column": 21, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -37,21 +37,21 @@ }, { "line": 30, - "column": 45, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 37, - "column": 37, + "column": 23, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 38, - "column": 40, + "column": 21, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -65,7 +65,7 @@ }, { "line": 68, - "column": 44, + "column": 22, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -79,42 +79,42 @@ }, { "line": 70, - "column": 35, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 75, - "column": 48, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 78, - "column": 48, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 81, - "column": 31, + "column": 9, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 82, - "column": 31, + "column": 9, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 87, - "column": 32, + "column": 16, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -128,7 +128,7 @@ }, { "line": 94, - "column": 37, + "column": 20, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -142,42 +142,42 @@ }, { "line": 96, - "column": 30, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 101, - "column": 42, + "column": 25, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 104, - "column": 42, + "column": 25, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 107, - "column": 20, + "column": 3, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 108, - "column": 20, + "column": 3, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 113, - "column": 21, + "column": 10, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -254,35 +254,35 @@ }, { "line": 136, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 137, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 138, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 139, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 141, - "column": 5, + "column": 1, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" diff --git a/linter-4.2/test/functions.ts b/linter-4.2/test/functions.ts index 8d67f99ff3292a00005ed662c0798ca5ab08801e..fd8646324ae5cec720ba4c189a8dfdac408f85ff 100644 --- a/linter-4.2/test/functions.ts +++ b/linter-4.2/test/functions.ts @@ -105,4 +105,23 @@ bar(() => { bar(() => { f(null); }, null, f(null)); -}, null, foo(f(null))); \ No newline at end of file +}, null, foo(f(null))); + +type PropDecorator = () => void; +let Builder: PropDecorator; + +// this test is useless until we use custom tsc +@Builder +function buildSwiper() { + f(null) + foo(null) { + f(null) + foo(null) { + f(null) + foo(() => { + f(null) + }) + } + .foo(null) + } +} diff --git a/linter-4.2/test/functions.ts.autofix.json b/linter-4.2/test/functions.ts.autofix.json index bdec3c538a0a38afa2968f452019ea0cc98ccffe..944c5bf6b00aa3659df8313054492cb1ea47856f 100644 --- a/linter-4.2/test/functions.ts.autofix.json +++ b/linter-4.2/test/functions.ts.autofix.json @@ -157,6 +157,38 @@ "autofixable": false, "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 116, + "column": 5, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 118, + "column": 7, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 120, + "column": 11, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 122, + "column": 11, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." } ] } \ No newline at end of file diff --git a/linter-4.2/test/functions.ts.relax.json b/linter-4.2/test/functions.ts.relax.json index e11f7f9c4b4ba8fd83a515d2609ee21e3b7f6c08..1e86ab2f19832ca9bf8a34ad0e3cf11cea54bb8e 100644 --- a/linter-4.2/test/functions.ts.relax.json +++ b/linter-4.2/test/functions.ts.relax.json @@ -125,6 +125,34 @@ "problem": "StrictDiagnostic", "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 116, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 118, + "column": 7, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 120, + "column": 11, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 122, + "column": 11, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." } ] } \ No newline at end of file diff --git a/linter-4.2/test/functions.ts.strict.json b/linter-4.2/test/functions.ts.strict.json index d39199ff0024aa2f8a01d89ad214a4e3c83e8212..a1c2214e52d001dfb28b51cd6867ddd774c91cdb 100644 --- a/linter-4.2/test/functions.ts.strict.json +++ b/linter-4.2/test/functions.ts.strict.json @@ -139,6 +139,34 @@ "problem": "StrictDiagnostic", "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 116, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 118, + "column": 7, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 120, + "column": 11, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 122, + "column": 11, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." } ] } \ No newline at end of file diff --git a/linter-4.2/test/limited_stdlib_api.ts b/linter-4.2/test/limited_stdlib_api.ts index 0cc445fe759022f5cd6bcd7850aa3f018cf33849..918ecda770245ba60c156d10007ee46572f40e45 100644 --- a/linter-4.2/test/limited_stdlib_api.ts +++ b/linter-4.2/test/limited_stdlib_api.ts @@ -28,7 +28,7 @@ decodeURIComponent(''); escape(''); unescape(''); -// global and window are not portabe, so they are excluded from test suite +global.eval('console.log("foo")'); globalThis.eval('console.log("foo")'); class C {} @@ -90,10 +90,4 @@ if (handler.set) handler.set(c, "prop", 1, c); if (handler.setPrototypeOf) handler.setPrototypeOf(c, null); /// Array -ArrayBuffer.isView({}); - -Number.NaN; -Number.isFinite(1); -Number.isNaN(2); -Number.parseFloat('3'); -Number.parseInt('4', 10); +ArrayBuffer.isView({}); \ No newline at end of file diff --git a/linter-4.2/test/limited_stdlib_api.ts.autofix.json b/linter-4.2/test/limited_stdlib_api.ts.autofix.json index 6286f4c5d0b3ddb032dd27a3d39d87bfee9170f9..eb0a98815448f5fa65bb3aae2c053f8697d69296 100644 --- a/linter-4.2/test/limited_stdlib_api.ts.autofix.json +++ b/linter-4.2/test/limited_stdlib_api.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 17, @@ -9,24 +23,32 @@ "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { - "line": 32, + "line": 31, "column": 1, - "problem": "GlobalThis", + "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", - "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 32, - "column": 12, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, + { + "line": 32, + "column": 1, + "problem": "GlobalThis", + "autofixable": false, + "suggest": "", + "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + }, { "line": 43, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -34,7 +56,7 @@ }, { "line": 44, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -42,7 +64,7 @@ }, { "line": 45, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -58,7 +80,7 @@ }, { "line": 46, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -66,7 +88,7 @@ }, { "line": 48, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -74,7 +96,7 @@ }, { "line": 49, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -82,7 +104,7 @@ }, { "line": 50, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -90,7 +112,7 @@ }, { "line": 51, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -98,7 +120,7 @@ }, { "line": 52, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -106,7 +128,7 @@ }, { "line": 53, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -114,7 +136,7 @@ }, { "line": 54, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -122,7 +144,7 @@ }, { "line": 55, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -130,7 +152,7 @@ }, { "line": 56, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -138,7 +160,7 @@ }, { "line": 57, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -146,7 +168,7 @@ }, { "line": 58, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -154,7 +176,7 @@ }, { "line": 59, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -162,7 +184,7 @@ }, { "line": 60, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -170,7 +192,7 @@ }, { "line": 61, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -178,7 +200,7 @@ }, { "line": 62, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -186,7 +208,7 @@ }, { "line": 63, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -194,7 +216,7 @@ }, { "line": 66, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -202,7 +224,7 @@ }, { "line": 67, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -218,7 +240,7 @@ }, { "line": 68, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -234,7 +256,7 @@ }, { "line": 69, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -242,7 +264,7 @@ }, { "line": 70, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -250,7 +272,7 @@ }, { "line": 71, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -258,7 +280,7 @@ }, { "line": 72, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -266,7 +288,7 @@ }, { "line": 73, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -274,7 +296,7 @@ }, { "line": 74, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -290,15 +312,7 @@ }, { "line": 78, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 78, - "column": 28, + "column": 20, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -306,15 +320,7 @@ }, { "line": 79, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 79, - "column": 32, + "column": 24, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -322,15 +328,7 @@ }, { "line": 80, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 80, - "column": 37, + "column": 29, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -346,15 +344,7 @@ }, { "line": 81, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 81, - "column": 37, + "column": 29, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -362,23 +352,7 @@ }, { "line": 82, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 82, - "column": 26, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 83, - "column": 13, + "column": 18, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -386,15 +360,7 @@ }, { "line": 83, - "column": 47, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 84, - "column": 13, + "column": 39, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -402,15 +368,7 @@ }, { "line": 84, - "column": 37, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 85, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -418,15 +376,7 @@ }, { "line": 85, - "column": 26, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 86, - "column": 13, + "column": 18, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -434,7 +384,7 @@ }, { "line": 86, - "column": 35, + "column": 27, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -442,23 +392,7 @@ }, { "line": 87, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 87, - "column": 30, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 88, - "column": 13, + "column": 22, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -466,15 +400,7 @@ }, { "line": 88, - "column": 40, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 89, - "column": 13, + "column": 32, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -482,7 +408,7 @@ }, { "line": 89, - "column": 26, + "column": 18, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -490,23 +416,7 @@ }, { "line": 90, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 90, - "column": 37, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 93, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", diff --git a/linter-4.2/test/limited_stdlib_api.ts.relax.json b/linter-4.2/test/limited_stdlib_api.ts.relax.json index 7f5db9e71c7cb9e6dfc0b80057cfd409ad490712..2e0b7e73690290d2698de6e85687986aa11d15cf 100644 --- a/linter-4.2/test/limited_stdlib_api.ts.relax.json +++ b/linter-4.2/test/limited_stdlib_api.ts.relax.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 17, @@ -8,36 +22,43 @@ "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { - "line": 32, + "line": 31, "column": 1, - "problem": "GlobalThis", + "problem": "LimitedStdLibApi", "suggest": "", - "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 32, - "column": 12, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, + { + "line": 32, + "column": 1, + "problem": "GlobalThis", + "suggest": "", + "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + }, { "line": 43, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 44, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 45, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -51,133 +72,133 @@ }, { "line": 46, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 48, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 49, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 50, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 51, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 52, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 53, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 54, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 55, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 56, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 57, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 58, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 59, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 60, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 61, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 62, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 63, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 66, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 67, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -191,7 +212,7 @@ }, { "line": 68, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -205,42 +226,42 @@ }, { "line": 69, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 70, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 71, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 72, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 73, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 74, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -254,42 +275,21 @@ }, { "line": 78, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 78, - "column": 28, + "column": 20, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 79, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 79, - "column": 32, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 80, - "column": 13, + "column": 24, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 80, - "column": 37, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -303,147 +303,70 @@ }, { "line": 81, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 81, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 82, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 82, - "column": 26, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 83, - "column": 13, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 83, - "column": 47, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 84, - "column": 13, + "column": 39, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 84, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 85, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 85, - "column": 26, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 86, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 86, - "column": 35, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 87, - "column": 13, + "column": 27, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 87, - "column": 30, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 88, - "column": 13, + "column": 22, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 88, - "column": 40, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 89, - "column": 13, + "column": 32, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 89, - "column": 26, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 90, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 90, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 93, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" diff --git a/linter-4.2/test/limited_stdlib_api.ts.strict.json b/linter-4.2/test/limited_stdlib_api.ts.strict.json index 7f5db9e71c7cb9e6dfc0b80057cfd409ad490712..2e0b7e73690290d2698de6e85687986aa11d15cf 100644 --- a/linter-4.2/test/limited_stdlib_api.ts.strict.json +++ b/linter-4.2/test/limited_stdlib_api.ts.strict.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 17, @@ -8,36 +22,43 @@ "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { - "line": 32, + "line": 31, "column": 1, - "problem": "GlobalThis", + "problem": "LimitedStdLibApi", "suggest": "", - "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 32, - "column": 12, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, + { + "line": 32, + "column": 1, + "problem": "GlobalThis", + "suggest": "", + "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + }, { "line": 43, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 44, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 45, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -51,133 +72,133 @@ }, { "line": 46, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 48, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 49, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 50, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 51, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 52, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 53, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 54, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 55, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 56, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 57, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 58, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 59, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 60, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 61, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 62, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 63, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 66, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 67, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -191,7 +212,7 @@ }, { "line": 68, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -205,42 +226,42 @@ }, { "line": 69, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 70, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 71, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 72, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 73, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 74, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -254,42 +275,21 @@ }, { "line": 78, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 78, - "column": 28, + "column": 20, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 79, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 79, - "column": 32, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 80, - "column": 13, + "column": 24, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 80, - "column": 37, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -303,147 +303,70 @@ }, { "line": 81, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 81, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 82, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 82, - "column": 26, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 83, - "column": 13, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 83, - "column": 47, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 84, - "column": 13, + "column": 39, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 84, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 85, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 85, - "column": 26, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 86, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 86, - "column": 35, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 87, - "column": 13, + "column": 27, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 87, - "column": 30, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 88, - "column": 13, + "column": 22, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 88, - "column": 40, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 89, - "column": 13, + "column": 32, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 89, - "column": 26, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 90, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 90, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 93, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" diff --git a/linter-4.2/test/modules.ts.autofix.json b/linter-4.2/test/modules.ts.autofix.json index 567b9a523a2bc47149edca0b119738a94115535a..476aed0b64742d7aba1b026823c41bba6d4f7cb9 100644 --- a/linter-4.2/test/modules.ts.autofix.json +++ b/linter-4.2/test/modules.ts.autofix.json @@ -111,51 +111,12 @@ "problem": "ImportAfterStatement", "autofixable": false }, - { - "line": 92, - "column": 8, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 1923, - "end": 1947, - "replacementText": "{ APIResponseType }" - } - ] - }, { "line": 93, "column": 1, "problem": "ImportAfterStatement", "autofixable": false }, - { - "line": 93, - "column": 8, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 1969, - "end": 1980, - "replacementText": "* as P" - } - ] - }, - { - "line": 96, - "column": 1, - "problem": "TypeOnlyExport", - "autofixable": true, - "autofix": [ - { - "start": 2014, - "end": 2045, - "replacementText": "export { TypeA as TypeB };" - } - ] - }, { "line": 104, "column": 1, diff --git a/linter-4.2/test/modules.ts.strict.json b/linter-4.2/test/modules.ts.strict.json index 9481d07d8d642c6b8d190fbe9ae603a826ac99a8..88de583880c7d9279cda15172273567053297ae4 100644 --- a/linter-4.2/test/modules.ts.strict.json +++ b/linter-4.2/test/modules.ts.strict.json @@ -89,26 +89,11 @@ "column": 1, "problem": "ImportAfterStatement" }, - { - "line": 92, - "column": 8, - "problem": "TypeOnlyImport" - }, { "line": 93, "column": 1, "problem": "ImportAfterStatement" }, - { - "line": 93, - "column": 8, - "problem": "TypeOnlyImport" - }, - { - "line": 96, - "column": 1, - "problem": "TypeOnlyExport" - }, { "line": 104, "column": 1, diff --git a/linter-4.2/test/new_target.ts.relax.json b/linter-4.2/test/new_target.ts.relax.json index 0b83a11983237ced2f41aa64eaaeb370019ee51f..5ec99daa29eeeccfa7c6b5bdcdcefea2f5999fe5 100644 --- a/linter-4.2/test/new_target.ts.relax.json +++ b/linter-4.2/test/new_target.ts.relax.json @@ -16,7 +16,7 @@ "nodes": [ { "line": 19, - "column": 12, + "column": 5, "problem": "LimitedStdLibApi" }, { diff --git a/linter-4.2/test/new_target.ts.strict.json b/linter-4.2/test/new_target.ts.strict.json index 0b83a11983237ced2f41aa64eaaeb370019ee51f..5ec99daa29eeeccfa7c6b5bdcdcefea2f5999fe5 100644 --- a/linter-4.2/test/new_target.ts.strict.json +++ b/linter-4.2/test/new_target.ts.strict.json @@ -16,7 +16,7 @@ "nodes": [ { "line": 19, - "column": 12, + "column": 5, "problem": "LimitedStdLibApi" }, { diff --git a/linter-4.2/test/oh_modules/ohos_factory.ts b/linter-4.2/test/oh_modules/ohos_factory.ts index e26c4c911ba886e1d930a38404f9a87434d454b3..b4fc3d2d2fe025f7deb68faa0cf3374beece71ee 100644 --- a/linter-4.2/test/oh_modules/ohos_factory.ts +++ b/linter-4.2/test/oh_modules/ohos_factory.ts @@ -16,3 +16,18 @@ export declare class SomethingBar extends Something { } export declare class Bar { constructor(arg: { new(): T }); } + +export class Select { + public from(cls: any) { + return this; + } + + // we intentionally omit generic argument of 'Select', see #14228 + public eq(name: string): Select { + return this; + } + + public query(cls: any): Promise { + return cls.foo(); + } +} \ No newline at end of file diff --git a/linter-4.2/test/property_access_by_index.ts b/linter-4.2/test/property_access_by_index.ts new file mode 100644 index 0000000000000000000000000000000000000000..407d7055373017e1d207c0ad4cc5de563ef21474 --- /dev/null +++ b/linter-4.2/test/property_access_by_index.ts @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// #14071 +class A { + v: string = ''; +} +function SetProperty(oldObj: T, str: string, obj: Object): void { + oldObj[str] = obj; // Should report error +} +function GetProperty(oldObj: T, str: string): U { + return oldObj[str]; // Should report error +} +function test() { + let a: A = { v: 'abc' }; + SetProperty(a, 'u', 'def'); + return GetProperty(a, 'v') + GetProperty(a, 'u'); +} + +let ar1 = [1, 2, 3, 4]; +let ar2 = [1, '2', 3, 4]; +let ar3: number[] = []; + +ar1[2]; +ar2[2]; +ar3[2]; + +const r0 = [1, 2, 3][1]; +let r1 = [1, 2, 3, 4][0] +let r2 = [1, '2', 3, 4][0] + +function fobject1(o: object) { + o['j'] +} + +function fobject2(o: Object) { + o['k'] +} + +let array1 = [0,1] +let array2 = [1,2,3,4,5] +let array3: number[] = [1,2,3,4,5] +let array4: Array = [1,2,3,4,5] +let array5 = new Array(10) +let array6 = new Int8Array(10) +let array7 = new Uint8Array(10) +let array8 = new Uint8ClampedArray(10) +let array9 = new Int16Array(10) +let array10 = new Uint16Array(10) +let array11 = new Int32Array(10) +let array12 = new Uint32Array(10) +let array13 = new Float32Array(10) +let array14 = new Float64Array(10) +let array15 = new BigInt64Array(10) +let array16 = new BigUint64Array(10) + +array1[0]; +array2[0]; +array3[0]; +array4[0]; +array5[0]; +array6[0]; +array7[0]; +array8[0]; +array9[0]; +array10[0]; +array11[0]; +array12[0]; +array13[0]; +array14[0]; +array15[0]; +array16[0]; + +function fff1(r: Record) { + r['bob'] +} + +enum CCCCCCCCC { + KATE, + BOB, + ROB, +} + +CCCCCCCCC['KATE'] +CCCCCCCCC['BOB'] +CCCCCCCCC['ROB'] + +CCCCCCCCC[CCCCCCCCC.KATE] +CCCCCCCCC[CCCCCCCCC.BOB] +CCCCCCCCC[CCCCCCCCC.ROB] diff --git a/linter-4.2/test/property_access_by_index.ts.autofix.json b/linter-4.2/test/property_access_by_index.ts.autofix.json new file mode 100644 index 0000000000000000000000000000000000000000..2c4552959c61360287bfced911da4678778738ff --- /dev/null +++ b/linter-4.2/test/property_access_by_index.ts.autofix.json @@ -0,0 +1,58 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 21, + "column": 3, + "problem": "PropertyAccessByIndex", + "autofixable": false, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 24, + "column": 10, + "problem": "PropertyAccessByIndex", + "autofixable": false, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 45, + "column": 3, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 49, + "column": 3, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 56, + "column": 5, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test/property_access_by_index.ts.relax.json b/linter-4.2/test/property_access_by_index.ts.relax.json new file mode 100644 index 0000000000000000000000000000000000000000..6cefe023006258af8a68d625b2b8f2bfeb0ce012 --- /dev/null +++ b/linter-4.2/test/property_access_by_index.ts.relax.json @@ -0,0 +1,25 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 56, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test/property_access_by_index.ts.strict.json b/linter-4.2/test/property_access_by_index.ts.strict.json new file mode 100644 index 0000000000000000000000000000000000000000..6bb2b04001484dde5785ebd81b090e9afcee138f --- /dev/null +++ b/linter-4.2/test/property_access_by_index.ts.strict.json @@ -0,0 +1,53 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 21, + "column": 3, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 24, + "column": 10, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 45, + "column": 3, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 49, + "column": 3, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 56, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test/symbol_api.ts b/linter-4.2/test/symbol_api.ts index 2d33c448f2d46c9150ee43b838b41f7dc5d98a37..8d7d25d3e16a892137741335ce918d61bd964a59 100644 --- a/linter-4.2/test/symbol_api.ts +++ b/linter-4.2/test/symbol_api.ts @@ -50,3 +50,9 @@ class TestClass { return Symbol(); } } + +class BIter { + [Symbol.iterator] = () => { + return 1; + }; +} diff --git a/linter-4.2/test/symbol_api.ts.relax.json b/linter-4.2/test/symbol_api.ts.relax.json index e62c8c7b772eb72b7c1c2e435f564313f0be758a..c2211cf10708b2fa141fd797dc845a3553c2e98a 100644 --- a/linter-4.2/test/symbol_api.ts.relax.json +++ b/linter-4.2/test/symbol_api.ts.relax.json @@ -16,77 +16,77 @@ "nodes": [ { "line": 16, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 17, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 18, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 20, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 21, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 22, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 23, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 24, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 25, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 26, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 27, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" @@ -107,7 +107,7 @@ }, { "line": 33, - "column": 17, + "column": 10, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" diff --git a/linter-4.2/test/symbol_api.ts.strict.json b/linter-4.2/test/symbol_api.ts.strict.json index e62c8c7b772eb72b7c1c2e435f564313f0be758a..c2211cf10708b2fa141fd797dc845a3553c2e98a 100644 --- a/linter-4.2/test/symbol_api.ts.strict.json +++ b/linter-4.2/test/symbol_api.ts.strict.json @@ -16,77 +16,77 @@ "nodes": [ { "line": 16, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 17, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 18, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 20, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 21, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 22, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 23, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 24, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 25, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 26, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 27, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" @@ -107,7 +107,7 @@ }, { "line": 33, - "column": 17, + "column": 10, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" diff --git a/linter-4.2/test/ts_ignore.ts.relax.json b/linter-4.2/test/ts_ignore.ts.relax.json index d1f5176718b5277f4744fd1d2237f1bec3ddae0e..8e4a16c18b27647b34afc96b9bce3cc271f48477 100644 --- a/linter-4.2/test/ts_ignore.ts.relax.json +++ b/linter-4.2/test/ts_ignore.ts.relax.json @@ -17,62 +17,86 @@ { "line": 16, "column": 1, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 21, "column": 3, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 25, "column": 19, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 30, "column": 9, - "problem": "ErrorSuppression" - }, - { - "line": 33, - "column": 2, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 43, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 52, "column": 3, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 53, "column": 3, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 55, "column": 22, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 56, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 58, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" + }, + { + "line": 75, + "column": 1, + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 18, "column": 5, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Type 'null' is not assignable to type 'number'.", + "rule": "Type 'null' is not assignable to type 'number'." } ] -} +} \ No newline at end of file diff --git a/linter-4.2/test/ts_ignore.ts.strict.json b/linter-4.2/test/ts_ignore.ts.strict.json index d1f5176718b5277f4744fd1d2237f1bec3ddae0e..8e4a16c18b27647b34afc96b9bce3cc271f48477 100644 --- a/linter-4.2/test/ts_ignore.ts.strict.json +++ b/linter-4.2/test/ts_ignore.ts.strict.json @@ -17,62 +17,86 @@ { "line": 16, "column": 1, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 21, "column": 3, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 25, "column": 19, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 30, "column": 9, - "problem": "ErrorSuppression" - }, - { - "line": 33, - "column": 2, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 43, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 52, "column": 3, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 53, "column": 3, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 55, "column": 22, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 56, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 58, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" + }, + { + "line": 75, + "column": 1, + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 18, "column": 5, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Type 'null' is not assignable to type 'number'.", + "rule": "Type 'null' is not assignable to type 'number'." } ] -} +} \ No newline at end of file diff --git a/linter-4.2/test/types.ts.autofix.json b/linter-4.2/test/types.ts.autofix.json index 7833b9da06c47271168dc5b463b35b669eed9910..3263fe4927404003fa9338dcc7806eb519432e2c 100644 --- a/linter-4.2/test/types.ts.autofix.json +++ b/linter-4.2/test/types.ts.autofix.json @@ -214,6 +214,14 @@ "suggest": "", "rule": "\"in\" operator is not supported (arkts-no-in)" }, + { + "line": 78, + "column": 5, + "problem": "PropertyAccessByIndex", + "autofixable": false, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, { "line": 92, "column": 22, diff --git a/linter-4.2/test/types.ts.strict.json b/linter-4.2/test/types.ts.strict.json index 12af0241f0080993d1207515856d070dd647e821..50971119921dde92707a4fc5e30b91fe2d2fa2ee 100644 --- a/linter-4.2/test/types.ts.strict.json +++ b/linter-4.2/test/types.ts.strict.json @@ -189,6 +189,13 @@ "suggest": "", "rule": "\"in\" operator is not supported (arkts-no-in)" }, + { + "line": 78, + "column": 5, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, { "line": 92, "column": 22, diff --git a/linter-4.2/test/utility_types.ts.relax.json b/linter-4.2/test/utility_types.ts.relax.json index fe6131546f4334735729e5e3c1ab931d44572443..63a56e5cd84e9305c8c9235b62a945faa1f8a75f 100644 --- a/linter-4.2/test/utility_types.ts.relax.json +++ b/linter-4.2/test/utility_types.ts.relax.json @@ -266,7 +266,7 @@ }, { "line": 178, - "column": 18, + "column": 12, "problem": "FunctionApplyBindCall" }, { @@ -286,7 +286,7 @@ }, { "line": 187, - "column": 60, + "column": 54, "problem": "FunctionApplyBindCall" }, { diff --git a/linter-4.2/test/utility_types.ts.strict.json b/linter-4.2/test/utility_types.ts.strict.json index c5686de4b4c5b53e4bfe52a623bec80e0c788296..cb2916b9d5d09ea06f98df2322cb84b2bf0d83ae 100644 --- a/linter-4.2/test/utility_types.ts.strict.json +++ b/linter-4.2/test/utility_types.ts.strict.json @@ -291,7 +291,7 @@ }, { "line": 178, - "column": 18, + "column": 12, "problem": "FunctionApplyBindCall" }, { @@ -316,7 +316,7 @@ }, { "line": 187, - "column": 60, + "column": 54, "problem": "FunctionApplyBindCall" }, { diff --git a/linter-4.2/test_rules/rule116.ts.autofix.json b/linter-4.2/test_rules/rule116.ts.autofix.json index 8449964f6b0aebed7a3a412a87e959afbcb33487..f3a5f41b3b987383c1f652c7373135cda5df7173 100644 --- a/linter-4.2/test_rules/rule116.ts.autofix.json +++ b/linter-4.2/test_rules/rule116.ts.autofix.json @@ -6,7 +6,7 @@ "problem": "NonDeclarationInNamespace", "autofixable": false, "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" } ] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule116.ts.relax.json b/linter-4.2/test_rules/rule116.ts.relax.json index a5030d64e8a3e5c962cfc25bcfc7d49e88e73a86..3259498ae75cd5e1f5d128bfeacd40f997681159 100644 --- a/linter-4.2/test_rules/rule116.ts.relax.json +++ b/linter-4.2/test_rules/rule116.ts.relax.json @@ -5,7 +5,7 @@ "column": 5, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" } ] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule116.ts.strict.json b/linter-4.2/test_rules/rule116.ts.strict.json index a5030d64e8a3e5c962cfc25bcfc7d49e88e73a86..3259498ae75cd5e1f5d128bfeacd40f997681159 100644 --- a/linter-4.2/test_rules/rule116.ts.strict.json +++ b/linter-4.2/test_rules/rule116.ts.strict.json @@ -5,7 +5,7 @@ "column": 5, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" } ] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule118.ts.autofix.json b/linter-4.2/test_rules/rule118.ts.autofix.json index 3ff68f6c73f0870b0af431b06348497a9bf6a784..13f13363f579325755e8954b4011963971667481 100644 --- a/linter-4.2/test_rules/rule118.ts.autofix.json +++ b/linter-4.2/test_rules/rule118.ts.autofix.json @@ -1,19 +1,3 @@ { - "nodes": [ - { - "line": 5, - "column": 12, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 120, - "end": 144, - "replacementText": "{ APIResponseType }" - } - ], - "suggest": "", - "rule": "Special import type declarations are not supported (arkts-no-special-imports)" - } - ] + "nodes": [] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule118.ts.strict.json b/linter-4.2/test_rules/rule118.ts.strict.json index d30836a74acd706fd8fe37f455f2cb38b9d30f96..13f13363f579325755e8954b4011963971667481 100644 --- a/linter-4.2/test_rules/rule118.ts.strict.json +++ b/linter-4.2/test_rules/rule118.ts.strict.json @@ -1,11 +1,3 @@ { - "nodes": [ - { - "line": 5, - "column": 12, - "problem": "TypeOnlyImport", - "suggest": "", - "rule": "Special import type declarations are not supported (arkts-no-special-imports)" - } - ] + "nodes": [] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule127.ts.autofix.json b/linter-4.2/test_rules/rule127.ts.autofix.json index c32c0f461dd55626cd83972b7aa2a8d7bff66f60..13f13363f579325755e8954b4011963971667481 100644 --- a/linter-4.2/test_rules/rule127.ts.autofix.json +++ b/linter-4.2/test_rules/rule127.ts.autofix.json @@ -1,19 +1,3 @@ { - "nodes": [ - { - "line": 12, - "column": 5, - "problem": "TypeOnlyExport", - "autofixable": true, - "autofix": [ - { - "start": 218, - "end": 240, - "replacementText": "export { Class2 };" - } - ], - "suggest": "", - "rule": "Special \"export type\" declarations are not supported (arkts-no-special-exports)" - } - ] + "nodes": [] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule127.ts.strict.json b/linter-4.2/test_rules/rule127.ts.strict.json index 35f1a58896b2262887e713eb7ea091a5342d8b98..13f13363f579325755e8954b4011963971667481 100644 --- a/linter-4.2/test_rules/rule127.ts.strict.json +++ b/linter-4.2/test_rules/rule127.ts.strict.json @@ -1,11 +1,3 @@ { - "nodes": [ - { - "line": 12, - "column": 5, - "problem": "TypeOnlyExport", - "suggest": "", - "rule": "Special \"export type\" declarations are not supported (arkts-no-special-exports)" - } - ] + "nodes": [] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule129.ts.autofix.json b/linter-4.2/test_rules/rule129.ts.autofix.json index 6708658aec6699b02802c0afa208ab7c076c39a4..80fc9c4b1fa0b7d2af2c6a19111f4c1a8102ef3d 100644 --- a/linter-4.2/test_rules/rule129.ts.autofix.json +++ b/linter-4.2/test_rules/rule129.ts.autofix.json @@ -6,7 +6,7 @@ "problem": "NonDeclarationInNamespace", "autofixable": false, "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 2, diff --git a/linter-4.2/test_rules/rule129.ts.relax.json b/linter-4.2/test_rules/rule129.ts.relax.json index cc882319377db9e73f996ceb24a77cc508180fdd..ab877e8e921e03d48ab1603fd2146e3f4fe9557f 100644 --- a/linter-4.2/test_rules/rule129.ts.relax.json +++ b/linter-4.2/test_rules/rule129.ts.relax.json @@ -5,7 +5,7 @@ "column": 9, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 2, diff --git a/linter-4.2/test_rules/rule129.ts.strict.json b/linter-4.2/test_rules/rule129.ts.strict.json index cc882319377db9e73f996ceb24a77cc508180fdd..ab877e8e921e03d48ab1603fd2146e3f4fe9557f 100644 --- a/linter-4.2/test_rules/rule129.ts.strict.json +++ b/linter-4.2/test_rules/rule129.ts.strict.json @@ -5,7 +5,7 @@ "column": 9, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 2, diff --git a/linter-4.2/test_rules/rule132.ts.autofix.json b/linter-4.2/test_rules/rule132.ts.autofix.json index d1868ca7f895576a790a872e83c05b3f7b619086..9002b4276ade0505b91332d17e0d7c64608c6e8f 100644 --- a/linter-4.2/test_rules/rule132.ts.autofix.json +++ b/linter-4.2/test_rules/rule132.ts.autofix.json @@ -2,7 +2,7 @@ "nodes": [ { "line": 7, - "column": 16, + "column": 9, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", diff --git a/linter-4.2/test_rules/rule132.ts.relax.json b/linter-4.2/test_rules/rule132.ts.relax.json index 21468ce90773221bb8d0e37917a8f9a5eb974223..192c3aa101f830da08961e07bd44fabed0c97d54 100644 --- a/linter-4.2/test_rules/rule132.ts.relax.json +++ b/linter-4.2/test_rules/rule132.ts.relax.json @@ -2,7 +2,7 @@ "nodes": [ { "line": 7, - "column": 16, + "column": 9, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" diff --git a/linter-4.2/test_rules/rule132.ts.strict.json b/linter-4.2/test_rules/rule132.ts.strict.json index 21468ce90773221bb8d0e37917a8f9a5eb974223..192c3aa101f830da08961e07bd44fabed0c97d54 100644 --- a/linter-4.2/test_rules/rule132.ts.strict.json +++ b/linter-4.2/test_rules/rule132.ts.strict.json @@ -2,7 +2,7 @@ "nodes": [ { "line": 7, - "column": 16, + "column": 9, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" diff --git a/linter/docs/rules/recipe118.md b/linter/docs/rules/recipe118.md deleted file mode 100644 index f625bc3e982353617c9dd28f7c6d67ff886e1e6d..0000000000000000000000000000000000000000 --- a/linter/docs/rules/recipe118.md +++ /dev/null @@ -1,39 +0,0 @@ -# Special import type declarations are not supported - -Rule ``arkts-no-special-imports`` - -**Severity: error** - -ArkTS does not have a special notation for importing types. -Use ordinary import instead. - - -## TypeScript - - -``` - - // Re-using the same import - import { APIResponseType } from "api" - - // Explicitly use import type - import type { APIResponseType } from "api" - -``` - -## ArkTS - - -``` - - import { APIResponseType } from "api" - -``` - -## See also - -- Recipe 119: Importing a module for side-effects only is not supported (``arkts-no-side-effects-imports``) -- Recipe 120: ``import default as ...`` is not supported (``arkts-no-import-default-as``) -- Recipe 121: ``require`` and ``import`` assignment are not supported (``arkts-no-require``) - - diff --git a/linter/docs/rules/recipe127.md b/linter/docs/rules/recipe127.md deleted file mode 100644 index c89d24fbac4b50b1e68937ea99e7e979ae8c1452..0000000000000000000000000000000000000000 --- a/linter/docs/rules/recipe127.md +++ /dev/null @@ -1,48 +0,0 @@ -# Special ``export type`` declarations are not supported - -Rule ``arkts-no-special-exports`` - -**Severity: error** - -ArkTS does not have a special notation for exporting types through -``export type ...``. Use ordinary export instead. - - -## TypeScript - - -``` - - // Explicitly exported class: - export class Class1 { - // ... - } - - // Declared class later exported through export type ... - class Class2 { - // ... - } - - // This is not supported: - export type { Class2 } - -``` - -## ArkTS - - -``` - - // Explicitly exported class: - export class Class1 { - // ... - } - - // Explicitly exported class: - export class Class2 { - // ... - } - -``` - - diff --git a/linter/docs/rules/recipe144.md b/linter/docs/rules/recipe144.md index 0bbcfefd413a1b7fc5b4e07cf9bb7d5487c669b7..371513d07946355b28a85f8bd976626c553e2f92 100644 --- a/linter/docs/rules/recipe144.md +++ b/linter/docs/rules/recipe144.md @@ -30,8 +30,6 @@ Properties and functions of the global object: ``eval`` ``handler.has()``, ``handler.isExtensible()``, ``handler.ownKeys()``, ``handler.preventExtensions()``, ``handler.set()``, ``handler.setPrototypeOf()`` -``ArrayBuffer``: ``isView`` - ## See also diff --git a/linter/docs/rules/recipe151.md b/linter/docs/rules/recipe151.md index 0b00ba64328b8da460cba56c63a6dd63fd050e23..2e7fd2d46a7c1a86d1c9ac02edd38945f5cfd0b1 100644 --- a/linter/docs/rules/recipe151.md +++ b/linter/docs/rules/recipe151.md @@ -1,17 +1,18 @@ # Usage of ``ESObject`` type is restricted -Rule ``arkts-limited-esobject`` +Rule ``arkts-limited-esobj`` **Severity: warning** -ArkTS does not allow using ``ESObject`` type in some cases. The most part of limitations -are put in place in order to prevent spread of dynamic objects in the static codebase. -The only scenario where it is permited to use ``ESObject`` as type specifier is in local -variable declaration. Initialization of variables with ``ESObject`` type is also limited. -Such variables can only be initialized with values that originate from interop: -other ``ESObject`` typed variables, any, unknown, variables with anonymous type, etc. -It is prohibited to initialize ``ESObject`` typed variable with statically typed value. -Varaible of type ``ESObject`` can only be passed to interop calls and assigned to other +ArkTS does not allow using ``ESObject`` type in some cases. The most part of +limitations are put in place in order to prevent spread of dynamic objects in +the static codebase. The only scenario where it is permited to use ``ESObject`` +as type specifier is in local variable declaration. Initialization of variables +with ``ESObject`` type is also limited. Such variables can only be initialized +with values that originate from interop: other ``ESObject`` typed variables, +any, unknown, variables with anonymous type, etc. It is prohibited to +initialize ``ESObject`` typed variable with statically typed value. Varaible +of type ``ESObject`` can only be passed to interop calls and assigned to other variables of type ``ESObject``. @@ -32,12 +33,13 @@ variables of type ``ESObject``. let e3: ESObject = {}; // CTE - can't initialize ESObject with not dynamic values let e4: ESObject = []; // CTE - can't initialize ESObject with not dynamic values let e5: ESObject = ""; // CTE - can't initialize ESObject with not dynamic values + e5['prop'] // CTE - can't access dynamic properties of ESObject + e5[1] // CTE - can't access dynamic properties of ESObject + e5.prop // CTE - can't access dynamic properties of ESObject + let e6: ESObject = foo(); // OK - explicitly annotaded as ESObject let e7 = e6; // OK - initialize ESObject with ESObject - e6['prop'] // CTE - can't access dynamic properties of ESObject - e6[1] // CTE - can't access dynamic properties of ESObject - e6.prop // CTE - can't access dynamic properties of ESObject - bar(e6) // OK - ESObject is passed to interop call + bar(e7) // OK - ESObject is passed to interop call } ``` @@ -51,4 +53,3 @@ variables of type ``ESObject``. - Recipe 066: ``in`` operator is not supported (``arkts-no-in``) - Recipe 137: ``globalThis`` is not supported (``arkts-no-globalthis``) - diff --git a/linter/docs/rules/recipe29.md b/linter/docs/rules/recipe29.md index c7be978d6962ce635842df26f13c20591f59b060..7af61c43e6cc5976617e17be86598978444d8ebe 100644 --- a/linter/docs/rules/recipe29.md +++ b/linter/docs/rules/recipe29.md @@ -10,9 +10,13 @@ that are either declared in the class, or accessible via inheritance. Accessing any other fields is prohibited, and causes compile-time errors. To access a field, use ``obj.field`` syntax, indexed access (``obj["field"]``) -is not supported. An exception are all typed arrays from the standard library -(for example, ``Int32Array``), which support access to their elements through -``container[index]`` syntax. +is not supported. An exception are: + +- All typed arrays from the standard library (for example, ``Int32Array``), which +support access to their elements through ``container[index]`` syntax. +- Tuples. +- Records. +- Enums. ## TypeScript diff --git a/linter/package.json b/linter/package.json index b9f16d7bfea4cd002a7886685cd4458a0a90d685..ec50eeb1a0799f37718000cb9a0b76dcfda269bf 100644 --- a/linter/package.json +++ b/linter/package.json @@ -11,7 +11,7 @@ "scripts": { "tsc": "tsc", "webpack": "webpack -t node --config webpack.config.js", - "clean": "rimraf build dist bundle", + "clean": "rimraf build dist bundle && gts clean", "compile": "npm run tsc", "build": "npm run clean && npm run compile && npm run webpack && npm run pack:linter", "postinstall": "npm run build", @@ -19,7 +19,10 @@ "test": "npm run compile && rimraf test/results test_rules/results && node build/src/TestRunner.js test test_rules", "test_main": "npm run compile && rimraf test/results && node build/src/TestRunner.js test", "test_rules": "npm run compile && rimraf test_rules/results && node build/src/TestRunner.js test_rules", - "update-tests": "node scripts/update-test-results.mjs test test_rules" + "update-tests": "node scripts/update-test-results.mjs test test_rules", + "lint": "gts lint", + "fix": "gts fix", + "pretest": "npm run lint" }, "dependencies": { "typescript": "4.8.4", @@ -36,7 +39,8 @@ "eslint": "7.32.0", "eslint-config-prettier": "^6.15.0", "eslint-plugin-prettier": "^3.1.4", - "prettier": "^2.0.5" + "prettier": "^2.0.5", + "gts": "^5.2.0" }, "bundledDependencies": [ "typescript", diff --git a/linter/scripts/update-test-results.mjs b/linter/scripts/update-test-results.mjs index dc579e42453a4416215504af7d0e3133221a4f33..45029c37eb3f2858d3a3848b5eebc2453598d268 100644 --- a/linter/scripts/update-test-results.mjs +++ b/linter/scripts/update-test-results.mjs @@ -37,7 +37,7 @@ const RESULTS_DIR = 'results' let testDirs = []; // forces to update all tests regardless of whether there was diff in a test result -const force_update = false; +let force_update = false; for (let arg of process.argv.slice(2)) { if (arg === '--force') @@ -72,33 +72,37 @@ function readTestFile(filePath) { function updateTest(testDir, testFile, mode) { let resultExt = RESULT_EXT[mode]; - let testFileWithExt = testFile + resultExt; + let resultFileWithExt = testFile + resultExt; + let resultFilePath = path.join(testDir, resultFileWithExt); // Do not update autofix result if test is skipped - if (mode === Mode.AUTOFIX && fs.existsSync(path.join(testDir, testFileWithExt + AUTOFIX_SKIP_EXT))) { + if (mode === Mode.AUTOFIX && fs.existsSync(path.join(testDir, testFile + AUTOFIX_SKIP_EXT))) { return; } - // Update test result when 'diff' exists or the 'force' option is enabled. - if (!fs.existsSync(path.join(testDir, RESULTS_DIR, testFileWithExt + DIFF_EXT)) && !force_update) { + // Update test result when: + // - '.diff' exists + // - expected '.json' doesn't exist + // - 'force' option is enabled + if (fs.existsSync(resultFilePath) && !fs.existsSync(path.join(testDir, RESULTS_DIR, resultFileWithExt + DIFF_EXT)) && !force_update) { return; } - let expectedResult = readTestFile(path.join(testDir, testFileWithExt)); + let expectedResult = readTestFile(resultFilePath); const copyright = expectedResult?.copyright ?? DEFAULT_COPYRIGHT; - let actualResult = readTestFile(path.join(testDir, RESULTS_DIR, testFileWithExt)); + let actualResult = readTestFile(path.join(testDir, RESULTS_DIR, resultFileWithExt)); if (!actualResult || !actualResult.nodes) { - console.log(`Failed to update ${testFileWithExt}: couldn't read ACTUAL result file.`); + console.log(`Failed to update ${resultFileWithExt}: couldn't read ACTUAL result file.`); return; } // Write file with actual test results. let newResultJSON = JSON.stringify({ copyright, nodes: actualResult.nodes }, null, 4); - fs.writeFileSync(path.join(testDir, testFileWithExt), newResultJSON); + fs.writeFileSync(resultFilePath, newResultJSON); - console.log(`Updated ${testFileWithExt}`); + console.log(`Updated ${resultFileWithExt}`); } for (let testDir of testDirs) { diff --git a/linter/src/Autofixer.ts b/linter/src/Autofixer.ts index 59c1cc2d36a1986ab0400c64cec971b706faaa36..7a9acaafe91ae79b08c082d370f27e5e504eaac5 100644 --- a/linter/src/Autofixer.ts +++ b/linter/src/Autofixer.ts @@ -15,19 +15,21 @@ import * as ts from 'typescript'; import { AutofixInfo } from './autofixes/AutofixInfo'; -import { FaultID } from './utils/consts/Problems'; +import { FaultID } from './Problems'; import { isAssignmentOperator } from './utils/functions/isAssignmentOperator'; export const AUTOFIX_ALL: AutofixInfo = { - problemID: '', start: -1, end: -1 -} + problemID: '', + start: -1, + end: -1, +}; // Some fixes are potentially risky and may break source code if fixes // are applied separately. // Temporary solution is to disable all risky autofixes, until the // algorithm is improved to guarantee that fixes can be applied // safely and won't break program code. -const UNSAFE_FIXES: FaultID[] = [ FaultID.LiteralAsPropertyName, FaultID.PropertyAccessByIndex ]; +const UNSAFE_FIXES: FaultID[] = [FaultID.LiteralAsPropertyName, FaultID.PropertyAccessByIndex]; export interface Autofix { replacementText: string; @@ -43,63 +45,108 @@ export class AutofixInfoSet { } public shouldAutofix(node: ts.Node, faultID: FaultID): boolean { - if (UNSAFE_FIXES.includes(faultID)) return false; - if (this.autofixInfo.length === 0) return false; - if (this.autofixInfo.length === 1 && this.autofixInfo[0] == AUTOFIX_ALL) return true; - return this.autofixInfo.findIndex( - value => value.start === node.getStart() && value.end === node.getEnd() && value.problemID === FaultID[faultID] - ) !== -1; + if (UNSAFE_FIXES.includes(faultID)) { + return false; + } + if (this.autofixInfo.length === 0) { + return false; + } + if (this.autofixInfo.length === 1 && this.autofixInfo[0] === AUTOFIX_ALL) { + return true; + } + return ( + this.autofixInfo.findIndex( + value => + value.start === node.getStart() && + value.end === node.getEnd() && + value.problemID === FaultID[faultID] + ) !== -1 + ); } } export function fixLiteralAsPropertyName(node: ts.Node): Autofix[] | undefined { if (ts.isPropertyDeclaration(node) || ts.isPropertyAssignment(node)) { - let propName = (node as (ts.PropertyDeclaration | ts.PropertyAssignment)).name; - let identName = propertyName2IdentifierName(propName); - if (identName) - return [{ replacementText: identName, start: propName.getStart(), end: propName.getEnd() }]; + const propName = (node as ts.PropertyDeclaration | ts.PropertyAssignment).name; + const identName = propertyName2IdentifierName(propName); + if (identName) { + return [ + { + replacementText: identName, + start: propName.getStart(), + end: propName.getEnd(), + }, + ]; + } } return undefined; } export function fixPropertyAccessByIndex(node: ts.Node): Autofix[] | undefined { if (ts.isElementAccessExpression(node)) { - let elemAccess = node as ts.ElementAccessExpression; - let identifierName = indexExpr2IdentifierName(elemAccess.argumentExpression); - if (identifierName) - return [{ - replacementText: elemAccess.expression.getText() + '.' + identifierName, - start: elemAccess.getStart(), end: elemAccess.getEnd() - }]; + const elemAccess = node as ts.ElementAccessExpression; + const identifierName = indexExpr2IdentifierName(elemAccess.argumentExpression); + if (identifierName) { + return [ + { + replacementText: elemAccess.expression.getText() + '.' + identifierName, + start: elemAccess.getStart(), + end: elemAccess.getEnd(), + }, + ]; + } } return undefined; } -export function fixFunctionExpression(funcExpr: ts.FunctionExpression, - params: ts.NodeArray = funcExpr.parameters, +export function fixFunctionExpression( + funcExpr: ts.FunctionExpression, + params: ts.NodeArray = funcExpr.parameters, retType: ts.TypeNode | undefined = funcExpr.type, - modifiers: readonly ts.Modifier[] | undefined): Autofix { + modifiers: readonly ts.Modifier[] | undefined +): Autofix { let arrowFunc: ts.Expression = ts.factory.createArrowFunction( - modifiers, undefined, params, retType, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + modifiers, + undefined, + params, + retType, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), funcExpr.body ); if (needsParentheses(funcExpr)) { arrowFunc = ts.factory.createParenthesizedExpression(arrowFunc); } - let text = printer.printNode(ts.EmitHint.Unspecified, arrowFunc, funcExpr.getSourceFile()); - return { start: funcExpr.getStart(), end: funcExpr.getEnd(), replacementText: text }; + const text = printer.printNode(ts.EmitHint.Unspecified, arrowFunc, funcExpr.getSourceFile()); + return { + start: funcExpr.getStart(), + end: funcExpr.getEnd(), + replacementText: text, + }; } -export function fixReturnType(funcLikeDecl: ts.FunctionLikeDeclaration, typeNode: ts.TypeNode): Autofix { - let text = ': ' + printer.printNode(ts.EmitHint.Unspecified, typeNode, funcLikeDecl.getSourceFile()); - let pos = getReturnTypePosition(funcLikeDecl); +export function fixReturnType( + funcLikeDecl: ts.FunctionLikeDeclaration, + typeNode: ts.TypeNode +): Autofix { + const text = + ': ' + printer.printNode(ts.EmitHint.Unspecified, typeNode, funcLikeDecl.getSourceFile()); + const pos = getReturnTypePosition(funcLikeDecl); return { start: pos, end: pos, replacementText: text }; } export function dropTypeOnVarDecl(varDecl: ts.VariableDeclaration): Autofix { - let newVarDecl = ts.factory.createVariableDeclaration(varDecl.name, undefined, undefined, undefined); - let text = printer.printNode(ts.EmitHint.Unspecified, newVarDecl, varDecl.getSourceFile()); - return { start: varDecl.getStart(), end: varDecl.getEnd(), replacementText: text}; + const newVarDecl = ts.factory.createVariableDeclaration( + varDecl.name, + undefined, + undefined, + undefined + ); + const text = printer.printNode(ts.EmitHint.Unspecified, newVarDecl, varDecl.getSourceFile()); + return { + start: varDecl.getStart(), + end: varDecl.getEnd(), + replacementText: text, + }; } export function dropTypeOnlyFlag( @@ -107,37 +154,75 @@ export function dropTypeOnlyFlag( ): Autofix { let text: string; if (ts.isImportClause(impExpNode)) { - let newImportClause = ts.factory.createImportClause(false, impExpNode.name, impExpNode.namedBindings); + const newImportClause = ts.factory.createImportClause( + false, + impExpNode.name, + impExpNode.namedBindings + ); text = printer.printNode(ts.EmitHint.Unspecified, newImportClause, impExpNode.getSourceFile()); - } - else if (ts.isImportSpecifier(impExpNode)) { - let newImportSpec = ts.factory.createImportSpecifier(false, impExpNode.propertyName, impExpNode.name); + } else if (ts.isImportSpecifier(impExpNode)) { + const newImportSpec = ts.factory.createImportSpecifier( + false, + impExpNode.propertyName, + impExpNode.name + ); text = printer.printNode(ts.EmitHint.Unspecified, newImportSpec, impExpNode.getSourceFile()); - } - else if (ts.isExportDeclaration(impExpNode)) { - let newExportDecl = ts.factory.createExportDeclaration(impExpNode.modifiers, false, impExpNode.exportClause, - impExpNode.moduleSpecifier, impExpNode.assertClause); + } else if (ts.isExportDeclaration(impExpNode)) { + const newExportDecl = ts.factory.createExportDeclaration( + impExpNode.modifiers, + false, + impExpNode.exportClause, + impExpNode.moduleSpecifier, + impExpNode.assertClause + ); text = printer.printNode(ts.EmitHint.Unspecified, newExportDecl, impExpNode.getSourceFile()); - } - else { - let newExportSpec = ts.factory.createExportSpecifier(false, impExpNode.propertyName, impExpNode.name); + } else { + const newExportSpec = ts.factory.createExportSpecifier( + false, + impExpNode.propertyName, + impExpNode.name + ); text = printer.printNode(ts.EmitHint.Unspecified, newExportSpec, impExpNode.getSourceFile()); } - return { start: impExpNode.getStart(), end: impExpNode.getEnd(), replacementText: text }; + return { + start: impExpNode.getStart(), + end: impExpNode.getEnd(), + replacementText: text, + }; } -export function fixDefaultImport(importClause: ts.ImportClause, - defaultSpec: ts.ImportSpecifier, nonDefaultSpecs: ts.ImportSpecifier[]): Autofix { - let nameBindings = nonDefaultSpecs.length > 0 ? ts.factory.createNamedImports(nonDefaultSpecs) : undefined; - let newImportClause = ts.factory.createImportClause(importClause.isTypeOnly, defaultSpec.name, nameBindings); - let text = printer.printNode(ts.EmitHint.Unspecified, newImportClause, importClause.getSourceFile()); - return { start: importClause.getStart(), end: importClause.getEnd(), replacementText: text }; +export function fixDefaultImport( + importClause: ts.ImportClause, + defaultSpec: ts.ImportSpecifier, + nonDefaultSpecs: ts.ImportSpecifier[] +): Autofix { + const nameBindings = + nonDefaultSpecs.length > 0 ? ts.factory.createNamedImports(nonDefaultSpecs) : undefined; + const newImportClause = ts.factory.createImportClause( + importClause.isTypeOnly, + defaultSpec.name, + nameBindings + ); + const text = printer.printNode( + ts.EmitHint.Unspecified, + newImportClause, + importClause.getSourceFile() + ); + return { + start: importClause.getStart(), + end: importClause.getEnd(), + replacementText: text, + }; } export function fixTypeAssertion(typeAssertion: ts.TypeAssertion): Autofix { const asExpr = ts.factory.createAsExpression(typeAssertion.expression, typeAssertion.type); - let text = printer.printNode(ts.EmitHint.Unspecified, asExpr, typeAssertion.getSourceFile()); - return { start: typeAssertion.getStart(), end: typeAssertion.getEnd(), replacementText: text }; + const text = printer.printNode(ts.EmitHint.Unspecified, asExpr, typeAssertion.getSourceFile()); + return { + start: typeAssertion.getStart(), + end: typeAssertion.getEnd(), + replacementText: text, + }; } const printer: ts.Printer = ts.createPrinter(); @@ -147,27 +232,31 @@ function numericLiteral2IdentifierName(numeric: ts.NumericLiteral) { } function stringLiteral2IdentifierName(str: ts.StringLiteral) { - let text = (str as ts.StringLiteral).getText(); - return text.substring(1, text.length-1); // cut out starting and ending quoters. + const text = (str as ts.StringLiteral).getText(); + return text.substring(1, text.length - 1); // cut out starting and ending quoters. } function propertyName2IdentifierName(name: ts.PropertyName): string { - if (name.kind === ts.SyntaxKind.NumericLiteral) + if (name.kind === ts.SyntaxKind.NumericLiteral) { return numericLiteral2IdentifierName(name as ts.NumericLiteral); + } - if (name.kind === ts.SyntaxKind.StringLiteral) + if (name.kind === ts.SyntaxKind.StringLiteral) { return stringLiteral2IdentifierName(name as ts.StringLiteral); - + } + return ''; } function indexExpr2IdentifierName(index: ts.Expression) { - if (index.kind === ts.SyntaxKind.NumericLiteral) + if (index.kind === ts.SyntaxKind.NumericLiteral) { return numericLiteral2IdentifierName(index as ts.NumericLiteral); + } - if (index.kind === ts.SyntaxKind.StringLiteral) + if (index.kind === ts.SyntaxKind.StringLiteral) { return stringLiteral2IdentifierName(index as ts.StringLiteral); - + } + return ''; } @@ -176,15 +265,19 @@ function getReturnTypePosition(funcLikeDecl: ts.FunctionLikeDeclaration): number // Find position of the first node or token that follows parameters. // After that, iterate over child nodes in reverse order, until found // first closing parenthesis. - let postParametersPosition = ts.isArrowFunction(funcLikeDecl) + const postParametersPosition = ts.isArrowFunction(funcLikeDecl) ? funcLikeDecl.equalsGreaterThanToken.getStart() : funcLikeDecl.body.getStart(); - + const children = funcLikeDecl.getChildren(); for (let i = children.length - 1; i >= 0; i--) { const child = children[i]; - if (child.kind === ts.SyntaxKind.CloseParenToken && child.getEnd() <= postParametersPosition) + if ( + child.kind === ts.SyntaxKind.CloseParenToken && + child.getEnd() <= postParametersPosition + ) { return child.getEnd(); + } } } @@ -194,9 +287,15 @@ function getReturnTypePosition(funcLikeDecl: ts.FunctionLikeDeclaration): number function needsParentheses(node: ts.FunctionExpression): boolean { const parent = node.parent; - return ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent) || - ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent) || - ts.isTypeOfExpression(parent) || ts.isVoidExpression(parent) || ts.isAwaitExpression(parent) || + return ( + ts.isPrefixUnaryExpression(parent) || + ts.isPostfixUnaryExpression(parent) || + ts.isPropertyAccessExpression(parent) || + ts.isElementAccessExpression(parent) || + ts.isTypeOfExpression(parent) || + ts.isVoidExpression(parent) || + ts.isAwaitExpression(parent) || (ts.isCallExpression(parent) && node === parent.expression) || - (ts.isBinaryExpression(parent) && !isAssignmentOperator(parent.operatorToken)); -} \ No newline at end of file + (ts.isBinaryExpression(parent) && !isAssignmentOperator(parent.operatorToken)) + ); +} diff --git a/linter/src/CommandLineParser.ts b/linter/src/CommandLineParser.ts index 284ef5c8e55c77a39e397ba1127ea40e548ed199..1516054c58d7be06c01ae4535f34cbf393f9eb07 100644 --- a/linter/src/CommandLineParser.ts +++ b/linter/src/CommandLineParser.ts @@ -32,11 +32,12 @@ const logger = Logger.getLogger(); let inputFiles: string[]; let responseFile = ''; -function addSrcFile(value: string, dummy: string) { - if(value.startsWith('@')) +function addSrcFile(value: string) { + if (value.startsWith('@')) { responseFile = value; - else + } else { inputFiles.push(value); + } } const getFiles = (dir: string): string[] => { @@ -44,20 +45,21 @@ const getFiles = (dir: string): string[] => { const files = fs.readdirSync(dir); for (let i = 0; i < files.length; ++i) { - let name = path.join(dir, files[i]); + const name = path.join(dir, files[i]); if (fs.statSync(name).isDirectory()) { resultFiles.push(...getFiles(name)); } else { - let extension = path.extname(name); - if (extension === TS_EXT || extension === TSX_EXT || extension === ETS_EXT) + const extension = path.extname(name); + if (extension === TS_EXT || extension === TSX_EXT || extension === ETS_EXT) { resultFiles.push(name); + } } } return resultFiles; }; -function addProjectFolder(projectFolder: string, previous: any ) { +function addProjectFolder(projectFolder: string, previous: string[]) { return previous.concat([projectFolder]); } @@ -65,22 +67,28 @@ export function parseCommandLine(commandLineArgs: string[]): CommandLineOptions const opts: CommandLineOptions = { inputFiles: [], warningsAsErrors: false }; const program = new Command(); - program - .name('tslinter') - .description('Linter for TypeScript sources') - .version('0.0.1'); + program.name('tslinter').description('Linter for TypeScript sources').version('0.0.1'); program .option('-E, --TSC_Errors', 'show error messages from Tsc') .option('--relax', 'relax mode On') .option('--test-mode', 'run linter as if running TS test files') .option('--deveco-plugin-mode', 'run as IDE plugin') .option('-p, --project ', 'path to TS project config file') - .option('--project-folder ', 'path to folder containig TS files to verify', addProjectFolder, []) - .option('--autofix [autofix.json]', 'fix errors specified by JSON file (all if file is omitted)', - (val: string, prev: string|boolean) => { return val.endsWith(JSON_EXT) ? val : true; }) + .option( + '--project-folder ', + 'path to folder containig TS files to verify', + addProjectFolder, + [] + ) + .option( + '--autofix [autofix.json]', + 'fix errors specified by JSON file (all if file is omitted)', + (val: string) => { + return val.endsWith(JSON_EXT) ? val : true; + } + ) .addOption(new Option('--warnings-as-errors', 'treat warnings as errors').hideHelp(true)); - program - .argument('[srcFile...]', 'files to be verified', addSrcFile); + program.argument('[srcFile...]', 'files to be verified', addSrcFile); opts.strictMode = true; // Default mode of the linter. inputFiles = []; @@ -89,34 +97,56 @@ export function parseCommandLine(commandLineArgs: string[]): CommandLineOptions program.parse(cmdArgs); if (responseFile !== '') { try { - commandLineArgs = fs.readFileSync(responseFile.slice(1)).toString().split('\n').filter((e) => e.trimEnd()); + commandLineArgs = fs + .readFileSync(responseFile.slice(1)) + .toString() + .split('\n') + .filter(e => e.trimEnd()); cmdArgs = ['dummy', 'dummy']; cmdArgs.push(...commandLineArgs); - program.parse( cmdArgs); + program.parse(cmdArgs); + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { logger.error('Failed to read response file: ' + (error.message ?? error)); - process.exit(-1) + process.exit(-1); } } opts.inputFiles = inputFiles; const options = program.opts(); - if (options.relax) opts.strictMode = false; - if (options.TSC_Errors) opts.logTscErrors = true; - if (options.devecoPluginMode) opts.ideMode = true; - if (options.testMode) opts.testMode = true; - if (options.projectFolder) doProjectFolderArg(options.projectFolder, opts); - if (options.project) doProjectArg(options.project, opts); - if (options.autofix) doAutofixArg(options.autofix, opts); - if (options.warningsAsErrors) opts.warningsAsErrors = true; + if (options.relax) { + opts.strictMode = false; + } + if (options.TSC_Errors) { + opts.logTscErrors = true; + } + if (options.devecoPluginMode) { + opts.ideMode = true; + } + if (options.testMode) { + opts.testMode = true; + } + if (options.projectFolder) { + doProjectFolderArg(options.projectFolder, opts); + } + if (options.project) { + doProjectArg(options.project, opts); + } + if (options.autofix) { + doAutofixArg(options.autofix, opts); + } + if (options.warningsAsErrors) { + opts.warningsAsErrors = true; + } return opts; } function doProjectFolderArg(prjFolders: string[], opts: CommandLineOptions) { - for( let i = 0; i < prjFolders.length; i++ ) { - var prjFolderPath = prjFolders[ i ]; + for (let i = 0; i < prjFolders.length; i++) { + const prjFolderPath = prjFolders[i]; try { opts.inputFiles.push(...getFiles(prjFolderPath)); + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { logger.error('Failed to read folder: ' + (error.message ?? error)); process.exit(-1); @@ -134,12 +164,15 @@ function doProjectArg(cfgPath: string, opts: CommandLineOptions) { try { const oldUnrecoverableDiagnostic = host.onUnRecoverableConfigFileDiagnostic; - host.onUnRecoverableConfigFileDiagnostic = (diagnostic: ts.Diagnostic) => { diagnostics.push(diagnostic); }; + host.onUnRecoverableConfigFileDiagnostic = (diagnostic: ts.Diagnostic) => { + diagnostics.push(diagnostic); + }; opts.parsedConfigFile = ts.getParsedCommandLineOfConfigFile(configFile, {}, host); host.onUnRecoverableConfigFileDiagnostic = oldUnrecoverableDiagnostic; - if (opts.parsedConfigFile) + if (opts.parsedConfigFile) { diagnostics.push(...ts.getConfigFileParsingDiagnostics(opts.parsedConfigFile)); + } if (diagnostics.length > 0) { // Log all diagnostic messages and exit program. @@ -147,17 +180,19 @@ function doProjectArg(cfgPath: string, opts: CommandLineOptions) { logTscDiagnostic(diagnostics, logger.info); process.exit(-1); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { logger.error('Failed to read config file: ' + (error.message ?? error)); process.exit(-1); } } -function doAutofixArg(autofixOptVal: string|boolean, opts: CommandLineOptions) { +function doAutofixArg(autofixOptVal: string | boolean, opts: CommandLineOptions) { if (typeof autofixOptVal === 'string') { - let autofixInfoStr = fs.readFileSync(autofixOptVal).toString(); - let autofixInfos = JSON.parse(autofixInfoStr); + const autofixInfoStr = fs.readFileSync(autofixOptVal).toString(); + const autofixInfos = JSON.parse(autofixInfoStr); opts.autofixInfo = autofixInfos.autofixInfo.map((x: string) => decodeAutofixInfo(x)); + } else { + opts.autofixInfo = [AUTOFIX_ALL]; } - else opts.autofixInfo = [AUTOFIX_ALL]; } diff --git a/linter/src/CompilerWrapper.ts b/linter/src/CompilerWrapper.ts index 50172a72c7fe584a6758eb76543bf27d62fd2f4d..0b470f7cfd823a01eef8cb05467eb15e20d244b2 100644 --- a/linter/src/CompilerWrapper.ts +++ b/linter/src/CompilerWrapper.ts @@ -19,6 +19,7 @@ import { consoleLog } from './TypeScriptLinter'; import { formTscOptions } from './ts-compiler/FormTscOptions'; import { LintOptions } from './LintOptions'; +// eslint-disable-next-line @typescript-eslint/no-explicit-any export function compile(options: LintOptions, extraOptions?: any): ts.Program { const createProgramOptions = formTscOptions(options.cmdOptions, extraOptions); const program = ts.createProgram(createProgramOptions); @@ -26,9 +27,12 @@ export function compile(options: LintOptions, extraOptions?: any): ts.Program { if (options.cmdOptions.logTscErrors) { const diagnostics = ts.getPreEmitDiagnostics(program); logTscDiagnostic(diagnostics, consoleLog); - diagnostics.forEach((diagnostic) => { + diagnostics.forEach(diagnostic => { if (diagnostic.file && diagnostic.start) { - const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); + const { line, character } = ts.getLineAndCharacterOfPosition( + diagnostic.file, + diagnostic.start + ); const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); consoleLog(`${diagnostic.file.fileName} (${line + 1}, ${character + 1}): ${message}`); } else { diff --git a/linter/src/CookBookMsg.ts b/linter/src/CookBookMsg.ts index e977c8e19103a387bf789f4e820ab671e73ac312..faf305e3fc5aacaa2b819740a6fb28c7ef7a6d52 100644 --- a/linter/src/CookBookMsg.ts +++ b/linter/src/CookBookMsg.ts @@ -1,28 +1,29 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ export const cookBookMsg: string[] = []; export const cookBookTag: string[] = []; -for (let i = 0; i <= 150; i++) { +for (let i = 0; i <= 151; i++) { cookBookMsg[i] = ''; } -cookBookTag[1] = 'Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)'; +cookBookTag[1] = + 'Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)'; cookBookTag[2] = '"Symbol()" API is not supported (arkts-no-symbol)'; -cookBookTag[3] = 'Private \'#\' identifiers are not supported (arkts-no-private-identifiers)'; +cookBookTag[3] = "Private '#' identifiers are not supported (arkts-no-private-identifiers)"; cookBookTag[4] = 'Use unique names for types and namespaces. (arkts-unique-names)'; cookBookTag[5] = 'Use "let" instead of "var" (arkts-no-var)'; cookBookTag[6] = ''; @@ -34,7 +35,8 @@ cookBookTag[11] = ''; cookBookTag[12] = ''; cookBookTag[13] = ''; cookBookTag[14] = 'Use "class" instead of a type with call signature (arkts-no-call-signatures)'; -cookBookTag[15] = 'Use "class" instead of a type with constructor signature (arkts-no-ctor-signatures-type)'; +cookBookTag[15] = + 'Use "class" instead of a type with constructor signature (arkts-no-ctor-signatures-type)'; cookBookTag[16] = 'Only one static block is supported (arkts-no-multiple-static-blocks)'; cookBookTag[17] = 'Indexed signatures are not supported (arkts-no-indexed-signatures)'; cookBookTag[18] = ''; @@ -46,35 +48,43 @@ cookBookTag[23] = ''; cookBookTag[24] = ''; cookBookTag[25] = 'Declaring fields in "constructor" is not supported (arkts-no-ctor-prop-decls)'; cookBookTag[26] = ''; -cookBookTag[27] = 'Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)'; +cookBookTag[27] = + 'Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)'; cookBookTag[28] = 'Indexed access types are not supported (arkts-no-aliases-by-index)'; cookBookTag[29] = 'Indexed access is not supported for fields (arkts-no-props-by-index)'; cookBookTag[30] = 'Structural typing is not supported (arkts-no-structural-typing)'; cookBookTag[31] = ''; cookBookTag[32] = ''; cookBookTag[33] = ''; -cookBookTag[34] = 'Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)'; +cookBookTag[34] = + 'Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)'; cookBookTag[35] = ''; cookBookTag[36] = ''; cookBookTag[37] = 'RegExp literals are not supported (arkts-no-regexp-literals)'; -cookBookTag[38] = 'Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)'; +cookBookTag[38] = + 'Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)'; cookBookTag[39] = ''; -cookBookTag[40] = 'Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)'; +cookBookTag[40] = + 'Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)'; cookBookTag[41] = ''; cookBookTag[42] = ''; -cookBookTag[43] = 'Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)'; +cookBookTag[43] = + 'Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)'; cookBookTag[44] = ''; cookBookTag[45] = ''; cookBookTag[46] = 'Use arrow functions instead of function expressions (arkts-no-func-expressions)'; cookBookTag[47] = ''; cookBookTag[48] = ''; -cookBookTag[49] = 'Use generic functions instead of generic arrow functions (arkts-no-generic-lambdas)'; +cookBookTag[49] = + 'Use generic functions instead of generic arrow functions (arkts-no-generic-lambdas)'; cookBookTag[50] = 'Class literals are not supported (arkts-no-class-literals)'; -cookBookTag[51] = 'Classes cannot be specified in "implements" clause (arkts-implements-only-iface)'; +cookBookTag[51] = + 'Classes cannot be specified in "implements" clause (arkts-implements-only-iface)'; cookBookTag[52] = 'Reassigning object methods is not supported (arkts-no-method-reassignment)'; cookBookTag[53] = 'Only "as T" syntax is supported for type casts (arkts-as-casts)'; cookBookTag[54] = 'JSX expressions are not supported (arkts-no-jsx)'; -cookBookTag[55] = 'Unary operators "+", "-" and "~" work only on numbers (arkts-no-polymorphic-unops)'; +cookBookTag[55] = + 'Unary operators "+", "-" and "~" work only on numbers (arkts-no-polymorphic-unops)'; cookBookTag[56] = ''; cookBookTag[57] = ''; cookBookTag[58] = ''; @@ -90,7 +100,8 @@ cookBookTag[67] = ''; cookBookTag[68] = ''; cookBookTag[69] = 'Destructuring assignment is not supported (arkts-no-destruct-assignment)'; cookBookTag[70] = ''; -cookBookTag[71] = 'The comma operator "," is supported only in "for" loops (arkts-no-comma-outside-loops)'; +cookBookTag[71] = + 'The comma operator "," is supported only in "for" loops (arkts-no-comma-outside-loops)'; cookBookTag[72] = ''; cookBookTag[73] = ''; cookBookTag[74] = 'Destructuring variable declarations are not supported (arkts-no-destruct-decls)'; @@ -106,22 +117,27 @@ cookBookTag[83] = 'Mapped type expression is not supported (arkts-no-mapped-type cookBookTag[84] = '"with" statement is not supported (arkts-no-with)'; cookBookTag[85] = ''; cookBookTag[86] = ''; -cookBookTag[87] = '"throw" statements cannot accept values of arbitrary types (arkts-limited-throw)'; +cookBookTag[87] = + '"throw" statements cannot accept values of arbitrary types (arkts-limited-throw)'; cookBookTag[88] = ''; cookBookTag[89] = ''; cookBookTag[90] = 'Function return type inference is limited (arkts-no-implicit-return-types)'; -cookBookTag[91] = 'Destructuring parameter declarations are not supported (arkts-no-destruct-params)'; +cookBookTag[91] = + 'Destructuring parameter declarations are not supported (arkts-no-destruct-params)'; cookBookTag[92] = 'Nested functions are not supported (arkts-no-nested-funcs)'; -cookBookTag[93] = 'Using "this" inside stand-alone functions is not supported (arkts-no-standalone-this)'; +cookBookTag[93] = + 'Using "this" inside stand-alone functions is not supported (arkts-no-standalone-this)'; cookBookTag[94] = 'Generator functions are not supported (arkts-no-generators)'; cookBookTag[95] = ''; cookBookTag[96] = 'Type guarding is supported with "instanceof" and "as" (arkts-no-is)'; cookBookTag[97] = ''; cookBookTag[98] = ''; -cookBookTag[99] = 'It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)'; +cookBookTag[99] = + 'It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)'; cookBookTag[100] = ''; cookBookTag[101] = ''; -cookBookTag[102] = 'Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)'; +cookBookTag[102] = + 'Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)'; cookBookTag[103] = 'Declaration merging is not supported (arkts-no-decl-merging)'; cookBookTag[104] = 'Interfaces cannot extend classes (arkts-extends-only-class)'; cookBookTag[105] = ''; @@ -130,15 +146,18 @@ cookBookTag[107] = ''; cookBookTag[108] = ''; cookBookTag[109] = ''; cookBookTag[110] = ''; -cookBookTag[111] = 'Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)'; +cookBookTag[111] = + 'Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)'; cookBookTag[112] = ''; cookBookTag[113] = '"enum" declaration merging is not supported (arkts-no-enum-merging)'; cookBookTag[114] = 'Namespaces cannot be used as objects (arkts-no-ns-as-obj)'; cookBookTag[115] = ''; -cookBookTag[116] = 'Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)'; +cookBookTag[116] = + 'Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)'; cookBookTag[117] = ''; -cookBookTag[118] = 'Special import type declarations are not supported (arkts-no-special-imports)'; -cookBookTag[119] = 'Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)'; +cookBookTag[118] = ''; +cookBookTag[119] = + 'Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)'; cookBookTag[120] = '"import default as ..." is not supported (arkts-no-import-default-as)'; cookBookTag[121] = '"require" and "import" assignment are not supported (arkts-no-require)'; cookBookTag[122] = ''; @@ -146,28 +165,33 @@ cookBookTag[123] = ''; cookBookTag[124] = ''; cookBookTag[125] = ''; cookBookTag[126] = '"export = ..." assignment is not supported (arkts-no-export-assignment)'; -cookBookTag[127] = 'Special "export type" declarations are not supported (arkts-no-special-exports)'; +cookBookTag[127] = ''; cookBookTag[128] = 'Ambient module declaration is not supported (arkts-no-ambient-decls)'; cookBookTag[129] = 'Wildcards in module names are not supported (arkts-no-module-wildcards)'; cookBookTag[130] = 'Universal module definitions (UMD) are not supported (arkts-no-umd)'; cookBookTag[131] = ''; cookBookTag[132] = '"new.target" is not supported (arkts-no-new-target)'; cookBookTag[133] = ''; -cookBookTag[134] = 'Definite assignment assertions are not supported (arkts-no-definite-assignment)'; +cookBookTag[134] = + 'Definite assignment assertions are not supported (arkts-no-definite-assignment)'; cookBookTag[135] = ''; cookBookTag[136] = 'Prototype assignment is not supported (arkts-no-prototype-assignment)'; cookBookTag[137] = '"globalThis" is not supported (arkts-no-globalthis)'; cookBookTag[138] = 'Some of utility types are not supported (arkts-no-utility-types)'; cookBookTag[139] = 'Declaring properties on functions is not supported (arkts-no-func-props)'; -cookBookTag[140] = '"Function.apply", "Function.bind", "Function.call" are not supported (arkts-no-func-apply-bind-call)'; +cookBookTag[140] = + '"Function.apply", "Function.bind", "Function.call" are not supported (arkts-no-func-apply-bind-call)'; cookBookTag[141] = ''; cookBookTag[142] = '"as const" assertions are not supported (arkts-no-as-const)'; cookBookTag[143] = 'Import assertions are not supported (arkts-no-import-assertions)'; cookBookTag[144] = 'Usage of standard library is restricted (arkts-limited-stdlib)'; cookBookTag[145] = 'Strict type checking is enforced (arkts-strict-typing)'; -cookBookTag[146] = 'Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)'; +cookBookTag[146] = + 'Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)'; cookBookTag[147] = 'No dependencies on TypeScript code are currently allowed (arkts-no-ts-deps)'; -cookBookTag[148] = 'No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)'; +cookBookTag[148] = + 'No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)'; cookBookTag[149] = 'Classes cannot be used as objects (arkts-no-classes-as-obj)'; -cookBookTag[150] = '"import" statements after other statements are not allowed (arkts-no-misplaced-imports)'; -cookBookTag[151] = 'Usage of "ESObject" type is restricted (arkts-limited-esobject)'; +cookBookTag[150] = + '"import" statements after other statements are not allowed (arkts-no-misplaced-imports)'; +cookBookTag[151] = 'Usage of "ESObject" type is restricted (arkts-limited-esobj)'; diff --git a/linter/src/FaultAttrs.ts b/linter/src/FaultAttrs.ts index d4bb026cfd1778fd803000dc21e7b10ca3422bff..793464f6fa4a5d0d570f956e4f3d78e66003be3e 100644 --- a/linter/src/FaultAttrs.ts +++ b/linter/src/FaultAttrs.ts @@ -1,19 +1,19 @@ /* * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -import { FaultID } from './utils/consts/Problems'; +import { FaultID } from './Problems'; export class FaultAttributs { migratable?: boolean; @@ -23,11 +23,17 @@ export class FaultAttributs { export const faultsAttrs: FaultAttributs[] = []; -faultsAttrs[FaultID.LiteralAsPropertyName] = { migratable: true, cookBookRef: '1' }; +faultsAttrs[FaultID.LiteralAsPropertyName] = { + migratable: true, + cookBookRef: '1', +}; faultsAttrs[FaultID.ComputedPropertyName] = { cookBookRef: '1' }; faultsAttrs[FaultID.SymbolType] = { cookBookRef: '2' }; faultsAttrs[FaultID.PrivateIdentifier] = { migratable: true, cookBookRef: '3' }; -faultsAttrs[FaultID.DeclWithDuplicateName] = { migratable: true, cookBookRef: '4' }; +faultsAttrs[FaultID.DeclWithDuplicateName] = { + migratable: true, + cookBookRef: '4', +}; faultsAttrs[FaultID.VarDeclaration] = { migratable: true, cookBookRef: '5' }; faultsAttrs[FaultID.AnyType] = { cookBookRef: '8' }; faultsAttrs[FaultID.UnknownType] = { cookBookRef: '8' }; @@ -38,18 +44,30 @@ faultsAttrs[FaultID.IndexMember] = { cookBookRef: '17' }; faultsAttrs[FaultID.IntersectionType] = { cookBookRef: '19' }; faultsAttrs[FaultID.ThisType] = { cookBookRef: '21' }; faultsAttrs[FaultID.ConditionalType] = { cookBookRef: '22' }; -faultsAttrs[FaultID.ParameterProperties] = { migratable: true, cookBookRef: '25' }; +faultsAttrs[FaultID.ParameterProperties] = { + migratable: true, + cookBookRef: '25', +}; faultsAttrs[FaultID.ConstructorIface] = { cookBookRef: '27' }; faultsAttrs[FaultID.IndexedAccessType] = { cookBookRef: '28' }; -faultsAttrs[FaultID.PropertyAccessByIndex] = { migratable: true, cookBookRef: '29' }; +faultsAttrs[FaultID.PropertyAccessByIndex] = { + migratable: true, + cookBookRef: '29', +}; faultsAttrs[FaultID.StructuralIdentity] = { cookBookRef: '30' }; faultsAttrs[FaultID.GenericCallNoTypeArgs] = { cookBookRef: '34' }; faultsAttrs[FaultID.RegexLiteral] = { cookBookRef: '37' }; faultsAttrs[FaultID.ObjectLiteralNoContextType] = { cookBookRef: '38' }; faultsAttrs[FaultID.ObjectTypeLiteral] = { cookBookRef: '40' }; faultsAttrs[FaultID.ArrayLiteralNoContextType] = { cookBookRef: '43' }; -faultsAttrs[FaultID.FunctionExpression] = { migratable: true, cookBookRef: '46' }; -faultsAttrs[FaultID.LambdaWithTypeParameters] = { migratable: true, cookBookRef: '49' }; +faultsAttrs[FaultID.FunctionExpression] = { + migratable: true, + cookBookRef: '46', +}; +faultsAttrs[FaultID.LambdaWithTypeParameters] = { + migratable: true, + cookBookRef: '49', +}; faultsAttrs[FaultID.ClassExpression] = { migratable: true, cookBookRef: '50' }; faultsAttrs[FaultID.ImplementsClass] = { cookBookRef: '51' }; faultsAttrs[FaultID.MethodReassignment] = { cookBookRef: '52' }; @@ -60,15 +78,27 @@ faultsAttrs[FaultID.DeleteOperator] = { cookBookRef: '59' }; faultsAttrs[FaultID.TypeQuery] = { cookBookRef: '60' }; faultsAttrs[FaultID.InstanceofUnsupported] = { cookBookRef: '65' }; faultsAttrs[FaultID.InOperator] = { cookBookRef: '66' }; -faultsAttrs[FaultID.DestructuringAssignment] = { migratable: true, cookBookRef: '69' }; +faultsAttrs[FaultID.DestructuringAssignment] = { + migratable: true, + cookBookRef: '69', +}; faultsAttrs[FaultID.CommaOperator] = { cookBookRef: '71' }; -faultsAttrs[FaultID.DestructuringDeclaration] = { migratable: true, cookBookRef: '74' }; -faultsAttrs[FaultID.CatchWithUnsupportedType] = { migratable: true, cookBookRef: '79' }; +faultsAttrs[FaultID.DestructuringDeclaration] = { + migratable: true, + cookBookRef: '74', +}; +faultsAttrs[FaultID.CatchWithUnsupportedType] = { + migratable: true, + cookBookRef: '79', +}; faultsAttrs[FaultID.ForInStatement] = { cookBookRef: '80' }; faultsAttrs[FaultID.MappedType] = { cookBookRef: '83' }; faultsAttrs[FaultID.WithStatement] = { cookBookRef: '84' }; faultsAttrs[FaultID.ThrowStatement] = { migratable: true, cookBookRef: '87' }; -faultsAttrs[FaultID.LimitedReturnTypeInference] = { migratable: true, cookBookRef: '90'}; +faultsAttrs[FaultID.LimitedReturnTypeInference] = { + migratable: true, + cookBookRef: '90', +}; faultsAttrs[FaultID.DestructuringParameter] = { cookBookRef: '91' }; faultsAttrs[FaultID.LocalFunction] = { migratable: true, cookBookRef: '92' }; faultsAttrs[FaultID.FunctionContainsThis] = { cookBookRef: '93' }; @@ -85,11 +115,9 @@ faultsAttrs[FaultID.EnumMerging] = { cookBookRef: '113' }; faultsAttrs[FaultID.NamespaceAsObject] = { cookBookRef: '114' }; faultsAttrs[FaultID.NonDeclarationInNamespace] = { cookBookRef: '116' }; faultsAttrs[FaultID.ImportFromPath] = { cookBookRef: '119' }; -faultsAttrs[FaultID.TypeOnlyImport] = { migratable: true, cookBookRef: '118' }; faultsAttrs[FaultID.DefaultImport] = { migratable: true, cookBookRef: '120' }; faultsAttrs[FaultID.ImportAssignment] = { cookBookRef: '121' }; faultsAttrs[FaultID.ExportAssignment] = { cookBookRef: '126' }; -faultsAttrs[FaultID.TypeOnlyExport] = { migratable: true, cookBookRef: '127' }; faultsAttrs[FaultID.ShorthandAmbientModuleDecl] = { cookBookRef: '128' }; faultsAttrs[FaultID.WildcardsInModuleName] = { cookBookRef: '129' }; faultsAttrs[FaultID.UMDModuleDefinition] = { cookBookRef: '130' }; @@ -105,7 +133,10 @@ faultsAttrs[FaultID.ImportAssertion] = { cookBookRef: '143' }; faultsAttrs[FaultID.LimitedStdLibApi] = { cookBookRef: '144' }; faultsAttrs[FaultID.StrictDiagnostic] = { cookBookRef: '145' }; faultsAttrs[FaultID.ErrorSuppression] = { cookBookRef: '146' }; -faultsAttrs[FaultID.UnsupportedDecorators] = { warning: true, cookBookRef: '148' }; +faultsAttrs[FaultID.UnsupportedDecorators] = { + warning: true, + cookBookRef: '148', +}; faultsAttrs[FaultID.ClassAsObject] = { cookBookRef: '149' }; faultsAttrs[FaultID.ImportAfterStatement] = { cookBookRef: '150' }; faultsAttrs[FaultID.EsObjectType] = { warning: true, cookBookRef: '151' }; diff --git a/linter/src/FaultDesc.ts b/linter/src/FaultDesc.ts index c61b136e7b1aabf1c36ce96c92a0b4c5bf039df3..7ca180b86e0448c1981bd02432d608ef5d7deeec 100644 --- a/linter/src/FaultDesc.ts +++ b/linter/src/FaultDesc.ts @@ -13,13 +13,14 @@ * limitations under the License. */ -import { FaultID } from './utils/consts/Problems'; +import { FaultID } from './Problems'; export const faultDesc: string[] = []; faultDesc[FaultID.AnyType] = '"any" type'; faultDesc[FaultID.SymbolType] = '"symbol" type'; -faultDesc[FaultID.ObjectLiteralNoContextType] = 'Object literals with no context Class or Interface type'; +faultDesc[FaultID.ObjectLiteralNoContextType] = + 'Object literals with no context Class or Interface type'; faultDesc[FaultID.ArrayLiteralNoContextType] = 'Array literals with no context Array type'; faultDesc[FaultID.ComputedPropertyName] = 'Computed properties'; faultDesc[FaultID.LiteralAsPropertyName] = 'String or integer literal as property name'; @@ -76,8 +77,6 @@ faultDesc[FaultID.MultipleStaticBlocks] = 'Multiple static blocks'; faultDesc[FaultID.ThisType] = '"this" type'; faultDesc[FaultID.IntefaceExtendDifProps] = 'Extends same properties with different types'; faultDesc[FaultID.StructuralIdentity] = 'Use of type structural identity'; -faultDesc[FaultID.TypeOnlyImport] = 'Type-only imports'; -faultDesc[FaultID.TypeOnlyExport] = 'Type-only exports'; faultDesc[FaultID.DefaultImport] = 'Default import declarations'; faultDesc[FaultID.ExportAssignment] = 'Export assignments (export = ..)'; faultDesc[FaultID.ImportAssignment] = 'Import assignments (import = ..)'; diff --git a/linter/src/LintOptions.ts b/linter/src/LintOptions.ts index 621b43dc22c89263632bdf73aaed55357b091b88..48a6f22f6d6b1c75ce91219ef1b32c09b6d68055 100644 --- a/linter/src/LintOptions.ts +++ b/linter/src/LintOptions.ts @@ -26,5 +26,6 @@ export interface LintOptions { incrementalLintInfo?: IncrementalLintInfo; tsProgram?: ts.Program; reportAutofixCb?: ReportAutofixCallback; + // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any; } diff --git a/linter/src/LinterCLI.ts b/linter/src/LinterCLI.ts index 7fd5063d9d5e4b260641c501412b12cdf34ab8b0..7332d13bcca059afb7092432b2f80aeb097e28f3 100644 --- a/linter/src/LinterCLI.ts +++ b/linter/src/LinterCLI.ts @@ -49,7 +49,10 @@ export function run() { } function getTempFileName() { - return path.join(os.tmpdir(), Math.floor(Math.random() * 10000000).toString() + '_linter_tmp_file.ts'); + return path.join( + os.tmpdir(), + Math.floor(Math.random() * 10000000).toString() + '_linter_tmp_file.ts' + ); } function runIDEMode(cmdOptions: CommandLineOptions) { @@ -63,7 +66,9 @@ function runIDEMode(cmdOptions: CommandLineOptions) { terminal: false, }); - rl.on('line', (line: string) => { fs.appendFileSync(tmpFileName, line + '\n'); }); + rl.on('line', (line: string) => { + fs.appendFileSync(tmpFileName, line + '\n'); + }); rl.once('close', () => { // end of input writeStream.close(); @@ -74,7 +79,7 @@ function runIDEMode(cmdOptions: CommandLineOptions) { const result = lint({ cmdOptions: cmdOptions, realtimeLint: false }); const problems = Array.from(result.problemsInfos.values()); if (problems.length === 1) { - const jsonMessage = problems[0].map((x) => ({ + const jsonMessage = problems[0].map(x => ({ line: x.line, column: x.column, start: x.start, @@ -84,7 +89,7 @@ function runIDEMode(cmdOptions: CommandLineOptions) { rule: x.rule, severity: x.severity, autofixable: x.autofixable, - autofix: x.autofix + autofix: x.autofix, })); logger.info(`{"linter messages":${JSON.stringify(jsonMessage)}}`); } else { diff --git a/linter/src/LinterRunner.ts b/linter/src/LinterRunner.ts index 0e701f2baa717d06dc4c66a680990d66d8c508c9..7b7bb5f4a176a2ec33da85048404ff6571822249 100644 --- a/linter/src/LinterRunner.ts +++ b/linter/src/LinterRunner.ts @@ -16,7 +16,7 @@ import * as ts from 'typescript'; import { ProblemInfo } from './ProblemInfo'; import { TypeScriptLinter, consoleLog } from './TypeScriptLinter'; -import { FaultID } from './utils/consts/Problems'; +import { FaultID } from './Problems'; import { faultDesc } from './FaultDesc'; import { faultsAttrs } from './FaultAttrs'; import { LintRunResult } from './LintRunResult'; @@ -24,7 +24,12 @@ import * as path from 'node:path'; import { compile } from './CompilerWrapper'; import { LintOptions } from './LintOptions'; import { AutofixInfoSet } from './Autofixer'; -import { TSCCompiledProgram, TSCCompiledProgramSimple, TSCCompiledProgramWithDiagnostics, getStrictOptions } from './ts-diagnostics/TSCCompiledProgram'; +import { + TSCCompiledProgram, + TSCCompiledProgramSimple, + TSCCompiledProgramWithDiagnostics, + getStrictOptions, +} from './ts-diagnostics/TSCCompiledProgram'; import { mergeArrayMaps } from './utils/functions/MergeArrayMaps'; import { getTscDiagnostics } from './ts-diagnostics/GetTscDiagnostics'; import { transformTscDiagnostics } from './ts-diagnostics/TransformTscDiagnostics'; @@ -45,21 +50,25 @@ export function lint(options: LintOptions): LintRunResult { if (cmdOptions.inputFiles.length > 0) { // Apply linter only to the project source files that are specified // as a command-line arguments. Other source files will be discarded. - const cmdInputsResolvedPaths = cmdOptions.inputFiles.map((x) => path.resolve(x)); - const configInputsResolvedPaths = inputFiles.map((x) => path.resolve(x)); - inputFiles = configInputsResolvedPaths.filter((x) => cmdInputsResolvedPaths.some((y) => x === y)); + const cmdInputsResolvedPaths = cmdOptions.inputFiles.map(x => path.resolve(x)); + const configInputsResolvedPaths = inputFiles.map(x => path.resolve(x)); + inputFiles = configInputsResolvedPaths.filter(x => cmdInputsResolvedPaths.some(y => x === y)); } } // #13436: ignore-list for ArkTS projects. - inputFiles = inputFiles.filter(input => - !ARKTS_IGNORE_FILES.some(ignore => path.basename(input) === ignore) && - !ARKTS_IGNORE_DIRS.some(ignore => pathContainsDirectory(path.resolve(input), ignore))); + inputFiles = inputFiles.filter( + input => + !ARKTS_IGNORE_FILES.some(ignore => path.basename(input) === ignore) && + !ARKTS_IGNORE_DIRS.some(ignore => pathContainsDirectory(path.resolve(input), ignore)) + ); const srcFiles: ts.SourceFile[] = []; for (const inputFile of inputFiles) { const srcFile = tsProgram.getSourceFile(inputFile); - if (srcFile) srcFiles.push(srcFile); + if (srcFile) { + srcFiles.push(srcFile); + } } const tscStrictDiagnostics = getTscDiagnostics(tscDiagnosticsLinter, srcFiles); @@ -79,14 +88,20 @@ export function lint(options: LintOptions): LintRunResult { consoleLog('\n\n\nFiles scanned: ', srcFiles.length); consoleLog('\nFiles with problems: ', errorNodes); - let errorNodesTotal = 0, warningNodes = 0; + let errorNodesTotal = 0, + warningNodes = 0; for (let i = 0; i < FaultID.LAST_ID; i++) { // if Strict mode - count all cases - if (!linter.strictMode && faultsAttrs[i].migratable) // In relax mode skip migratable + if (!linter.strictMode && faultsAttrs[i].migratable) { + // In relax mode skip migratable continue; + } - if (faultsAttrs[i].warning) warningNodes += linter.nodeCounters[i]; - else errorNodesTotal += linter.nodeCounters[i]; + if (faultsAttrs[i].warning) { + warningNodes += linter.nodeCounters[i]; + } else { + errorNodesTotal += linter.nodeCounters[i]; + } } logTotalProblemsInfo(errorNodesTotal, warningNodes, linter); logProblemsPercentageByFeatures(linter); @@ -109,7 +124,7 @@ export function createLinter(options: LintOptions): TSCCompiledProgram { function lintFiles(srcFiles: ts.SourceFile[], linter: TypeScriptLinter): LintRunResult { let problemFiles = 0; - let problemsInfos: Map = new Map(); + const problemsInfos: Map = new Map(); for (const srcFile of srcFiles) { const prevVisitedNodes = linter.totalVisitedNodes; @@ -119,12 +134,13 @@ function lintFiles(srcFiles: ts.SourceFile[], linter: TypeScriptLinter): LintRun linter.warningLineNumbersString = ''; const nodeCounters: number[] = []; - for (let i = 0; i < FaultID.LAST_ID; i++) + for (let i = 0; i < FaultID.LAST_ID; i++) { nodeCounters[i] = linter.nodeCounters[i]; + } linter.lint(srcFile); // save results and clear problems array - problemsInfos.set( path.normalize(srcFile.fileName), [...linter.problemsInfos]); + problemsInfos.set(path.normalize(srcFile.fileName), [...linter.problemsInfos]); linter.problemsInfos.length = 0; // print results for current file @@ -133,7 +149,13 @@ function lintFiles(srcFiles: ts.SourceFile[], linter: TypeScriptLinter): LintRun const fileWarningLines = linter.totalWarningLines - prevWarningLines; problemFiles = countProblemFiles( - nodeCounters, problemFiles, srcFile, fileVisitedNodes, fileErrorLines, fileWarningLines, linter + nodeCounters, + problemFiles, + srcFile, + fileVisitedNodes, + fileErrorLines, + fileWarningLines, + linter ); } @@ -144,32 +166,57 @@ function lintFiles(srcFiles: ts.SourceFile[], linter: TypeScriptLinter): LintRun } function countProblemFiles( - nodeCounters: number[], filesNumber: number, tsSrcFile: ts.SourceFile, - fileNodes: number, fileErrorLines: number, fileWarningLines: number, linter: TypeScriptLinter, + nodeCounters: number[], + filesNumber: number, + tsSrcFile: ts.SourceFile, + fileNodes: number, + fileErrorLines: number, + fileWarningLines: number, + linter: TypeScriptLinter ) { - let errorNodes = 0, warningNodes = 0; + let errorNodes = 0, + warningNodes = 0; for (let i = 0; i < FaultID.LAST_ID; i++) { - let nodeCounterDiff = linter.nodeCounters[i] - nodeCounters[i]; - if (faultsAttrs[i].warning) warningNodes += nodeCounterDiff; - else errorNodes += nodeCounterDiff; + const nodeCounterDiff = linter.nodeCounters[i] - nodeCounters[i]; + if (faultsAttrs[i].warning) { + warningNodes += nodeCounterDiff; + } else { + errorNodes += nodeCounterDiff; + } } if (errorNodes > 0) { filesNumber++; - let errorRate = ((errorNodes / fileNodes) * 100).toFixed(2); - let warningRate = ((warningNodes / fileNodes) * 100).toFixed(2); + const errorRate = ((errorNodes / fileNodes) * 100).toFixed(2); + const warningRate = ((warningNodes / fileNodes) * 100).toFixed(2); consoleLog(tsSrcFile.fileName, ': ', '\n\tError lines: ', linter.errorLineNumbersString); consoleLog(tsSrcFile.fileName, ': ', '\n\tWarning lines: ', linter.warningLineNumbersString); - consoleLog('\n\tError constructs (%): ', errorRate, '\t[ of ', fileNodes, ' constructs ], \t', fileErrorLines, ' lines'); - consoleLog('\n\tWarning constructs (%): ', warningRate, '\t[ of ', fileNodes, ' constructs ], \t', fileWarningLines, ' lines'); + consoleLog( + '\n\tError constructs (%): ', + errorRate, + '\t[ of ', + fileNodes, + ' constructs ], \t', + fileErrorLines, + ' lines' + ); + consoleLog( + '\n\tWarning constructs (%): ', + warningRate, + '\t[ of ', + fileNodes, + ' constructs ], \t', + fileWarningLines, + ' lines' + ); } return filesNumber; } function logTotalProblemsInfo(errorNodes: number, warningNodes: number, linter: TypeScriptLinter) { - let errorRate = ((errorNodes / linter.totalVisitedNodes) * 100).toFixed(2); - let warningRate = ((warningNodes / linter.totalVisitedNodes) * 100).toFixed(2); + const errorRate = ((errorNodes / linter.totalVisitedNodes) * 100).toFixed(2); + const warningRate = ((warningNodes / linter.totalVisitedNodes) * 100).toFixed(2); consoleLog('\nTotal error constructs (%): ', errorRate); consoleLog('\nTotal warning constructs (%): ', warningRate); consoleLog('\nTotal error lines:', linter.totalErrorLines, ' lines\n'); @@ -180,13 +227,22 @@ function logProblemsPercentageByFeatures(linter: TypeScriptLinter) { consoleLog('\nPercent by features: '); for (let i = 0; i < FaultID.LAST_ID; i++) { // if Strict mode - count all cases - if (!linter.strictMode && faultsAttrs[i].migratable) + if (!linter.strictMode && faultsAttrs[i].migratable) { continue; - - let nodes = linter.nodeCounters[i]; - let lines = linter.lineCounters[i]; - let pecentage = ((nodes / linter.totalVisitedNodes) * 100).toFixed(2).padEnd(7, ' '); + } - consoleLog(faultDesc[i].padEnd(55, ' '), pecentage, '[', nodes, ' constructs / ', lines, ' lines]'); + const nodes = linter.nodeCounters[i]; + const lines = linter.lineCounters[i]; + const pecentage = ((nodes / linter.totalVisitedNodes) * 100).toFixed(2).padEnd(7, ' '); + + consoleLog( + faultDesc[i].padEnd(55, ' '), + pecentage, + '[', + nodes, + ' constructs / ', + lines, + ' lines]' + ); } } diff --git a/linter/src/ProblemSeverity.ts b/linter/src/ProblemSeverity.ts index 3736c692ef46726f5ecced3be6290c18c371f039..41822bf05ef184cb0d15a1ae9dfec19a69c63313 100644 --- a/linter/src/ProblemSeverity.ts +++ b/linter/src/ProblemSeverity.ts @@ -13,4 +13,7 @@ * limitations under the License. */ -export enum ProblemSeverity { WARNING = 1, ERROR = 2 } +export enum ProblemSeverity { + WARNING = 1, + ERROR = 2, +} diff --git a/linter/src/utils/consts/Problems.ts b/linter/src/Problems.ts similarity index 98% rename from linter/src/utils/consts/Problems.ts rename to linter/src/Problems.ts index 3d1def20dcb9e9f650dd85af93e81eff6643be04..b8e666e59419b70697972a545cf74329ea01525e 100644 --- a/linter/src/utils/consts/Problems.ts +++ b/linter/src/Problems.ts @@ -73,8 +73,6 @@ export enum FaultID { ThisType, IntefaceExtendDifProps, StructuralIdentity, - TypeOnlyImport, - TypeOnlyExport, DefaultImport, ExportAssignment, ImportAssignment, diff --git a/linter/src/TestRunner.ts b/linter/src/TestRunner.ts index 99fa9295880361299aaf627ce609c5942cb4763b..92c270706ac2e3f832db095bc14418fa9d0cc836 100644 --- a/linter/src/TestRunner.ts +++ b/linter/src/TestRunner.ts @@ -40,7 +40,7 @@ interface TestNodeInfo { enum Mode { STRICT, RELAX, - AUTOFIX + AUTOFIX, } const RESULT_EXT: string[] = []; @@ -49,7 +49,7 @@ RESULT_EXT[Mode.RELAX] = '.relax.json'; RESULT_EXT[Mode.AUTOFIX] = '.autofix.json'; const AUTOFIX_CONFIG_EXT = '.autofix.cfg.json'; const AUTOFIX_SKIP_EXT = '.autofix.skip'; -const ARGS_CONFIG_EXT = '.args.json' +const ARGS_CONFIG_EXT = '.args.json'; const DIFF_EXT = '.diff'; function runTests(testDirs: string[]): number { @@ -60,13 +60,21 @@ function runTests(testDirs: string[]): number { TypeScriptLinter.ideMode = true; TypeScriptLinter.testMode = true; - let passed = 0, failed = 0; + let passed = 0, + failed = 0; // Get tests from test directory - if (!testDirs?.length) testDirs = [ TEST_DIR ]; + if (!testDirs?.length) { + testDirs = [TEST_DIR]; + } for (const testDir of testDirs) { - let testFiles: string[] = fs.readdirSync(testDir) - .filter((x) => (x.trimEnd().endsWith(ts.Extension.Ts) && !x.trimEnd().endsWith(ts.Extension.Dts)) || x.trimEnd().endsWith(ts.Extension.Tsx)); + const testFiles: string[] = fs + .readdirSync(testDir) + .filter( + x => + (x.trimEnd().endsWith(ts.Extension.Ts) && !x.trimEnd().endsWith(ts.Extension.Dts)) || + x.trimEnd().endsWith(ts.Extension.Tsx) + ); logger.info(`\nProcessing "${testDir}" directory:\n`); @@ -75,25 +83,30 @@ function runTests(testDirs: string[]): number { if (runTest(testDir, testFile, Mode.STRICT)) { failed++; hasComparisonFailures = true; + } else { + passed++; } - else passed++; if (runTest(testDir, testFile, Mode.AUTOFIX)) { failed++; hasComparisonFailures = true; + } else { + passed++; } - else passed++; if (runTest(testDir, testFile, Mode.RELAX)) { failed++; hasComparisonFailures = true; + } else { + passed++; } - else passed++; } } - logger.info(`\nSUMMARY: ${passed + failed} total, ${passed} passed or skipped, ${failed} failed.`); - logger.info((failed > 0) ? '\nTEST FAILED' : '\nTEST SUCCESSFUL'); + logger.info( + `\nSUMMARY: ${passed + failed} total, ${passed} passed or skipped, ${failed} failed.` + ); + logger.info(failed > 0 ? '\nTEST FAILED' : '\nTEST SUCCESSFUL'); process.exit(hasComparisonFailures ? -1 : 0); } @@ -110,8 +123,8 @@ function runTest(testDir: string, testFile: string, mode: Mode): boolean { // Configure test parameters and run linter. const args: string[] = [path.join(testDir, testFile)]; - let argsFileName = path.join(testDir, testFile + ARGS_CONFIG_EXT); - let currentTestMode = TypeScriptLinter.testMode; + const argsFileName = path.join(testDir, testFile + ARGS_CONFIG_EXT); + const currentTestMode = TypeScriptLinter.testMode; if (fs.existsSync(argsFileName)) { const data = fs.readFileSync(argsFileName).toString(); @@ -121,15 +134,18 @@ function runTest(testDir: string, testFile: string, mode: Mode): boolean { } } - if (mode === Mode.RELAX) args.push('--relax'); - else if (mode === Mode.AUTOFIX) { + if (mode === Mode.RELAX) { + args.push('--relax'); + } else if (mode === Mode.AUTOFIX) { args.push('--autofix'); - let autofixCfg = path.join(testDir, testFile + AUTOFIX_CONFIG_EXT); - if (fs.existsSync(autofixCfg)) args.push(autofixCfg); + const autofixCfg = path.join(testDir, testFile + AUTOFIX_CONFIG_EXT); + if (fs.existsSync(autofixCfg)) { + args.push(autofixCfg); + } } const cmdOptions = parseCommandLine(args); const result = lint({ cmdOptions: cmdOptions, realtimeLint: false }); - const fileProblems = result.problemsInfos.get( path.normalize(cmdOptions.inputFiles[0]) ); + const fileProblems = result.problemsInfos.get(path.normalize(cmdOptions.inputFiles[0])); if (fileProblems === undefined) { return true; } @@ -140,27 +156,31 @@ function runTest(testDir: string, testFile: string, mode: Mode): boolean { const testResultFileName = testFile + resultExt; // Get list of bad nodes from the current run. - const resultNodes: TestNodeInfo[] = - fileProblems.map( - (x) => ({ - line: x.line, column: x.column, problem: x.problem, - autofixable: mode === Mode.AUTOFIX ? x.autofixable : undefined, - autofix: mode === Mode.AUTOFIX ? x.autofix : undefined, - suggest: x.suggest, - rule: x.rule - }) - ); + const resultNodes: TestNodeInfo[] = fileProblems.map(x => ({ + line: x.line, + column: x.column, + problem: x.problem, + autofixable: mode === Mode.AUTOFIX ? x.autofixable : undefined, + autofix: mode === Mode.AUTOFIX ? x.autofix : undefined, + suggest: x.suggest, + rule: x.rule, + })); // Read file with expected test result. let expectedResult: { nodes: TestNodeInfo[] }; - let diff: string = ''; + let diff = ''; try { const expectedResultFile = fs.readFileSync(path.join(testDir, testResultFileName)).toString(); expectedResult = JSON.parse(expectedResultFile); - if (!expectedResult || !expectedResult.nodes || expectedResult.nodes.length !== resultNodes.length) { + if ( + !expectedResult || + !expectedResult.nodes || + expectedResult.nodes.length !== resultNodes.length + ) { testFailed = true; - let expectedResultCount = expectedResult && expectedResult.nodes ? expectedResult.nodes.length : 0; + const expectedResultCount = + expectedResult && expectedResult.nodes ? expectedResult.nodes.length : 0; diff = `Expected count: ${expectedResultCount} vs actual count: ${resultNodes.length}`; logger.info(`${TAB}${diff}`); } else { @@ -171,6 +191,7 @@ function runTest(testDir: string, testFile: string, mode: Mode): boolean { if (testFailed) { logger.info(`${TAB}Test failed. Expected and actual results differ.`); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { testFailed = true; logger.info(`${TAB}Test failed. ${error.message ?? error}`); @@ -182,15 +203,25 @@ function runTest(testDir: string, testFile: string, mode: Mode): boolean { return testFailed; } -function expectedAndActualMatch(expectedNodes: TestNodeInfo[], actualNodes: TestNodeInfo[]): string { +function expectedAndActualMatch( + expectedNodes: TestNodeInfo[], + actualNodes: TestNodeInfo[] +): string { // Compare expected and actual results. for (let i = 0; i < actualNodes.length; i++) { - let actual = actualNodes[i]; - let expect = expectedNodes[i]; - if (actual.line !== expect.line || actual.column !== expect.column || actual.problem !== expect.problem) { + const actual = actualNodes[i]; + const expect = expectedNodes[i]; + if ( + actual.line !== expect.line || + actual.column !== expect.column || + actual.problem !== expect.problem + ) { return reportDiff(expect, actual); } - if (actual.autofixable !== expect.autofixable || !autofixArraysMatch(expect.autofix, actual.autofix)) { + if ( + actual.autofixable !== expect.autofixable || + !autofixArraysMatch(expect.autofix, actual.autofix) + ) { return reportDiff(expect, actual); } if (expect.suggest && actual.suggest !== expect.suggest) { @@ -204,21 +235,40 @@ function expectedAndActualMatch(expectedNodes: TestNodeInfo[], actualNodes: Test return ''; } -function autofixArraysMatch(expected: Autofix[] | undefined, actual: Autofix[] | undefined): boolean { - if (!expected && !actual) return true; - if (!(expected && actual) || expected.length !== actual.length) return false; +function autofixArraysMatch( + expected: Autofix[] | undefined, + actual: Autofix[] | undefined +): boolean { + if (!expected && !actual) { + return true; + } + if (!(expected && actual) || expected.length !== actual.length) { + return false; + } for (let i = 0; i < actual.length; ++i) { if ( - actual[i].start !== expected[i].start || actual[i].end !== expected[i].end || - actual[i].replacementText.replace(/\r\n/g, '\n') !== expected[i].replacementText.replace(/\r\n/g, '\n') - ) return false; + actual[i].start !== expected[i].start || + actual[i].end !== expected[i].end || + actual[i].replacementText.replace(/\r\n/g, '\n') !== + expected[i].replacementText.replace(/\r\n/g, '\n') + ) { + return false; + } } return true; } -function writeActualResultFile(testDir: string, testFile: string, resultExt: string, resultNodes: TestNodeInfo[], diff: string) { +function writeActualResultFile( + testDir: string, + testFile: string, + resultExt: string, + resultNodes: TestNodeInfo[], + diff: string +) { const actualResultsDir = path.join(testDir, 'results'); - if (!fs.existsSync(actualResultsDir)) fs.mkdirSync(actualResultsDir); + if (!fs.existsSync(actualResultsDir)) { + fs.mkdirSync(actualResultsDir); + } const actualResultJSON = JSON.stringify({ nodes: resultNodes }, null, 4); fs.writeFileSync(path.join(actualResultsDir, testFile + resultExt), actualResultJSON); @@ -229,11 +279,10 @@ function writeActualResultFile(testDir: string, testFile: string, resultExt: str } function reportDiff(expected: TestNodeInfo, actual: TestNodeInfo): string { - let expectedNode = JSON.stringify({ nodes: [expected] }, null, 4); - let actualNode = JSON.stringify({ nodes: [actual] }, null, 4); + const expectedNode = JSON.stringify({ nodes: [expected] }, null, 4); + const actualNode = JSON.stringify({ nodes: [actual] }, null, 4); - let diff = -`Expected: + const diff = `Expected: ${expectedNode} Actual: ${actualNode}`; diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index 15d018ed5999142bb38be27095e9792ba21f180b..4c935f1d9e5ca6a7fb10a7dab759e236adeddccc 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -15,8 +15,8 @@ import * as ts from 'typescript'; import * as path from 'node:path'; -import { TsUtils, CheckType } from './utils/TsUtils'; -import { FaultID } from './utils/consts/Problems'; +import { TsUtils } from './utils/TsUtils'; +import { FaultID } from './Problems'; import { faultsAttrs } from './FaultAttrs'; import { faultDesc } from './FaultDesc'; import { cookBookMsg, cookBookTag } from './CookBookMsg'; @@ -27,14 +27,21 @@ import { ProblemInfo } from './ProblemInfo'; import { ProblemSeverity } from './ProblemSeverity'; import Logger from '../utils/logger'; import { ARKUI_DECORATORS } from './utils/consts/ArkUIDecorators'; -import { NON_INITIALIZABLE_PROPERTY_DECORATORS, - NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS } from './utils/consts/NonInitializablePropertyDecorators'; +import { LIMITED_STD_GLOBAL_FUNC } from './utils/consts/LimitedStdGlobalFunc'; +import { LIMITED_STD_OBJECT_API } from './utils/consts/LimitedStdObjectAPI'; +import { LIMITED_STD_REFLECT_API } from './utils/consts/LimitedStdReflectAPI'; +import { LIMITED_STD_PROXYHANDLER_API } from './utils/consts/LimitedStdProxyHandlerAPI'; +import { ALLOWED_STD_SYMBOL_API } from './utils/consts/AllowedStdSymbolAPI'; +import { + NON_INITIALIZABLE_PROPERTY_DECORATORS, + NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS, +} from './utils/consts/NonInitializablePropertyDecorators'; import { NON_RETURN_FUNCTION_DECORATORS } from './utils/consts/NonReturnFunctionDecorators'; import { LIMITED_STANDARD_UTILITY_TYPES } from './utils/consts/LimitedStandardUtilityTypes'; import { PROPERTY_HAS_NO_INITIALIZER_ERROR_CODE } from './utils/consts/PropertyHasNoInitializerErrorCode'; import { FUNCTION_HAS_NO_RETURN_ERROR_CODE } from './utils/consts/FunctionHasNoReturnErrorCode'; -import { identiferUseInValueContext } from './utils/functions/identiferUseInValueContext' -import { hasPredecessor } from './utils/functions/HasPredecessor' +import { identiferUseInValueContext } from './utils/functions/identiferUseInValueContext'; +import { hasPredecessor } from './utils/functions/HasPredecessor'; import { scopeContainsThis } from './utils/functions/ContainsThis'; import { isStructDeclaration, isStruct } from './utils/functions/IsStruct'; import { isAssignmentOperator } from './utils/functions/isAssignmentOperator'; @@ -46,9 +53,8 @@ import { DiagnosticChecker } from './utils/functions/DiagnosticChecker'; import { ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE, TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE, - LibraryTypeCallDiagnosticChecker + LibraryTypeCallDiagnosticChecker, } from './utils/functions/LibraryTypeCallDiagnosticChecker'; -import { LIMITED_STD_API, LIMITED_STD_GLOBAL_API } from './utils/consts/LimitedStdApi'; const logger = Logger.getLogger(); @@ -64,14 +70,14 @@ export function consoleLog(...args: any[]): void { } export class TypeScriptLinter { - totalVisitedNodes: number = 0; + totalVisitedNodes = 0; nodeCounters: number[] = []; lineCounters: number[] = []; - totalErrorLines: number = 0; - errorLineNumbersString: string = ''; - totalWarningLines: number = 0; - warningLineNumbersString: string = ''; + totalErrorLines = 0; + errorLineNumbersString = ''; + totalWarningLines = 0; + warningLineNumbersString = ''; problemsInfos: ProblemInfo[] = []; @@ -85,8 +91,8 @@ export class TypeScriptLinter { private sourceFile?: ts.SourceFile; static filteredDiagnosticMessages: Set; - static ideMode: boolean = false; - static testMode: boolean = false; + static ideMode = false; + static testMode = false; static advancedClassChecks = false; @@ -104,12 +110,18 @@ export class TypeScriptLinter { private tscStrictDiagnostics?: Map, private reportAutofixCb?: ReportAutofixCallback ) { - this.tsUtils = new TsUtils(this.tsTypeChecker, TypeScriptLinter.testMode, TypeScriptLinter.advancedClassChecks); + this.tsUtils = new TsUtils( + this.tsTypeChecker, + TypeScriptLinter.testMode, + TypeScriptLinter.advancedClassChecks + ); this.currentErrorLine = 0; this.currentWarningLine = 0; this.staticBlocks = new Set(); this.walkedComments = new Set(); - this.libraryTypeCallDiagnosticChecker = new LibraryTypeCallDiagnosticChecker(TypeScriptLinter.filteredDiagnosticMessages); + this.libraryTypeCallDiagnosticChecker = new LibraryTypeCallDiagnosticChecker( + TypeScriptLinter.filteredDiagnosticMessages + ); for (let i = 0; i < FaultID.LAST_ID; i++) { this.nodeCounters[i] = 0; @@ -154,7 +166,6 @@ export class TypeScriptLinter { [ts.SyntaxKind.ElementAccessExpression, this.handleElementAccessExpression], [ts.SyntaxKind.EnumMember, this.handleEnumMember], [ts.SyntaxKind.TypeReference, this.handleTypeReference], - [ts.SyntaxKind.ExportDeclaration, this.handleExportDeclaration], [ts.SyntaxKind.ExportAssignment, this.handleExportAssignment], [ts.SyntaxKind.CallExpression, this.handleCallExpression], [ts.SyntaxKind.MetaProperty, this.handleMetaProperty], @@ -166,10 +177,17 @@ export class TypeScriptLinter { [ts.SyntaxKind.SetAccessor, this.handleSetAccessor], [ts.SyntaxKind.ConstructSignature, this.handleConstructSignature], [ts.SyntaxKind.ExpressionWithTypeArguments, this.handleExpressionWithTypeArguments], + [ts.SyntaxKind.ComputedPropertyName, this.handleComputedPropertyName], ]); - public incrementCounters(node: ts.Node | ts.CommentRange, faultId: number, autofixable: boolean = false, autofix?: Autofix[],) { - if (!this.strictMode && faultsAttrs[faultId].migratable) { // In relax mode skip migratable + public incrementCounters( + node: ts.Node | ts.CommentRange, + faultId: number, + autofixable = false, + autofix?: Autofix[] + ) { + if (!this.strictMode && faultsAttrs[faultId].migratable) { + // In relax mode skip migratable return; } const startPos = this.tsUtils.getStartPos(node); @@ -180,8 +198,8 @@ export class TypeScriptLinter { let { line, character } = this.sourceFile!.getLineAndCharacterOfPosition(startPos); ++line; ++character; - let faultDescr = faultDesc[faultId]; - let faultType = LinterConfig.tsSyntaxKindNames[node.kind]; + const faultDescr = faultDesc[faultId]; + const faultType = LinterConfig.tsSyntaxKindNames[node.kind]; if (TypeScriptLinter.ideMode) { const cookBookMsgNum = faultsAttrs[faultId] ? Number(faultsAttrs[faultId].cookBookRef) : 0; const cookBookTg = cookBookTag[cookBookMsgNum]; @@ -205,7 +223,8 @@ export class TypeScriptLinter { ruleTag: cookBookMsgNum, autofixable: autofixable, autofix: autofix, - autofixTitle: isMsgNumValid && autofixable ? cookBookRefToFixTitle.get(cookBookMsgNum) : undefined, + autofixTitle: + isMsgNumValid && autofixable ? cookBookRefToFixTitle.get(cookBookMsgNum) : undefined, }; this.problemsInfos.push(badNodeInfo); // problems with autofixes might be collected separately @@ -214,17 +233,19 @@ export class TypeScriptLinter { } } else { logger.info( - `Warning: ${this.sourceFile!.fileName} (${line}, ${character}): ${faultDescr ? faultDescr : faultType}` + `Warning: ${this.sourceFile!.fileName} (${line}, ${character}): ${ + faultDescr ? faultDescr : faultType + }` ); } this.lineCounters[faultId]++; if (faultsAttrs[faultId].warning) { - if (line != this.currentWarningLine) { + if (line !== this.currentWarningLine) { this.currentWarningLine = line; ++this.totalWarningLines; - this.warningLineNumbersString += line + ', ' + this.warningLineNumbersString += line + ', '; } - } else if (line != this.currentErrorLine) { + } else if (line !== this.currentErrorLine) { this.currentErrorLine = line; ++this.totalErrorLines; this.errorLineNumbersString += line + ', '; @@ -232,37 +253,39 @@ export class TypeScriptLinter { } private visitTSNode(node: ts.Node): void { - const self = this; - visitTSNodeImpl(node); - function visitTSNodeImpl(node: ts.Node): void { - if (node === null || node.kind === null) { - return; - } - if (self.incrementalLintInfo?.shouldSkipCheck(node)) { - return; - } + if (node === null || node.kind === null) { + return; + } + if (this.incrementalLintInfo?.shouldSkipCheck(node)) { + return; + } - self.totalVisitedNodes++; - if (isStructDeclaration(node)) { - self.handleStructDeclaration(node); - return; - } - self.handleComments(node); - if (LinterConfig.terminalTokens.has(node.kind)) { - return; - } - let incrementedType = LinterConfig.incrementOnlyTokens.get(node.kind); - if (incrementedType !== undefined) { - self.incrementCounters(node, incrementedType); - } else { - let handler = self.handlersMap.get(node.kind); - if (handler !== undefined) { - // possibly requested cancellation will be checked in a limited number of handlers - // checked nodes are selected as construct nodes, similar to how TSC does - handler.call(self, node); - } + this.totalVisitedNodes++; + if (isStructDeclaration(node)) { + this.handleStructDeclaration(node); + return; + } + this.handleComments(node); + if (LinterConfig.terminalTokens.has(node.kind)) { + return; + } + const incrementedType = LinterConfig.incrementOnlyTokens.get(node.kind); + if (incrementedType !== undefined) { + this.incrementCounters(node, incrementedType); + } else { + const handler = this.handlersMap.get(node.kind); + if (handler !== undefined) { + // possibly requested cancellation will be checked in a limited number of handlers + // checked nodes are selected as construct nodes, similar to how TSC does + handler.call(this, node); } - ts.forEachChild(node, visitTSNodeImpl); + } + + // #13972: The 'ts.forEachChild' doesn't iterate over in-between punctuation tokens. + // As result, we can miss comment directives attached to those. Instead, use 'node.getChildren()'. + // to traverse child nodes. + for (const child of node.getChildren()) { + this.visitTSNode(child); } } @@ -283,9 +306,12 @@ export class TypeScriptLinter { } } - private countDeclarationsWithDuplicateName(tsNode: ts.Node, tsDeclNode: ts.Node, tsDeclKind?: ts.SyntaxKind + private countDeclarationsWithDuplicateName( + tsNode: ts.Node, + tsDeclNode: ts.Node, + tsDeclKind?: ts.SyntaxKind ): void { - let symbol = this.tsTypeChecker.getSymbolAtLocation(tsNode); + const symbol = this.tsTypeChecker.getSymbolAtLocation(tsNode); // If specific declaration kind is provided, check against it. // Otherwise, use syntax kind of corresponding declaration node. if (!!symbol && this.tsUtils.symbolHasDuplicateName(symbol, tsDeclKind ?? tsDeclNode.kind)) { @@ -331,8 +357,12 @@ export class TypeScriptLinter { } } - private isPrototypePropertyAccess(tsPropertyAccess: ts.PropertyAccessExpression, propAccessSym: ts.Symbol | undefined, - baseExprSym: ts.Symbol | undefined, baseExprType: ts.Type): boolean { + private isPrototypePropertyAccess( + tsPropertyAccess: ts.PropertyAccessExpression, + propAccessSym: ts.Symbol | undefined, + baseExprSym: ts.Symbol | undefined, + baseExprType: ts.Type + ): boolean { if (!(ts.isIdentifier(tsPropertyAccess.name) && tsPropertyAccess.name.text === 'prototype')) { return false; } @@ -366,11 +396,21 @@ export class TypeScriptLinter { // The latter check is to cover cases with multiple prototype // chain (as the 'Prototype' property should be 'Any' type): // X.prototype.prototype.prototype = ... - const baseExprTypeNode = this.tsTypeChecker.typeToTypeNode(baseExprType, undefined, ts.NodeBuilderFlags.None); - return ((baseExprTypeNode && ts.isFunctionTypeNode(baseExprTypeNode)) || this.tsUtils.isAnyType(baseExprType)); + const baseExprTypeNode = this.tsTypeChecker.typeToTypeNode( + baseExprType, + undefined, + ts.NodeBuilderFlags.None + ); + return ( + (baseExprTypeNode && ts.isFunctionTypeNode(baseExprTypeNode)) || + this.tsUtils.isAnyType(baseExprType) + ); } - private interfaceInheritanceLint(node: ts.Node, heritageClauses: ts.NodeArray): void { + private interfaceInheritanceLint( + node: ts.Node, + heritageClauses: ts.NodeArray + ): void { for (const hClause of heritageClauses) { if (hClause.token !== ts.SyntaxKind.ExtendsKeyword) { continue; @@ -388,7 +428,9 @@ export class TypeScriptLinter { } private lintForInterfaceExtendsDifferentPorpertyTypes( - node: ts.Node, tsExprType: ts.Type, prop2type: Map + node: ts.Node, + tsExprType: ts.Type, + prop2type: Map ): void { const props = tsExprType.getProperties(); for (const p of props) { @@ -405,16 +447,18 @@ export class TypeScriptLinter { } private handleObjectLiteralExpression(node: ts.Node) { - let objectLiteralExpr = node as ts.ObjectLiteralExpression; + const objectLiteralExpr = node as ts.ObjectLiteralExpression; // If object literal is a part of destructuring assignment, then don't process it further. if (this.tsUtils.isDestructuringAssignmentLHS(objectLiteralExpr)) { return; } // issue 13082: Allow initializing struct instances with object literal. - let objectLiteralType = this.tsTypeChecker.getContextualType(objectLiteralExpr); - if (!this.tsUtils.isStructObjectInitializer(objectLiteralExpr) && - !this.tsUtils.isDynamicLiteralInitializer(objectLiteralExpr) && - !this.tsUtils.isObjectLiteralAssignable(objectLiteralType, objectLiteralExpr)) { + const objectLiteralType = this.tsTypeChecker.getContextualType(objectLiteralExpr); + if ( + !this.tsUtils.isStructObjectInitializer(objectLiteralExpr) && + !this.tsUtils.isDynamicLiteralInitializer(objectLiteralExpr) && + !this.tsUtils.isObjectLiteralAssignable(objectLiteralType, objectLiteralExpr) + ) { this.incrementCounters(node, FaultID.ObjectLiteralNoContextType); } } @@ -425,16 +469,18 @@ export class TypeScriptLinter { if (this.tsUtils.isDestructuringAssignmentLHS(node as ts.ArrayLiteralExpression)) { return; } - let arrayLitNode = node as ts.ArrayLiteralExpression; + const arrayLitNode = node as ts.ArrayLiteralExpression; let noContextTypeForArrayLiteral = false; // check that array literal consists of inferrable types // e.g. there is no element which is untyped object literals - let arrayLitElements = arrayLitNode.elements; - for(let element of arrayLitElements ) { - if(ts.isObjectLiteralExpression(element)) { - let objectLiteralType = this.tsTypeChecker.getContextualType(element); - if (!this.tsUtils.isDynamicLiteralInitializer(arrayLitNode) && - !this.tsUtils.isObjectLiteralAssignable(objectLiteralType, element)) { + const arrayLitElements = arrayLitNode.elements; + for (const element of arrayLitElements) { + if (ts.isObjectLiteralExpression(element)) { + const objectLiteralType = this.tsTypeChecker.getContextualType(element); + if ( + !this.tsUtils.isDynamicLiteralInitializer(arrayLitNode) && + !this.tsUtils.isObjectLiteralAssignable(objectLiteralType, element) + ) { noContextTypeForArrayLiteral = true; break; } @@ -446,11 +492,11 @@ export class TypeScriptLinter { } private handleParameter(node: ts.Node) { - let tsParam = node as ts.ParameterDeclaration; + const tsParam = node as ts.ParameterDeclaration; if (ts.isArrayBindingPattern(tsParam.name) || ts.isObjectBindingPattern(tsParam.name)) { this.incrementCounters(node, FaultID.DestructuringParameter); } - let tsParamMods = ts.getModifiers(tsParam); + const tsParamMods = ts.getModifiers(tsParam); if ( tsParamMods && (this.tsUtils.hasModifier(tsParamMods, ts.SyntaxKind.PublicKeyword) || @@ -465,13 +511,13 @@ export class TypeScriptLinter { } private handleEnumDeclaration(node: ts.Node) { - let enumNode = node as ts.EnumDeclaration; + const enumNode = node as ts.EnumDeclaration; this.countDeclarationsWithDuplicateName(enumNode.name, enumNode); - let enumSymbol = this.tsUtils.trueSymbolAtLocation(enumNode.name); + const enumSymbol = this.tsUtils.trueSymbolAtLocation(enumNode.name); if (!enumSymbol) { return; } - let enumDecls = enumSymbol.getDeclarations(); + const enumDecls = enumSymbol.getDeclarations(); if (!enumDecls) { return; } @@ -481,7 +527,9 @@ export class TypeScriptLinter { // See 'countDeclarationsWithDuplicateName' method for details. let enumDeclCount = 0; for (const decl of enumDecls) { - if (decl.kind === ts.SyntaxKind.EnumDeclaration) enumDeclCount++; + if (decl.kind === ts.SyntaxKind.EnumDeclaration) { + enumDeclCount++; + } } if (enumDeclCount > 1) { this.incrementCounters(node, FaultID.EnumMerging); @@ -492,9 +540,9 @@ export class TypeScriptLinter { // early exit via exception if cancellation was requested this.cancellationToken?.throwIfCancellationRequested(); - let interfaceNode = node as ts.InterfaceDeclaration; - let iSymbol = this.tsUtils.trueSymbolAtLocation(interfaceNode.name); - let iDecls = iSymbol ? iSymbol.getDeclarations() : null; + const interfaceNode = node as ts.InterfaceDeclaration; + const iSymbol = this.tsUtils.trueSymbolAtLocation(interfaceNode.name); + const iDecls = iSymbol ? iSymbol.getDeclarations() : null; if (iDecls) { // Since type checker merges all declarations with the same name // into one symbol, we need to check that there's more than one @@ -502,7 +550,9 @@ export class TypeScriptLinter { // See 'countDeclarationsWithDuplicateName' method for details. let iDeclCount = 0; for (const decl of iDecls) { - if (decl.kind === ts.SyntaxKind.InterfaceDeclaration) iDeclCount++; + if (decl.kind === ts.SyntaxKind.InterfaceDeclaration) { + iDeclCount++; + } } if (iDeclCount > 1) { this.incrementCounters(node, FaultID.InterfaceMerging); @@ -515,24 +565,30 @@ export class TypeScriptLinter { } private handleThrowStatement(node: ts.Node) { - let throwStmt = node as ts.ThrowStatement; - let throwExprType = this.tsTypeChecker.getTypeAtLocation(throwStmt.expression); - if (!throwExprType.isClassOrInterface() || !this.tsUtils.isDerivedFrom(throwExprType, CheckType.Error)) { + const throwStmt = node as ts.ThrowStatement; + const throwExprType = this.tsTypeChecker.getTypeAtLocation(throwStmt.expression); + if ( + !throwExprType.isClassOrInterface() || + !this.tsUtils.isOrDerivedFrom(throwExprType, this.tsUtils.isStdErrorType) + ) { this.incrementCounters(node, FaultID.ThrowStatement, false, undefined); } } private handleForStatement(node: ts.Node) { - let tsForStmt = node as ts.ForStatement; - let tsForInit = tsForStmt.initializer; - if (tsForInit && (ts.isArrayLiteralExpression(tsForInit) || ts.isObjectLiteralExpression(tsForInit))) { + const tsForStmt = node as ts.ForStatement; + const tsForInit = tsForStmt.initializer; + if ( + tsForInit && + (ts.isArrayLiteralExpression(tsForInit) || ts.isObjectLiteralExpression(tsForInit)) + ) { this.incrementCounters(tsForInit, FaultID.DestructuringAssignment); } } private handleForInStatement(node: ts.Node) { - let tsForInStmt = node as ts.ForInStatement; - let tsForInInit = tsForInStmt.initializer; + const tsForInStmt = node as ts.ForInStatement; + const tsForInInit = tsForInStmt.initializer; if (ts.isArrayLiteralExpression(tsForInInit) || ts.isObjectLiteralExpression(tsForInInit)) { this.incrementCounters(tsForInInit, FaultID.DestructuringAssignment); } @@ -540,8 +596,8 @@ export class TypeScriptLinter { } private handleForOfStatement(node: ts.Node) { - let tsForOfStmt = node as ts.ForOfStatement; - let tsForOfInit = tsForOfStmt.initializer; + const tsForOfStmt = node as ts.ForOfStatement; + const tsForOfInit = tsForOfStmt.initializer; if (ts.isArrayLiteralExpression(tsForOfInit) || ts.isObjectLiteralExpression(tsForOfInit)) { this.incrementCounters(tsForOfInit, FaultID.DestructuringAssignment); } @@ -551,7 +607,7 @@ export class TypeScriptLinter { // early exit via exception if cancellation was requested this.cancellationToken?.throwIfCancellationRequested(); - let importDeclNode = node as ts.ImportDeclaration; + const importDeclNode = node as ts.ImportDeclaration; for (const stmt of importDeclNode.parent.statements) { if (stmt === importDeclNode) { break; @@ -561,7 +617,7 @@ export class TypeScriptLinter { break; } } - let expr1 = importDeclNode.moduleSpecifier; + const expr1 = importDeclNode.moduleSpecifier; if (expr1.kind === ts.SyntaxKind.StringLiteral) { if (!importDeclNode.importClause) { this.incrementCounters(node, FaultID.ImportFromPath); @@ -573,39 +629,61 @@ export class TypeScriptLinter { } private handlePropertyAccessExpression(node: ts.Node) { - let propertyAccessNode = node as ts.PropertyAccessExpression; + if (ts.isCallExpression(node.parent) && node === node.parent.expression) { + return; + } + + const propertyAccessNode = node as ts.PropertyAccessExpression; const exprSym = this.tsUtils.trueSymbolAtLocation(propertyAccessNode); const baseExprSym = this.tsUtils.trueSymbolAtLocation(propertyAccessNode.expression); const baseExprType = this.tsTypeChecker.getTypeAtLocation(propertyAccessNode.expression); - if (!!baseExprSym && this.tsUtils.symbolHasEsObjectType(baseExprSym)) { - this.incrementCounters(propertyAccessNode, FaultID.EsObjectType); - } - if (this.isPrototypePropertyAccess(propertyAccessNode, exprSym, baseExprSym, baseExprType)) { + if (this.isPrototypePropertyAccess(propertyAccessNode, exprSym, baseExprSym, baseExprType)) { this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); } - if (TypeScriptLinter.advancedClassChecks && this.tsUtils.isClassObjectExpression(propertyAccessNode.expression)) { + if ( + !!exprSym && + this.tsUtils.isSymbolAPI(exprSym) && + !ALLOWED_STD_SYMBOL_API.includes(exprSym.getName()) + ) { + this.incrementCounters(propertyAccessNode, FaultID.SymbolType); + } + if ( + TypeScriptLinter.advancedClassChecks && + this.tsUtils.isClassObjectExpression(propertyAccessNode.expression) + ) { // missing exact rule this.incrementCounters(propertyAccessNode.expression, FaultID.ClassAsObject); } + if (!!baseExprSym && this.tsUtils.symbolHasEsObjectType(baseExprSym)) { + this.incrementCounters(propertyAccessNode, FaultID.EsObjectType); + } } private handlePropertyAssignmentOrDeclaration(node: ts.Node) { - let propName = (node as ts.PropertyAssignment | ts.PropertyDeclaration).name; - if (propName && (propName.kind === ts.SyntaxKind.NumericLiteral || propName.kind === ts.SyntaxKind.StringLiteral)) { + const propName = (node as ts.PropertyAssignment | ts.PropertyDeclaration).name; + if ( + propName && + (propName.kind === ts.SyntaxKind.NumericLiteral || + propName.kind === ts.SyntaxKind.StringLiteral) + ) { // We can use literals as property names only when creating Record or any interop instances. let isRecordObjectInitializer = false; - let isDynamicLiteralInitializer = false; + let isDynamic = false; if (ts.isPropertyAssignment(node)) { - let objectLiteralType = this.tsTypeChecker.getContextualType(node.parent); - isRecordObjectInitializer = !!objectLiteralType && this.tsUtils.isStdRecordType(objectLiteralType); - isDynamicLiteralInitializer = this.tsUtils.isDynamicLiteralInitializer(node.parent); + const objectLiteralType = this.tsTypeChecker.getContextualType(node.parent); + if (objectLiteralType) { + isRecordObjectInitializer = this.tsUtils.isStdRecordType(objectLiteralType); + isDynamic = + this.tsUtils.isLibraryType(objectLiteralType) || + this.tsUtils.isDynamicLiteralInitializer(node.parent); + } } - if (!isRecordObjectInitializer && !isDynamicLiteralInitializer) { - let autofix : Autofix[] | undefined = Autofixer.fixLiteralAsPropertyName(node); - let autofixable = autofix != undefined; + if (!isRecordObjectInitializer && !isDynamic) { + let autofix: Autofix[] | undefined = Autofixer.fixLiteralAsPropertyName(node); + const autofixable = autofix !== undefined; if (!this.autofixesInfo.shouldAutofix(node, FaultID.LiteralAsPropertyName)) { autofix = undefined; } @@ -615,13 +693,22 @@ export class TypeScriptLinter { if (ts.isPropertyDeclaration(node)) { const decorators = ts.getDecorators(node); this.handleDecorators(decorators); - this.filterOutDecoratorsDiagnostics(decorators, NON_INITIALIZABLE_PROPERTY_DECORATORS, - {begin: propName.getStart(), end: propName.getStart()}, PROPERTY_HAS_NO_INITIALIZER_ERROR_CODE); - + this.filterOutDecoratorsDiagnostics( + decorators, + NON_INITIALIZABLE_PROPERTY_DECORATORS, + { begin: propName.getStart(), end: propName.getStart() }, + PROPERTY_HAS_NO_INITIALIZER_ERROR_CODE + ); + const classDecorators = ts.getDecorators(node.parent); const propType = (node as ts.PropertyDeclaration).type?.getText(); - this.filterOutDecoratorsDiagnostics(classDecorators, NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS, - {begin: propName.getStart(), end: propName.getStart()}, PROPERTY_HAS_NO_INITIALIZER_ERROR_CODE, propType); + this.filterOutDecoratorsDiagnostics( + classDecorators, + NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS, + { begin: propName.getStart(), end: propName.getStart() }, + PROPERTY_HAS_NO_INITIALIZER_ERROR_CODE, + propType + ); this.handleDeclarationInferredType(node); this.handleDefiniteAssignmentAssertion(node); } @@ -630,56 +717,57 @@ export class TypeScriptLinter { private filterOutDecoratorsDiagnostics( decorators: readonly ts.Decorator[] | undefined, expectedDecorators: readonly string[], - range: {begin: number, end: number}, + range: { begin: number; end: number }, code: number, propType?: string ) { // Filter out non-initializable property decorators from strict diagnostics. if (this.tscStrictDiagnostics && this.sourceFile) { - if (decorators?.some(x => { - let decoratorName = ''; - if (ts.isIdentifier(x.expression)) { - decoratorName = x.expression.text; - } else if (ts.isCallExpression(x.expression) && ts.isIdentifier(x.expression.expression)) { - decoratorName = x.expression.expression.text; - } - // special case for property of type CustomDialogController of the @CustomDialog-decorated class - if (expectedDecorators.includes(NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS[0])) { - return expectedDecorators.includes(decoratorName) && propType === 'CustomDialogController' - } - return expectedDecorators.includes(decoratorName); - })) { - let file = path.normalize(this.sourceFile.fileName); - let tscDiagnostics = this.tscStrictDiagnostics.get(file) + if ( + decorators?.some(x => { + let decoratorName = ''; + if (ts.isIdentifier(x.expression)) { + decoratorName = x.expression.text; + } else if ( + ts.isCallExpression(x.expression) && + ts.isIdentifier(x.expression.expression) + ) { + decoratorName = x.expression.expression.text; + } + // special case for property of type CustomDialogController of the @CustomDialog-decorated class + if (expectedDecorators.includes(NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS[0])) { + return ( + expectedDecorators.includes(decoratorName) && propType === 'CustomDialogController' + ); + } + return expectedDecorators.includes(decoratorName); + }) + ) { + const file = path.normalize(this.sourceFile.fileName); + const tscDiagnostics = this.tscStrictDiagnostics.get(file); if (tscDiagnostics) { - let filteredDiagnostics = tscDiagnostics.filter( - (val, idx, array) => { - if (val.code !== code) { - return true; - } - - if (val.start === undefined) { - return true; - } - - if (val.start < range.begin) { - return true; - } - - if (val.start > range.end) { - return true; - } - - return false; + const filteredDiagnostics = tscDiagnostics.filter(val => { + if (val.code !== code) { + return true; } - ); + if (val.start === undefined) { + return true; + } + if (val.start < range.begin) { + return true; + } + if (val.start > range.end) { + return true; + } + return false; + }); this.tscStrictDiagnostics.set(file, filteredDiagnostics); } } } } - private checkInRange(rangesToFilter: { begin: number, end: number }[], pos: number): boolean { + private checkInRange(rangesToFilter: { begin: number; end: number }[], pos: number): boolean { for (let i = 0; i < rangesToFilter.length; i++) { if (pos >= rangesToFilter[i].begin && pos < rangesToFilter[i].end) { return false; @@ -688,13 +776,15 @@ export class TypeScriptLinter { return true; } - private filterStrictDiagnostics(filters: { [code: number]: (pos: number) => boolean }, - diagnosticChecker: DiagnosticChecker): boolean { + private filterStrictDiagnostics( + filters: { [code: number]: (pos: number) => boolean }, + diagnosticChecker: DiagnosticChecker + ): boolean { if (!this.tscStrictDiagnostics || !this.sourceFile) { return false; } - let file = path.normalize(this.sourceFile.fileName); - let tscDiagnostics = this.tscStrictDiagnostics.get(file) + const file = path.normalize(this.sourceFile.fileName); + const tscDiagnostics = this.tscStrictDiagnostics.get(file); if (!tscDiagnostics) { return false; } @@ -721,16 +811,28 @@ export class TypeScriptLinter { const funcExpr = node as ts.FunctionExpression; const isGenerator = funcExpr.asteriskToken !== undefined; const containsThis = scopeContainsThis(funcExpr.body); - const hasValidContext = hasPredecessor(funcExpr, ts.isClassLike) || - hasPredecessor(funcExpr, ts.isInterfaceDeclaration); + const hasValidContext = + hasPredecessor(funcExpr, ts.isClassLike) || + hasPredecessor(funcExpr, ts.isInterfaceDeclaration); const isGeneric = funcExpr.typeParameters !== undefined && funcExpr.typeParameters.length > 0; const isCalledRecursively = this.tsUtils.isFunctionCalledRecursively(funcExpr); const [hasUnfixableReturnType, newRetTypeNode] = this.handleMissingReturnType(funcExpr); - const autofixable = !isGeneric && !isGenerator && !containsThis && !hasUnfixableReturnType && + const autofixable = + !isGeneric && + !isGenerator && + !containsThis && + !hasUnfixableReturnType && !isCalledRecursively; let autofix: Autofix[] | undefined; if (autofixable && this.autofixesInfo.shouldAutofix(node, FaultID.FunctionExpression)) { - autofix = [ Autofixer.fixFunctionExpression(funcExpr, funcExpr.parameters, newRetTypeNode, ts.getModifiers(funcExpr)) ]; + autofix = [ + Autofixer.fixFunctionExpression( + funcExpr, + funcExpr.parameters, + newRetTypeNode, + ts.getModifiers(funcExpr) + ), + ]; } this.incrementCounters(node, FaultID.FunctionExpression, autofixable, autofix); if (isGeneric) { @@ -750,8 +852,9 @@ export class TypeScriptLinter { private handleArrowFunction(node: ts.Node) { const arrowFunc = node as ts.ArrowFunction; const containsThis = scopeContainsThis(arrowFunc.body); - const hasValidContext = hasPredecessor(arrowFunc, ts.isClassLike) || - hasPredecessor(arrowFunc, ts.isInterfaceDeclaration); + const hasValidContext = + hasPredecessor(arrowFunc, ts.isClassLike) || + hasPredecessor(arrowFunc, ts.isInterfaceDeclaration); if (containsThis && !hasValidContext) { this.incrementCounters(arrowFunc, FaultID.FunctionContainsThis); } @@ -767,7 +870,7 @@ export class TypeScriptLinter { } private handleClassExpression(node: ts.Node) { - let tsClassExpr = node as ts.ClassExpression; + const tsClassExpr = node as ts.ClassExpression; this.incrementCounters(node, FaultID.ClassExpression); this.handleDecorators(ts.getDecorators(tsClassExpr)); } @@ -776,7 +879,7 @@ export class TypeScriptLinter { // early exit via exception if cancellation was requested this.cancellationToken?.throwIfCancellationRequested(); - let tsFunctionDeclaration = node as ts.FunctionDeclaration; + const tsFunctionDeclaration = node as ts.FunctionDeclaration; if (!tsFunctionDeclaration.type) { this.handleMissingReturnType(tsFunctionDeclaration); } @@ -786,7 +889,10 @@ export class TypeScriptLinter { if (tsFunctionDeclaration.body && scopeContainsThis(tsFunctionDeclaration.body)) { this.incrementCounters(node, FaultID.FunctionContainsThis); } - if (!ts.isSourceFile(tsFunctionDeclaration.parent) && !ts.isModuleBlock(tsFunctionDeclaration.parent)) { + if ( + !ts.isSourceFile(tsFunctionDeclaration.parent) && + !ts.isModuleBlock(tsFunctionDeclaration.parent) + ) { this.incrementCounters(tsFunctionDeclaration, FaultID.LocalFunction); } if (tsFunctionDeclaration.asteriskToken) { @@ -794,11 +900,14 @@ export class TypeScriptLinter { } } - private handleMissingReturnType(funcLikeDecl: ts.FunctionLikeDeclaration | ts.MethodSignature): [boolean, ts.TypeNode | undefined] { + private handleMissingReturnType( + funcLikeDecl: ts.FunctionLikeDeclaration | ts.MethodSignature + ): [boolean, ts.TypeNode | undefined] { // Note: Return type can't be inferred for function without body. const isSignature = ts.isMethodSignature(funcLikeDecl); if (isSignature || !funcLikeDecl.body) { // Ambient flag is not exposed, so we apply dirty hack to make it visible + // eslint-disable-next-line @typescript-eslint/no-explicit-any const isAmbientDeclaration = !!(funcLikeDecl.flags & (ts.NodeFlags as any)['Ambient']); if ((isSignature || isAmbientDeclaration) && !funcLikeDecl.type) { this.incrementCounters(funcLikeDecl, FaultID.LimitedReturnTypeInference); @@ -806,20 +915,24 @@ export class TypeScriptLinter { return [false, undefined]; } let autofixable = false; - let autofix : Autofix[] | undefined; + let autofix: Autofix[] | undefined; let newRetTypeNode: ts.TypeNode | undefined; - let isFuncExpr = ts.isFunctionExpression(funcLikeDecl); + const isFuncExpr = ts.isFunctionExpression(funcLikeDecl); // Currently, ArkTS can't infer return type of function, when expression // in the return statement is a call to a function or method whose return // value type is omitted. In that case, we attempt to prepare an autofix. let hasLimitedRetTypeInference = this.hasLimitedTypeInferenceFromReturnExpr(funcLikeDecl.body); - let tsSignature = this.tsTypeChecker.getSignatureFromDeclaration(funcLikeDecl); + const tsSignature = this.tsTypeChecker.getSignatureFromDeclaration(funcLikeDecl); if (tsSignature) { - let tsRetType = this.tsTypeChecker.getReturnTypeOfSignature(tsSignature); + const tsRetType = this.tsTypeChecker.getReturnTypeOfSignature(tsSignature); if (!tsRetType || this.tsUtils.isUnsupportedType(tsRetType)) { hasLimitedRetTypeInference = true; } else if (hasLimitedRetTypeInference) { - newRetTypeNode = this.tsTypeChecker.typeToTypeNode(tsRetType, funcLikeDecl, ts.NodeBuilderFlags.None); + newRetTypeNode = this.tsTypeChecker.typeToTypeNode( + tsRetType, + funcLikeDecl, + ts.NodeBuilderFlags.None + ); if (newRetTypeNode && !isFuncExpr) { autofixable = true; if (this.autofixesInfo.shouldAutofix(funcLikeDecl, FaultID.LimitedReturnTypeInference)) { @@ -831,25 +944,29 @@ export class TypeScriptLinter { // Don't report here if in function expression context. // See handleFunctionExpression for details. if (hasLimitedRetTypeInference && !isFuncExpr) { - this.incrementCounters(funcLikeDecl, FaultID.LimitedReturnTypeInference, autofixable, autofix); + this.incrementCounters( + funcLikeDecl, + FaultID.LimitedReturnTypeInference, + autofixable, + autofix + ); } return [hasLimitedRetTypeInference && !newRetTypeNode, newRetTypeNode]; } private hasLimitedTypeInferenceFromReturnExpr(funBody: ts.ConciseBody): boolean { let hasLimitedTypeInference = false; - const self = this; - function visitNode(tsNode: ts.Node): void { - if (hasLimitedTypeInference) { - return; - } + const visitNode = (tsNode: ts.Node) => { if ( - ts.isReturnStatement(tsNode) && tsNode.expression && - self.tsUtils.isCallToFunctionWithOmittedReturnType(self.tsUtils.unwrapParenthesized(tsNode.expression)) + ts.isReturnStatement(tsNode) && + tsNode.expression && + this.tsUtils.isCallToFunctionWithOmittedReturnType( + this.tsUtils.unwrapParenthesized(tsNode.expression) + ) ) { - hasLimitedTypeInference = true; - return; + return true; } + // Visit children nodes. Don't traverse other nested function-like declarations. if ( !ts.isFunctionDeclaration(tsNode) && @@ -857,11 +974,17 @@ export class TypeScriptLinter { !ts.isMethodDeclaration(tsNode) && !ts.isAccessor(tsNode) && !ts.isArrowFunction(tsNode) - ) - tsNode.forEachChild(visitNode); - } + ) { + for (const child of tsNode.getChildren()) { + if (visitNode(child)) { + return true; + } + } + } + return false; + }; if (ts.isBlock(funBody)) { - visitNode(funBody); + hasLimitedTypeInference = visitNode(funBody); } else { const tsExpr = this.tsUtils.unwrapParenthesized(funBody); hasLimitedTypeInference = this.tsUtils.isCallToFunctionWithOmittedReturnType(tsExpr); @@ -870,19 +993,22 @@ export class TypeScriptLinter { } private handlePrefixUnaryExpression(node: ts.Node) { - let tsUnaryArithm = node as ts.PrefixUnaryExpression; - let tsUnaryOp = tsUnaryArithm.operator; + const tsUnaryArithm = node as ts.PrefixUnaryExpression; + const tsUnaryOp = tsUnaryArithm.operator; if ( tsUnaryOp === ts.SyntaxKind.PlusToken || tsUnaryOp === ts.SyntaxKind.MinusToken || tsUnaryOp === ts.SyntaxKind.TildeToken ) { const tsOperatndType = this.tsTypeChecker.getTypeAtLocation(tsUnaryArithm.operand); - if (!(tsOperatndType.getFlags() & (ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLiteral)) || - ( tsUnaryOp === ts.SyntaxKind.TildeToken && tsUnaryArithm.operand.kind === ts.SyntaxKind.NumericLiteral && - !this.tsUtils.isIntegerConstantValue(tsUnaryArithm.operand as ts.NumericLiteral) ) - ) + if ( + !(tsOperatndType.getFlags() & (ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLiteral)) || + (tsUnaryOp === ts.SyntaxKind.TildeToken && + tsUnaryArithm.operand.kind === ts.SyntaxKind.NumericLiteral && + !this.tsUtils.isIntegerConstantValue(tsUnaryArithm.operand as ts.NumericLiteral)) + ) { this.incrementCounters(node, FaultID.UnaryArithmNotNumber); + } } } @@ -904,8 +1030,13 @@ export class TypeScriptLinter { case ts.SyntaxKind.InstanceOfKeyword: this.processBinaryInstanceOf(node, tsLhsExpr, leftOperandType); break; + case ts.SyntaxKind.InKeyword: + this.incrementCounters(tsBinaryExpr.operatorToken, FaultID.InOperator); + break; case ts.SyntaxKind.EqualsToken: - if (this.tsUtils.needToDeduceStructuralIdentity(leftOperandType, rightOperandType, tsRhsExpr)) { + if ( + this.tsUtils.needToDeduceStructuralIdentity(leftOperandType, rightOperandType, tsRhsExpr) + ) { this.incrementCounters(tsBinaryExpr, FaultID.StructuralIdentity); } this.handleEsObjectAssignment(tsBinaryExpr, typeNode, tsRhsExpr); @@ -922,14 +1053,16 @@ export class TypeScriptLinter { if (ts.isPropertyAccessExpression(tsLhsExpr)) { const tsLhsSymbol = this.tsUtils.trueSymbolAtLocation(tsLhsExpr); const tsLhsBaseSymbol = this.tsUtils.trueSymbolAtLocation(tsLhsExpr.expression); - if (tsLhsSymbol && (tsLhsSymbol.flags & ts.SymbolFlags.Method)) { + if (tsLhsSymbol && tsLhsSymbol.flags & ts.SymbolFlags.Method) { this.incrementCounters(tsLhsExpr, FaultID.MethodReassignment); } if ( - this.tsUtils.isMethodAssignment(tsLhsSymbol) && tsLhsBaseSymbol && + this.tsUtils.isMethodAssignment(tsLhsSymbol) && + tsLhsBaseSymbol && (tsLhsBaseSymbol.flags & ts.SymbolFlags.Function) !== 0 - ) + ) { this.incrementCounters(tsLhsExpr, FaultID.PropertyDeclOnFunction); + } } } @@ -943,12 +1076,18 @@ export class TypeScriptLinter { } if (tsParentNode && tsParentNode.kind === ts.SyntaxKind.ForStatement) { const tsForNode = tsParentNode as ts.ForStatement; - if (tsExprNode === tsForNode.initializer || tsExprNode === tsForNode.incrementor) return; + if (tsExprNode === tsForNode.initializer || tsExprNode === tsForNode.incrementor) { + return; + } } this.incrementCounters(tsBinaryExpr as ts.Node, FaultID.CommaOperator); } - private processBinaryInstanceOf(node: ts.Node, tsLhsExpr: ts.Expression, leftOperandType: ts.Type) { + private processBinaryInstanceOf( + node: ts.Node, + tsLhsExpr: ts.Expression, + leftOperandType: ts.Type + ) { const leftExpr = this.tsUtils.unwrapParenthesized(tsLhsExpr); const leftSymbol = this.tsUtils.trueSymbolAtLocation(leftExpr); // In STS, the left-hand side expression may be of any reference type, otherwise @@ -957,31 +1096,43 @@ export class TypeScriptLinter { return; } - if (this.tsUtils.isPrimitiveType(leftOperandType) || ts.isTypeNode(leftExpr) || this.tsUtils.isTypeSymbol(leftSymbol)) { + if ( + this.tsUtils.isPrimitiveType(leftOperandType) || + ts.isTypeNode(leftExpr) || + this.tsUtils.isTypeSymbol(leftSymbol) + ) { this.incrementCounters(node, FaultID.InstanceofUnsupported); } } private handleVariableDeclarationList(node: ts.Node) { - let varDeclFlags = ts.getCombinedNodeFlags(node); - if (!(varDeclFlags & (ts.NodeFlags.Let | ts.NodeFlags.Const))) + const varDeclFlags = ts.getCombinedNodeFlags(node); + if (!(varDeclFlags & (ts.NodeFlags.Let | ts.NodeFlags.Const))) { this.incrementCounters(node, FaultID.VarDeclaration); + } } private handleVariableDeclaration(node: ts.Node) { - let tsVarDecl = node as ts.VariableDeclaration; - if (ts.isArrayBindingPattern(tsVarDecl.name) || ts.isObjectBindingPattern(tsVarDecl.name)) + const tsVarDecl = node as ts.VariableDeclaration; + if (ts.isArrayBindingPattern(tsVarDecl.name) || ts.isObjectBindingPattern(tsVarDecl.name)) { this.incrementCounters(node, FaultID.DestructuringDeclaration); + } { // Check variable declaration for duplicate name. const visitBindingPatternNames = (tsBindingName: ts.BindingName) => { if (ts.isIdentifier(tsBindingName)) { // The syntax kind of the declaration is defined here by the parent of 'BindingName' node. - this.countDeclarationsWithDuplicateName(tsBindingName, tsBindingName, tsBindingName.parent.kind); + this.countDeclarationsWithDuplicateName( + tsBindingName, + tsBindingName, + tsBindingName.parent.kind + ); return; } for (const tsBindingElem of tsBindingName.elements) { - if (ts.isOmittedExpression(tsBindingElem)) continue; + if (ts.isOmittedExpression(tsBindingElem)) { + continue; + } visitBindingPatternNames(tsBindingElem.name); } @@ -989,9 +1140,9 @@ export class TypeScriptLinter { visitBindingPatternNames(tsVarDecl.name); } if (tsVarDecl.type && tsVarDecl.initializer) { - let tsVarInit = tsVarDecl.initializer; - let tsVarType = this.tsTypeChecker.getTypeAtLocation(tsVarDecl.type); - let tsInitType = this.tsTypeChecker.getTypeAtLocation(tsVarInit); + const tsVarInit = tsVarDecl.initializer; + const tsVarType = this.tsTypeChecker.getTypeAtLocation(tsVarDecl.type); + const tsInitType = this.tsTypeChecker.getTypeAtLocation(tsVarInit); if (this.tsUtils.needToDeduceStructuralIdentity(tsVarType, tsInitType, tsVarInit)) { this.incrementCounters(tsVarDecl, FaultID.StructuralIdentity); } @@ -1003,9 +1154,11 @@ export class TypeScriptLinter { private handleEsObjectDelaration(node: ts.VariableDeclaration) { const isDeclaredESObject = !!node.type && this.tsUtils.isEsObjectType(node.type); - const initalizerTypeNode = node.initializer && this.tsUtils.getVariableDeclarationTypeNode(node.initializer); - const isInitializedWithESObject = !!initalizerTypeNode && this.tsUtils.isEsObjectType(initalizerTypeNode); - const isLocal = this.tsUtils.isInsideBlock(node) + const initalizerTypeNode = + node.initializer && this.tsUtils.getVariableDeclarationTypeNode(node.initializer); + const isInitializedWithESObject = + !!initalizerTypeNode && this.tsUtils.isEsObjectType(initalizerTypeNode); + const isLocal = this.tsUtils.isInsideBlock(node); if ((isDeclaredESObject || isInitializedWithESObject) && !isLocal) { this.incrementCounters(node, FaultID.EsObjectType); return; @@ -1016,11 +1169,16 @@ export class TypeScriptLinter { } } - private handleEsObjectAssignment(node: ts.Node, nodeDeclType: ts.TypeNode | undefined, initializer: ts.Node) { + private handleEsObjectAssignment( + node: ts.Node, + nodeDeclType: ts.TypeNode | undefined, + initializer: ts.Node + ) { const isTypeAnnotated = !!nodeDeclType; const isDeclaredESObject = isTypeAnnotated && this.tsUtils.isEsObjectType(nodeDeclType); const initalizerTypeNode = this.tsUtils.getVariableDeclarationTypeNode(initializer); - const isInitializedWithESObject = !!initalizerTypeNode && this.tsUtils.isEsObjectType(initalizerTypeNode); + const isInitializedWithESObject = + !!initalizerTypeNode && this.tsUtils.isEsObjectType(initalizerTypeNode); if (isTypeAnnotated && !isDeclaredESObject && isInitializedWithESObject) { this.incrementCounters(node, FaultID.EsObjectType); return; @@ -1032,15 +1190,16 @@ export class TypeScriptLinter { } private handleCatchClause(node: ts.Node) { - let tsCatch = node as ts.CatchClause; + const tsCatch = node as ts.CatchClause; // In TS catch clause doesn't permit specification of the exception varible type except 'any' or 'unknown'. // It is not compatible with STS 'catch' where the exception variable has to be of type // Error or derived from it. // So each 'catch' which has explicit type for the exception object goes to problems in strict mode. if (tsCatch.variableDeclaration && tsCatch.variableDeclaration.type) { let autofix: Autofix[] | undefined; - if (this.autofixesInfo.shouldAutofix(tsCatch, FaultID.CatchWithUnsupportedType)) - autofix = [ Autofixer.dropTypeOnVarDecl(tsCatch.variableDeclaration) ]; + if (this.autofixesInfo.shouldAutofix(tsCatch, FaultID.CatchWithUnsupportedType)) { + autofix = [Autofixer.dropTypeOnVarDecl(tsCatch.variableDeclaration)]; + } this.incrementCounters(node, FaultID.CatchWithUnsupportedType, true, autofix); } } @@ -1049,7 +1208,7 @@ export class TypeScriptLinter { // early exit via exception if cancellation was requested this.cancellationToken?.throwIfCancellationRequested(); - let tsClassDecl = node as ts.ClassDeclaration; + const tsClassDecl = node as ts.ClassDeclaration; this.staticBlocks.clear(); if (tsClassDecl.name) { this.countDeclarationsWithDuplicateName(tsClassDecl.name, tsClassDecl); @@ -1059,7 +1218,7 @@ export class TypeScriptLinter { const visitHClause = (hClause: ts.HeritageClause) => { for (const tsTypeExpr of hClause.types) { const tsExprType = this.tsTypeChecker.getTypeAtLocation(tsTypeExpr.expression); - if (tsExprType.isClass() && hClause.token == ts.SyntaxKind.ImplementsKeyword) { + if (tsExprType.isClass() && hClause.token === ts.SyntaxKind.ImplementsKeyword) { this.incrementCounters(tsTypeExpr, FaultID.ImplementsClass); } } @@ -1080,12 +1239,12 @@ export class TypeScriptLinter { // early exit via exception if cancellation was requested this.cancellationToken?.throwIfCancellationRequested(); - let tsModuleDecl = node as ts.ModuleDeclaration; + const tsModuleDecl = node as ts.ModuleDeclaration; this.countDeclarationsWithDuplicateName(tsModuleDecl.name, tsModuleDecl); - let tsModuleBody = tsModuleDecl.body; - let tsModifiers = ts.getModifiers(tsModuleDecl); + const tsModuleBody = tsModuleDecl.body; + const tsModifiers = ts.getModifiers(tsModuleDecl); if (tsModuleBody) { if (ts.isModuleBlock(tsModuleBody)) { for (const tsModuleStmt of tsModuleBody.statements) { @@ -1110,81 +1269,75 @@ export class TypeScriptLinter { } } - if (!(tsModuleDecl.flags & ts.NodeFlags.Namespace) && - this.tsUtils.hasModifier(tsModifiers, ts.SyntaxKind.DeclareKeyword)) { + if ( + !(tsModuleDecl.flags & ts.NodeFlags.Namespace) && + this.tsUtils.hasModifier(tsModifiers, ts.SyntaxKind.DeclareKeyword) + ) { this.incrementCounters(tsModuleDecl, FaultID.ShorthandAmbientModuleDecl); } - if (ts.isStringLiteral(tsModuleDecl.name) && tsModuleDecl.name.text.includes('*')) + if (ts.isStringLiteral(tsModuleDecl.name) && tsModuleDecl.name.text.includes('*')) { this.incrementCounters(tsModuleDecl, FaultID.WildcardsInModuleName); + } } private handleTypeAliasDeclaration(node: ts.Node) { - let tsTypeAlias = node as ts.TypeAliasDeclaration; + const tsTypeAlias = node as ts.TypeAliasDeclaration; this.countDeclarationsWithDuplicateName(tsTypeAlias.name, tsTypeAlias); } private handleImportClause(node: ts.Node) { - let tsImportClause = node as ts.ImportClause; + const tsImportClause = node as ts.ImportClause; if (tsImportClause.name) { this.countDeclarationsWithDuplicateName(tsImportClause.name, tsImportClause); } if (tsImportClause.namedBindings && ts.isNamedImports(tsImportClause.namedBindings)) { - let nonDefaultSpecs: ts.ImportSpecifier[] = []; + const nonDefaultSpecs: ts.ImportSpecifier[] = []; let defaultSpec: ts.ImportSpecifier | undefined; for (const importSpec of tsImportClause.namedBindings.elements) { - if (this.tsUtils.isDefaultImport(importSpec)) defaultSpec = importSpec; - else nonDefaultSpecs.push(importSpec); + if (this.tsUtils.isDefaultImport(importSpec)) { + defaultSpec = importSpec; + } else { + nonDefaultSpecs.push(importSpec); + } } if (defaultSpec) { let autofix: Autofix[] | undefined; - if (this.autofixesInfo.shouldAutofix(defaultSpec, FaultID.DefaultImport)) - autofix = [ Autofixer.fixDefaultImport(tsImportClause, defaultSpec, nonDefaultSpecs) ]; + if (this.autofixesInfo.shouldAutofix(defaultSpec, FaultID.DefaultImport)) { + autofix = [Autofixer.fixDefaultImport(tsImportClause, defaultSpec, nonDefaultSpecs)]; + } this.incrementCounters(defaultSpec, FaultID.DefaultImport, true, autofix); } } - if (tsImportClause.isTypeOnly) { - let autofix: Autofix[] | undefined; - if (this.autofixesInfo.shouldAutofix(node, FaultID.TypeOnlyImport)) - autofix = [ Autofixer.dropTypeOnlyFlag(tsImportClause) ]; - this.incrementCounters(node, FaultID.TypeOnlyImport, true, autofix); - } } private handleImportSpecifier(node: ts.Node) { - let importSpec = node as ts.ImportSpecifier; + const importSpec = node as ts.ImportSpecifier; this.countDeclarationsWithDuplicateName(importSpec.name, importSpec); - // Don't report or autofix type-only flag on default import if the latter has been autofixed already. - if ( - importSpec.isTypeOnly && - (!this.tsUtils.isDefaultImport(importSpec) || !this.autofixesInfo.shouldAutofix(importSpec, FaultID.DefaultImport)) - ) { - let autofix: Autofix[] | undefined; - if (this.autofixesInfo.shouldAutofix(node, FaultID.TypeOnlyImport)) - autofix = [ Autofixer.dropTypeOnlyFlag(importSpec) ]; - this.incrementCounters(node, FaultID.TypeOnlyImport, true, autofix); - } } private handleNamespaceImport(node: ts.Node) { - let tsNamespaceImport = node as ts.NamespaceImport; + const tsNamespaceImport = node as ts.NamespaceImport; this.countDeclarationsWithDuplicateName(tsNamespaceImport.name, tsNamespaceImport); } private handleTypeAssertionExpression(node: ts.Node) { - let tsTypeAssertion = node as ts.TypeAssertion; - if (tsTypeAssertion.type.getText() === 'const') + const tsTypeAssertion = node as ts.TypeAssertion; + if (tsTypeAssertion.type.getText() === 'const') { this.incrementCounters(tsTypeAssertion, FaultID.ConstAssertion); - else - this.incrementCounters(node, FaultID.TypeAssertion, true, [ Autofixer.fixTypeAssertion(tsTypeAssertion) ]); + } else { + this.incrementCounters(node, FaultID.TypeAssertion, true, [ + Autofixer.fixTypeAssertion(tsTypeAssertion), + ]); + } } private handleMethodDeclaration(node: ts.Node) { const tsMethodDecl = node as ts.MethodDeclaration; const hasThis = scopeContainsThis(tsMethodDecl); - let isStatic = false + let isStatic = false; if (tsMethodDecl.modifiers) { - for (let mod of tsMethodDecl.modifiers) { + for (const mod of tsMethodDecl.modifiers) { if (mod.kind === ts.SyntaxKind.StaticKeyword) { isStatic = true; break; @@ -1201,9 +1354,15 @@ export class TypeScriptLinter { this.incrementCounters(node, FaultID.GeneratorFunction); } this.handleDecorators(ts.getDecorators(tsMethodDecl)); - this.filterOutDecoratorsDiagnostics(ts.getDecorators(tsMethodDecl), NON_RETURN_FUNCTION_DECORATORS, - {begin: tsMethodDecl.parameters.end, end: tsMethodDecl.body?.getStart() ?? tsMethodDecl.parameters.end}, - FUNCTION_HAS_NO_RETURN_ERROR_CODE); + this.filterOutDecoratorsDiagnostics( + ts.getDecorators(tsMethodDecl), + NON_RETURN_FUNCTION_DECORATORS, + { + begin: tsMethodDecl.parameters.end, + end: tsMethodDecl.body?.getStart() ?? tsMethodDecl.parameters.end, + }, + FUNCTION_HAS_NO_RETURN_ERROR_CODE + ); } private handleMethodSignature(node: ts.MethodSignature) { @@ -1217,22 +1376,24 @@ export class TypeScriptLinter { if (ts.isClassDeclaration(node.parent)) { const tsClassDecl = node.parent as ts.ClassDeclaration; let className = ''; - if (tsClassDecl.name) + if (tsClassDecl.name) { // May be undefined in `export default class { ... }`. className = tsClassDecl.name.text; + } if (scopeContainsThis(node)) { this.incrementCounters(node, FaultID.FunctionContainsThis); } - if (this.staticBlocks.has(className)) + if (this.staticBlocks.has(className)) { this.incrementCounters(node, FaultID.MultipleStaticBlocks); - else + } else { this.staticBlocks.add(className); + } } } private handleIdentifier(node: ts.Node) { - let tsIdentifier = node as ts.Identifier; - let tsIdentSym = this.tsUtils.trueSymbolAtLocation(tsIdentifier); + const tsIdentifier = node as ts.Identifier; + const tsIdentSym = this.tsUtils.trueSymbolAtLocation(tsIdentifier); if (!tsIdentSym) { return; } @@ -1241,15 +1402,14 @@ export class TypeScriptLinter { (tsIdentSym.flags & ts.SymbolFlags.Transient) !== 0 && tsIdentifier.text === 'globalThis' ) { - this.incrementCounters(tsIdentifier, FaultID.GlobalThis); + this.incrementCounters(node, FaultID.GlobalThis); } else { - this.checkLimitedStdLib(tsIdentifier, tsIdentSym); this.handleRestrictedValues(tsIdentifier, tsIdentSym); } } // hard-coded alternative to TypeScriptLinter.advancedClassChecks - private isAllowedClassValueContext(tsIdentifier: ts.Identifier, tsIdentSym: ts.Symbol): boolean { + private isAllowedClassValueContext(tsIdentifier: ts.Identifier): boolean { let ctx: ts.Node = tsIdentifier; while (ts.isPropertyAccessExpression(ctx.parent) || ts.isQualifiedName(ctx.parent)) { ctx = ctx.parent; @@ -1257,13 +1417,15 @@ export class TypeScriptLinter { if (ts.isPropertyAssignment(ctx.parent) && ts.isObjectLiteralExpression(ctx.parent.parent)) { ctx = ctx.parent.parent; } - if (ts.isArrowFunction(ctx.parent) && ctx.parent.body == ctx) { + if (ts.isArrowFunction(ctx.parent) && ctx.parent.body === ctx) { ctx = ctx.parent; } if (ts.isCallExpression(ctx.parent) || ts.isNewExpression(ctx.parent)) { - let callee = ctx.parent.expression; - if (callee != ctx && this.tsUtils.hasLibraryType(callee)) { + const callee = ctx.parent.expression; + const isAny = this.tsUtils.isAnyType(this.tsTypeChecker.getTypeAtLocation(callee)); + const isDynamic = isAny || this.tsUtils.hasLibraryType(callee); + if (callee !== ctx && isDynamic) { return true; } } @@ -1271,23 +1433,33 @@ export class TypeScriptLinter { } private handleRestrictedValues(tsIdentifier: ts.Identifier, tsIdentSym: ts.Symbol) { - const illegalValues = ts.SymbolFlags.ConstEnum | ts.SymbolFlags.RegularEnum | ts.SymbolFlags.ValueModule | - (TypeScriptLinter.advancedClassChecks? 0 : ts.SymbolFlags.Class); - + const illegalValues = + ts.SymbolFlags.ConstEnum | + ts.SymbolFlags.RegularEnum | + ts.SymbolFlags.ValueModule | + (TypeScriptLinter.advancedClassChecks ? 0 : ts.SymbolFlags.Class); + // If module name is duplicated by another declaration, this increases the possibility // of finding a lot of false positives. Thus, do not check further in that case. - if ((tsIdentSym.flags & ts.SymbolFlags.ValueModule) != 0) { - if (!!tsIdentSym && this.tsUtils.symbolHasDuplicateName(tsIdentSym, ts.SyntaxKind.ModuleDeclaration)) { + if ((tsIdentSym.flags & ts.SymbolFlags.ValueModule) !== 0) { + if ( + !!tsIdentSym && + this.tsUtils.symbolHasDuplicateName(tsIdentSym, ts.SyntaxKind.ModuleDeclaration) + ) { return; } } - if ((tsIdentSym.flags & illegalValues) == 0 || isStruct(tsIdentSym) || !identiferUseInValueContext(tsIdentifier, tsIdentSym)) { + if ( + (tsIdentSym.flags & illegalValues) === 0 || + isStruct(tsIdentSym) || + !identiferUseInValueContext(tsIdentifier, tsIdentSym) + ) { return; } - if ((tsIdentSym.flags & ts.SymbolFlags.Class) != 0) { - if (!TypeScriptLinter.advancedClassChecks && this.isAllowedClassValueContext(tsIdentifier, tsIdentSym)) { + if ((tsIdentSym.flags & ts.SymbolFlags.Class) !== 0) { + if (!TypeScriptLinter.advancedClassChecks && this.isAllowedClassValueContext(tsIdentifier)) { return; } } @@ -1302,26 +1474,28 @@ export class TypeScriptLinter { private handleElementAccessExpression(node: ts.Node) { const tsElementAccessExpr = node as ts.ElementAccessExpression; - const tsElemAccessBaseExprType = this.tsTypeChecker.getTypeAtLocation(tsElementAccessExpr.expression); - const tsElemAccessBaseExprTypeNode = this.tsTypeChecker.typeToTypeNode(tsElemAccessBaseExprType, undefined, ts.NodeBuilderFlags.None); - - const checkClassOrInterface = tsElemAccessBaseExprType.isClassOrInterface() && - !this.tsUtils.isGenericArrayType(tsElemAccessBaseExprType) && - !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); - const checkThisOrSuper = this.tsUtils.isThisOrSuperExpr(tsElementAccessExpr.expression) && - !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); - - // implement check for enum argument expression - + const tsElemAccessBaseExprType = this.tsUtils.getTypeOrTypeConstraintAtLocation( + tsElementAccessExpr.expression + ); + const tsElemAccessBaseExprTypeNode = this.tsTypeChecker.typeToTypeNode( + tsElemAccessBaseExprType, + undefined, + ts.NodeBuilderFlags.None + ); if ( - !this.tsUtils.isLibraryType(tsElemAccessBaseExprType) && !this.tsUtils.isTypedArray(tsElemAccessBaseExprTypeNode) && - (checkClassOrInterface || this.tsUtils.isObjectLiteralType(tsElemAccessBaseExprType) || checkThisOrSuper) + !this.tsUtils.isLibraryType(tsElemAccessBaseExprType) && + !ts.isArrayLiteralExpression(tsElementAccessExpr.expression) && + !this.tsUtils.isOrDerivedFrom(tsElemAccessBaseExprType, this.tsUtils.isArray) && + !this.tsUtils.isOrDerivedFrom(tsElemAccessBaseExprType, this.tsUtils.isTuple) && + !this.tsUtils.isOrDerivedFrom(tsElemAccessBaseExprType, this.tsUtils.isStdRecordType) && + !this.tsUtils.isEnumType(tsElemAccessBaseExprType) && + !this.tsUtils.isEsObjectType(tsElemAccessBaseExprTypeNode) ) { let autofix = Autofixer.fixPropertyAccessByIndex(node); - const autofixable = autofix != undefined; - if (!this.autofixesInfo.shouldAutofix(node, FaultID.PropertyAccessByIndex)) + const autofixable = autofix !== undefined; + if (!this.autofixesInfo.shouldAutofix(node, FaultID.PropertyAccessByIndex)) { autofix = undefined; - + } this.incrementCounters(node, FaultID.PropertyAccessByIndex, autofixable, autofix); } @@ -1331,47 +1505,37 @@ export class TypeScriptLinter { } private handleEnumMember(node: ts.Node) { - let tsEnumMember = node as ts.EnumMember; - let tsEnumMemberType = this.tsTypeChecker.getTypeAtLocation(tsEnumMember); - let constVal = this.tsTypeChecker.getConstantValue(tsEnumMember); - if (tsEnumMember.initializer && !this.tsUtils.isValidEnumMemberInit(tsEnumMember.initializer)) + const tsEnumMember = node as ts.EnumMember; + const tsEnumMemberType = this.tsTypeChecker.getTypeAtLocation(tsEnumMember); + const constVal = this.tsTypeChecker.getConstantValue(tsEnumMember); + if (tsEnumMember.initializer && !this.tsUtils.isValidEnumMemberInit(tsEnumMember.initializer)) { this.incrementCounters(node, FaultID.EnumMemberNonConstInit); + } // check for type - all members should be of same type - let enumDecl = tsEnumMember.parent; - let firstEnumMember = enumDecl.members[0]; - let firstEnumMemberType = this.tsTypeChecker.getTypeAtLocation(firstEnumMember); - let firstElewmVal = this.tsTypeChecker.getConstantValue(firstEnumMember); + const enumDecl = tsEnumMember.parent; + const firstEnumMember = enumDecl.members[0]; + const firstEnumMemberType = this.tsTypeChecker.getTypeAtLocation(firstEnumMember); + const firstElewmVal = this.tsTypeChecker.getConstantValue(firstEnumMember); // each string enum member has its own type // so check that value type is string - if( constVal !==undefined && typeof constVal === 'string' && - firstElewmVal !==undefined && typeof firstElewmVal === 'string' ) + if ( + constVal !== undefined && + typeof constVal === 'string' && + firstElewmVal !== undefined && + typeof firstElewmVal === 'string' + ) { return; - if( constVal !==undefined && typeof constVal === 'number' && - firstElewmVal !==undefined && typeof firstElewmVal === 'number' ) + } + if ( + constVal !== undefined && + typeof constVal === 'number' && + firstElewmVal !== undefined && + typeof firstElewmVal === 'number' + ) { return; - if(firstEnumMemberType !== tsEnumMemberType) { - this.incrementCounters(node, FaultID.EnumMemberNonConstInit); } - } - - private handleExportDeclaration(node: ts.Node) { - let tsExportDecl = node as ts.ExportDeclaration; - if (tsExportDecl.isTypeOnly) { - let autofix: Autofix[] | undefined; - if (this.autofixesInfo.shouldAutofix(node, FaultID.TypeOnlyExport)) - autofix = [ Autofixer.dropTypeOnlyFlag(tsExportDecl) ]; - this.incrementCounters(node, FaultID.TypeOnlyExport, true, autofix); - } - let exportClause = tsExportDecl.exportClause; - if (exportClause && ts.isNamedExports(exportClause)) { - for (const exportSpec of exportClause.elements) { - if (exportSpec.isTypeOnly) { - let autofix: Autofix[] | undefined; - if (this.autofixesInfo.shouldAutofix(exportSpec, FaultID.TypeOnlyExport)) - autofix = [ Autofixer.dropTypeOnlyFlag(exportSpec) ]; - this.incrementCounters(exportSpec, FaultID.TypeOnlyExport, true, autofix); - } - } + if (firstEnumMemberType !== tsEnumMemberType) { + this.incrementCounters(node, FaultID.EnumMemberNonConstInit); } } @@ -1383,7 +1547,7 @@ export class TypeScriptLinter { } private handleCallExpression(node: ts.Node) { - let tsCallExpr = node as ts.CallExpression; + const tsCallExpr = node as ts.CallExpression; const calleeSym = this.tsUtils.trueSymbolAtLocation(tsCallExpr.expression); const calleeType = this.tsTypeChecker.getTypeAtLocation(tsCallExpr.expression); @@ -1391,22 +1555,28 @@ export class TypeScriptLinter { this.handleImportCall(tsCallExpr); this.handleRequireCall(tsCallExpr); - if (!!calleeSym) { + // NOTE: Keep handleFunctionApplyBindPropCall above handleGenericCallWithNoTypeArgs here!!! + if (calleeSym !== undefined) { + this.handleStdlibAPICall(tsCallExpr, calleeSym); + this.handleFunctionApplyBindPropCall(tsCallExpr, calleeSym); if (this.tsUtils.symbolHasEsObjectType(calleeSym)) { this.incrementCounters(tsCallExpr, FaultID.EsObjectType); } - // need to process Symbol call separatey in order to not report two times when using Symbol API - if (this.tsUtils.isStdSymbol(calleeSym)) { - this.incrementCounters(tsCallExpr, FaultID.SymbolType); - } } - if (!!callSignature) { + if (callSignature !== undefined) { if (!this.tsUtils.isLibrarySymbol(calleeSym)) { this.handleGenericCallWithNoTypeArgs(tsCallExpr, callSignature); } this.handleStructIdentAndUndefinedInArgs(tsCallExpr, callSignature); } this.handleLibraryTypeCall(tsCallExpr, calleeType); + + if ( + ts.isPropertyAccessExpression(tsCallExpr.expression) && + this.tsUtils.hasEsObjectType(tsCallExpr.expression.expression) + ) { + this.incrementCounters(node, FaultID.EsObjectType); + } } private handleImportCall(tsCallExpr: ts.CallExpression) { @@ -1433,21 +1603,33 @@ export class TypeScriptLinter { tsCallExpr.expression.text === 'require' && ts.isVariableDeclaration(tsCallExpr.parent) ) { - let tsType = this.tsTypeChecker.getTypeAtLocation(tsCallExpr.expression); - if (this.tsUtils.isInterfaceType(tsType) && tsType.symbol.name === 'NodeRequire') + const tsType = this.tsTypeChecker.getTypeAtLocation(tsCallExpr.expression); + if (this.tsUtils.isInterfaceType(tsType) && tsType.symbol.name === 'NodeRequire') { this.incrementCounters(tsCallExpr.parent, FaultID.ImportAssignment); + } } } - private handleGenericCallWithNoTypeArgs(callLikeExpr: ts.CallExpression | ts.NewExpression, callSignature: ts.Signature) { + private handleGenericCallWithNoTypeArgs( + callLikeExpr: ts.CallExpression | ts.NewExpression, + callSignature: ts.Signature + ) { // Note: The PR!716 has led to a significant performance degradation. // Since initial problem was fixed in a more general way, this change - // became redundant. Therefore, it was reverted. See #13721 comments - // for a detailed analysis. - const tsSyntaxKind = ts.isNewExpression(callLikeExpr) ? ts.SyntaxKind.Constructor : ts.SyntaxKind.FunctionDeclaration; - const signFlags = ts.NodeBuilderFlags.WriteTypeArgumentsOfSignature | ts.NodeBuilderFlags.IgnoreErrors; - - const signDecl = this.tsTypeChecker.signatureToSignatureDeclaration(callSignature, tsSyntaxKind, undefined, signFlags); + // became redundant. Therefore, it was reverted. See #13721 comments + // for a detailed analysis. + const tsSyntaxKind = ts.isNewExpression(callLikeExpr) + ? ts.SyntaxKind.Constructor + : ts.SyntaxKind.FunctionDeclaration; + const signFlags = + ts.NodeBuilderFlags.WriteTypeArgumentsOfSignature | ts.NodeBuilderFlags.IgnoreErrors; + + const signDecl = this.tsTypeChecker.signatureToSignatureDeclaration( + callSignature, + tsSyntaxKind, + undefined, + signFlags + ); if (!signDecl?.typeArguments) { return; } @@ -1460,32 +1642,55 @@ export class TypeScriptLinter { // 2. Compiler infer 'unknown' from arguments // We report error in both cases. It is ok because we cannot use 'unknown' // in ArkTS and already have separate check for it. - if (typeNode.kind == ts.SyntaxKind.UnknownKeyword) { + if (typeNode.kind === ts.SyntaxKind.UnknownKeyword) { this.incrementCounters(callLikeExpr, FaultID.GenericCallNoTypeArgs); break; } } } - private handleStructIdentAndUndefinedInArgs(tsCallOrNewExpr: ts.CallExpression | ts.NewExpression, callSignature: ts.Signature) { + private static listApplyBindCallApis = [ + 'Function.apply', + 'Function.call', + 'Function.bind', + 'CallableFunction.apply', + 'CallableFunction.call', + 'CallableFunction.bind', + ]; + private handleFunctionApplyBindPropCall(tsCallExpr: ts.CallExpression, calleeSym: ts.Symbol) { + const exprName = this.tsTypeChecker.getFullyQualifiedName(calleeSym); + if (TypeScriptLinter.listApplyBindCallApis.includes(exprName)) { + this.incrementCounters(tsCallExpr, FaultID.FunctionApplyBindCall); + } + } + + private handleStructIdentAndUndefinedInArgs( + tsCallOrNewExpr: ts.CallExpression | ts.NewExpression, + callSignature: ts.Signature + ) { if (!tsCallOrNewExpr.arguments) { return; } for (let argIndex = 0; argIndex < tsCallOrNewExpr.arguments.length; ++argIndex) { - let tsArg = tsCallOrNewExpr.arguments[argIndex]; - let tsArgType = this.tsTypeChecker.getTypeAtLocation(tsArg); + const tsArg = tsCallOrNewExpr.arguments[argIndex]; + const tsArgType = this.tsTypeChecker.getTypeAtLocation(tsArg); if (!tsArgType) { continue; } - let paramIndex = argIndex < callSignature.parameters.length ? argIndex : callSignature.parameters.length-1; - let tsParamSym = callSignature.parameters[paramIndex]; + const paramIndex = + argIndex < callSignature.parameters.length ? argIndex : callSignature.parameters.length - 1; + const tsParamSym = callSignature.parameters[paramIndex]; if (!tsParamSym) { continue; } - let tsParamDecl = tsParamSym.valueDeclaration; + const tsParamDecl = tsParamSym.valueDeclaration; if (tsParamDecl && ts.isParameter(tsParamDecl)) { let tsParamType = this.tsTypeChecker.getTypeOfSymbolAtLocation(tsParamSym, tsParamDecl); - if (tsParamDecl.dotDotDotToken && this.tsUtils.isGenericArrayType(tsParamType) && tsParamType.typeArguments) { + if ( + tsParamDecl.dotDotDotToken && + this.tsUtils.isGenericArrayType(tsParamType) && + tsParamType.typeArguments + ) { tsParamType = tsParamType.typeArguments[0]; } if (!tsParamType) { @@ -1498,29 +1703,50 @@ export class TypeScriptLinter { } } - private checkLimitedStdLib(node: ts.Node, symbol: ts.Symbol) { - const parName = this.tsUtils.getParentSymbolName(symbol); - const res = parName ? LIMITED_STD_API.get(parName) : undefined; - if (res && res.arr.includes(symbol.name)) { - this.incrementCounters(node, res.fault); + private static LimitedApis = new Map | null; fault: FaultID }>([ + ['global', { arr: LIMITED_STD_GLOBAL_FUNC, fault: FaultID.LimitedStdLibApi }], + ['Object', { arr: LIMITED_STD_OBJECT_API, fault: FaultID.LimitedStdLibApi }], + ['ObjectConstructor', { arr: LIMITED_STD_OBJECT_API, fault: FaultID.LimitedStdLibApi }], + ['Reflect', { arr: LIMITED_STD_REFLECT_API, fault: FaultID.LimitedStdLibApi }], + ['ProxyHandler', { arr: LIMITED_STD_PROXYHANDLER_API, fault: FaultID.LimitedStdLibApi }], + ['Symbol', { arr: null, fault: FaultID.SymbolType }], + ['SymbolConstructor', { arr: null, fault: FaultID.SymbolType }], + ]); + + private handleStdlibAPICall(callExpr: ts.CallExpression, calleeSym: ts.Symbol) { + const name = calleeSym.getName(); + const parName = this.tsUtils.getParentSymbolName(calleeSym); + if (parName === undefined) { + if (LIMITED_STD_GLOBAL_FUNC.includes(name)) { + this.incrementCounters(callExpr, FaultID.LimitedStdLibApi); + return; + } + const escapedName = calleeSym.escapedName; + if (escapedName === 'Symbol' || escapedName === 'SymbolConstructor') { + this.incrementCounters(callExpr, FaultID.SymbolType); + } return; } - const name = this.tsTypeChecker.getFullyQualifiedName(symbol); - if (LIMITED_STD_GLOBAL_API.includes(name)) { - this.incrementCounters(node, FaultID.LimitedStdLibApi) - return; + const lookup = TypeScriptLinter.LimitedApis.get(parName); + if (lookup !== undefined && (lookup.arr === null || lookup.arr.includes(name))) { + this.incrementCounters(callExpr, lookup.fault); } } - private findNonFilteringRangesFunctionCalls(callExpr: ts.CallExpression): { begin: number, end: number }[] { - let args = callExpr.arguments; - let result: { begin: number, end: number }[] = []; + private findNonFilteringRangesFunctionCalls( + callExpr: ts.CallExpression + ): { begin: number; end: number }[] { + const args = callExpr.arguments; + const result: { begin: number; end: number }[] = []; for (const arg of args) { if (ts.isArrowFunction(arg)) { - let arrowFuncExpr = arg as ts.ArrowFunction; - result.push({begin: arrowFuncExpr.body.pos, end: arrowFuncExpr.body.end}); + const arrowFuncExpr = arg as ts.ArrowFunction; + result.push({ + begin: arrowFuncExpr.body.pos, + end: arrowFuncExpr.body.end, + }); } else if (ts.isCallExpression(arg)) { - result.push({begin: arg.arguments.pos, end: arg.arguments.end}); + result.push({ begin: arg.arguments.pos, end: arg.arguments.end }); } // there may be other cases } @@ -1528,52 +1754,69 @@ export class TypeScriptLinter { } private handleLibraryTypeCall(callExpr: ts.CallExpression, calleeType: ts.Type) { - let inLibCall = this.tsUtils.isLibraryType(calleeType); - const diagnosticMessages: Array = [] + const inLibCall = this.tsUtils.isLibraryType(calleeType); + const diagnosticMessages: Array = []; this.libraryTypeCallDiagnosticChecker.configure(inLibCall, diagnosticMessages); - let nonFilteringRanges = this.findNonFilteringRangesFunctionCalls(callExpr); - let rangesToFilter: { begin: number, end: number }[] = []; + const nonFilteringRanges = this.findNonFilteringRangesFunctionCalls(callExpr); + const rangesToFilter: { begin: number; end: number }[] = []; if (nonFilteringRanges.length !== 0) { - let rangesSize = nonFilteringRanges.length; - rangesToFilter.push({ begin: callExpr.pos, end: nonFilteringRanges[0].begin }) - rangesToFilter.push({ begin: nonFilteringRanges[rangesSize - 1].end, end: callExpr.end }) + const rangesSize = nonFilteringRanges.length; + rangesToFilter.push({ + begin: callExpr.arguments.pos, + end: nonFilteringRanges[0].begin, + }); + rangesToFilter.push({ + begin: nonFilteringRanges[rangesSize - 1].end, + end: callExpr.arguments.end, + }); for (let i = 0; i < rangesSize - 1; i++) { - rangesToFilter.push({ begin: nonFilteringRanges[i].end, end: nonFilteringRanges[i + 1].begin }) + rangesToFilter.push({ + begin: nonFilteringRanges[i].end, + end: nonFilteringRanges[i + 1].begin, + }); } } else { - rangesToFilter.push({ begin: callExpr.pos, end: callExpr.end }) + rangesToFilter.push({ + begin: callExpr.arguments.pos, + end: callExpr.arguments.end, + }); } - this.filterStrictDiagnostics({ + this.filterStrictDiagnostics( + { [ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE]: (pos: number) => { return this.checkInRange(rangesToFilter, pos); }, [TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE]: (pos: number) => { return this.checkInRange(rangesToFilter, pos); - } + }, }, this.libraryTypeCallDiagnosticChecker ); for (const msgChain of diagnosticMessages) { - TypeScriptLinter.filteredDiagnosticMessages.add(msgChain) + TypeScriptLinter.filteredDiagnosticMessages.add(msgChain); } } private handleNewExpression(node: ts.Node) { - let tsNewExpr = node as ts.NewExpression; + const tsNewExpr = node as ts.NewExpression; if (TypeScriptLinter.advancedClassChecks) { - let calleeExpr = tsNewExpr.expression; - let calleeType = this.tsTypeChecker.getTypeAtLocation(calleeExpr); - if (!this.tsUtils.isClassTypeExrepssion(calleeExpr) && !isStdLibraryType(calleeType) && - !this.tsUtils.isLibraryType(calleeType) && !this.tsUtils.hasEsObjectType(calleeExpr)) { + const calleeExpr = tsNewExpr.expression; + const calleeType = this.tsTypeChecker.getTypeAtLocation(calleeExpr); + if ( + !this.tsUtils.isClassTypeExrepssion(calleeExpr) && + !isStdLibraryType(calleeType) && + !this.tsUtils.isLibraryType(calleeType) && + !this.tsUtils.hasEsObjectType(calleeExpr) + ) { // missing exact rule this.incrementCounters(calleeExpr, FaultID.ClassAsObject); } } - let callSignature = this.tsTypeChecker.getResolvedSignature(tsNewExpr); + const callSignature = this.tsTypeChecker.getResolvedSignature(tsNewExpr); if (callSignature !== undefined) { this.handleStructIdentAndUndefinedInArgs(tsNewExpr, callSignature); this.handleGenericCallWithNoTypeArgs(tsNewExpr, callSignature); @@ -1581,19 +1824,21 @@ export class TypeScriptLinter { } private handleAsExpression(node: ts.Node) { - let tsAsExpr = node as ts.AsExpression; + const tsAsExpr = node as ts.AsExpression; if (tsAsExpr.type.getText() === 'const') { this.incrementCounters(node, FaultID.ConstAssertion); } - let targetType = this.tsTypeChecker.getTypeAtLocation(tsAsExpr.type).getNonNullableType(); - let exprType = this.tsTypeChecker.getTypeAtLocation(tsAsExpr.expression).getNonNullableType(); - if (this.tsUtils.needToDeduceStructuralIdentity(targetType, exprType, tsAsExpr.expression, true)) { + const targetType = this.tsTypeChecker.getTypeAtLocation(tsAsExpr.type).getNonNullableType(); + const exprType = this.tsTypeChecker.getTypeAtLocation(tsAsExpr.expression).getNonNullableType(); + if ( + this.tsUtils.needToDeduceStructuralIdentity(targetType, exprType, tsAsExpr.expression, true) + ) { this.incrementCounters(tsAsExpr, FaultID.StructuralIdentity); } // check for rule#65: 'number as Number' and 'boolean as Boolean' are disabled if ( - ( this.tsUtils.isNumberType(exprType) && targetType.getSymbol()?.getName() === 'Number' ) || - ( this.tsUtils.isBooleanType(exprType) && targetType.getSymbol()?.getName() === 'Boolean' ) + (this.tsUtils.isNumberType(exprType) && targetType.getSymbol()?.getName() === 'Number') || + (this.tsUtils.isBooleanType(exprType) && targetType.getSymbol()?.getName() === 'Boolean') ) { this.incrementCounters(node, FaultID.TypeAssertion); } @@ -1619,7 +1864,8 @@ export class TypeScriptLinter { // Using Partial type is allowed only when its argument type is either Class or Interface. const isStdPartial = this.tsUtils.entityNameToString(typeRef.typeName) === 'Partial'; const hasSingleTypeArgument = !!typeRef.typeArguments && typeRef.typeArguments.length === 1; - const argType = hasSingleTypeArgument && this.tsTypeChecker.getTypeFromTypeNode(typeRef.typeArguments[0]); + const argType = + hasSingleTypeArgument && this.tsTypeChecker.getTypeFromTypeNode(typeRef.typeArguments[0]); if (isStdPartial && argType && !argType.isClassOrInterface()) { this.incrementCounters(node, FaultID.UtilityType); return; @@ -1627,7 +1873,7 @@ export class TypeScriptLinter { } private handleMetaProperty(node: ts.Node) { - let tsMetaProperty = node as ts.MetaProperty; + const tsMetaProperty = node as ts.MetaProperty; if (tsMetaProperty.name.text === 'target') { this.incrementCounters(node, FaultID.NewTarget); } @@ -1639,22 +1885,22 @@ export class TypeScriptLinter { node.forEachChild(child => { // Skip synthetic constructor in Struct declaration. - if (!ts.isConstructorDeclaration(child)) this.visitTSNode(child); + if (!ts.isConstructorDeclaration(child)) { + this.visitTSNode(child); + } }); } private handleSpreadOp(node: ts.Node) { // spread assignment is disabled // spread element is allowed only for arrays as rest parameter - if( ts.isSpreadElement(node) ) { - let spreadElemNode = node as ts.SpreadElement; - let spreadExprType = this.tsTypeChecker.getTypeAtLocation(spreadElemNode.expression); + if (ts.isSpreadElement(node)) { + const spreadElemNode = node as ts.SpreadElement; + const spreadExprType = this.tsTypeChecker.getTypeAtLocation(spreadElemNode.expression); if (spreadExprType) { - const spreadExprTypeNode = this.tsTypeChecker.typeToTypeNode(spreadExprType, undefined, ts.NodeBuilderFlags.None); - if (spreadExprTypeNode !== undefined && (ts.isCallLikeExpression(node.parent) || ts.isArrayLiteralExpression(node.parent))) { - if (ts.isArrayTypeNode(spreadExprTypeNode) || this.tsUtils.isTypedArray(spreadExprTypeNode) || - this.tsUtils.isDerivedFrom(spreadExprType, CheckType.Array)) { - return + if (ts.isCallLikeExpression(node.parent) || ts.isArrayLiteralExpression(node.parent)) { + if (this.tsUtils.isOrDerivedFrom(spreadExprType, this.tsUtils.isArray)) { + return; } } } @@ -1682,7 +1928,7 @@ export class TypeScriptLinter { const srcText = node.getSourceFile().getFullText(); const parent = node.parent; if (!parent || parent.getFullStart() !== node.getFullStart()) { - let leadingComments = ts.getLeadingCommentRanges(srcText, node.getFullStart()); + const leadingComments = ts.getLeadingCommentRanges(srcText, node.getFullStart()); if (leadingComments) { for (const comment of leadingComments) { // In the real-time linter comment from the first line is double proccessed. @@ -1695,7 +1941,7 @@ export class TypeScriptLinter { } } if (!parent || parent.getEnd() !== node.getEnd()) { - let trailingComments = ts.getTrailingCommentRanges(srcText, node.getEnd()); + const trailingComments = ts.getTrailingCommentRanges(srcText, node.getEnd()); if (trailingComments) { for (const comment of trailingComments) { // In the real-time linter comment from the first line is double proccessed. @@ -1710,22 +1956,39 @@ export class TypeScriptLinter { } private handleExpressionWithTypeArguments(node: ts.Node) { - let tsTypeExpr = node as ts.ExpressionWithTypeArguments; - let symbol = this.tsUtils.trueSymbolAtLocation(tsTypeExpr.expression); + const tsTypeExpr = node as ts.ExpressionWithTypeArguments; + const symbol = this.tsUtils.trueSymbolAtLocation(tsTypeExpr.expression); if (!!symbol && this.tsUtils.isEsObjectSymbol(symbol)) { this.incrementCounters(tsTypeExpr, FaultID.EsObjectType); } } + private handleComputedPropertyName(node: ts.Node) { + const computedProperty = node as ts.ComputedPropertyName; + const symbol = this.tsUtils.trueSymbolAtLocation(computedProperty.expression); + if (!!symbol && this.tsUtils.isSymbolIterator(symbol)) { + return; + } + this.incrementCounters(node, FaultID.ComputedPropertyName); + } + private checkErrorSuppressingAnnotation(comment: ts.CommentRange, srcText: string) { - const commentContent = comment.kind === ts.SyntaxKind.MultiLineCommentTrivia - ? srcText.slice(comment.pos + 2, comment.end - 2) - : srcText.slice(comment.pos + 2, comment.end); - const trimmedContent = commentContent.trim() - if (trimmedContent.startsWith('@ts-ignore') || - trimmedContent.startsWith('@ts-nocheck') || - trimmedContent.startsWith('@ts-expect-error')) + const commentContent = + comment.kind === ts.SyntaxKind.MultiLineCommentTrivia + ? srcText.slice(comment.pos + 2, comment.end - 2) + : srcText.slice(comment.pos + 2, comment.end); + // if comment is multiline end closing '*/' is not at the same line as '@ts-xxx' - do nothing (see #13851) + if (commentContent.endsWith('\n')) { + return; + } + const trimmedContent = commentContent.trim(); + if ( + trimmedContent.startsWith('@ts-ignore') || + trimmedContent.startsWith('@ts-nocheck') || + trimmedContent.startsWith('@ts-expect-error') + ) { this.incrementCounters(comment, FaultID.ErrorSuppression); + } } private handleDecorators(decorators: readonly ts.Decorator[] | undefined): void { @@ -1736,7 +1999,10 @@ export class TypeScriptLinter { let decoratorName = ''; if (ts.isIdentifier(decorator.expression)) { decoratorName = decorator.expression.text; - } else if (ts.isCallExpression(decorator.expression) && ts.isIdentifier(decorator.expression.expression)) { + } else if ( + ts.isCallExpression(decorator.expression) && + ts.isIdentifier(decorator.expression.expression) + ) { decoratorName = decorator.expression.expression.text; } if (!ARKUI_DECORATORS.includes(decoratorName)) { @@ -1778,9 +2044,12 @@ export class TypeScriptLinter { // option is enabled, compiler attempts to infer type from variable references: // see https://github.com/microsoft/TypeScript/pull/11263. // In this case, we still want to report the error, since ArkTS doesn't allow - // to omit both type annotation and initializer. - if (((ts.isVariableDeclaration(decl) && ts.isVariableStatement(decl.parent.parent)) || ts.isPropertyDeclaration(decl)) - && !decl.initializer) { + // to omit both type annotation and initializer. + if ( + ((ts.isVariableDeclaration(decl) && ts.isVariableStatement(decl.parent.parent)) || + ts.isPropertyDeclaration(decl)) && + !decl.initializer + ) { this.incrementCounters(decl, FaultID.AnyType); return; } @@ -1800,11 +2069,10 @@ export class TypeScriptLinter { private validatedTypesSet = new Set(); private checkAnyOrUnknownChildNode(node: ts.Node): boolean { - if (node.kind === ts.SyntaxKind.AnyKeyword || - node.kind === ts.SyntaxKind.UnknownKeyword) { + if (node.kind === ts.SyntaxKind.AnyKeyword || node.kind === ts.SyntaxKind.UnknownKeyword) { return true; } - for (let child of node.getChildren()) { + for (const child of node.getChildren()) { if (this.checkAnyOrUnknownChildNode(child)) { return true; } @@ -1831,12 +2099,10 @@ export class TypeScriptLinter { type: ts.Type, decl: ts.VariableDeclaration | ts.PropertyDeclaration | ts.ParameterDeclaration ): void { - if (type.aliasSymbol != undefined) { + if (type.aliasSymbol !== undefined) { return; } - const isObject = type.flags & ts.TypeFlags.Object; - const isReference = (type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference; - if (isObject && isReference) { + if (this.tsUtils.isObjectType(type) && !!(type.objectFlags & ts.ObjectFlags.Reference)) { this.handleInferredObjectreference(type, decl); return; } @@ -1845,8 +2111,8 @@ export class TypeScriptLinter { } if (type.isUnion()) { this.validatedTypesSet.add(type); - for (let unionElem of type.types) { - this.validateDeclInferredType(unionElem, decl) + for (const unionElem of type.types) { + this.validateDeclInferredType(unionElem, decl); } } if (this.tsUtils.isAnyType(type)) { diff --git a/linter/src/TypeScriptLinterConfig.ts b/linter/src/TypeScriptLinterConfig.ts index 58f32df628769245048013901d2624b994e3946b..c0099c97ef08b33a8d1912204fc4a5997f117d19 100644 --- a/linter/src/TypeScriptLinterConfig.ts +++ b/linter/src/TypeScriptLinterConfig.ts @@ -14,7 +14,7 @@ */ import * as ts from 'typescript'; -import { FaultID } from './utils/consts/Problems'; +import { FaultID } from './Problems'; export class LinterConfig { // The SyntaxKind enum defines additional elements at the end of the enum @@ -46,47 +46,96 @@ export class LinterConfig { // must detect terminals during parsing static terminalTokens: Set = new Set([ - ts.SyntaxKind.OpenBraceToken, ts.SyntaxKind.CloseBraceToken, ts.SyntaxKind.OpenParenToken, - ts.SyntaxKind.CloseParenToken, ts.SyntaxKind.OpenBracketToken, ts.SyntaxKind.CloseBracketToken, - ts.SyntaxKind.DotToken, ts.SyntaxKind.DotDotDotToken, ts.SyntaxKind.SemicolonToken, ts.SyntaxKind.CommaToken, - ts.SyntaxKind.QuestionDotToken, ts.SyntaxKind.LessThanToken, ts.SyntaxKind.LessThanSlashToken, - ts.SyntaxKind.GreaterThanToken, ts.SyntaxKind.LessThanEqualsToken, ts.SyntaxKind.GreaterThanEqualsToken, - ts.SyntaxKind.EqualsEqualsToken, ts.SyntaxKind.ExclamationEqualsToken, ts.SyntaxKind.EqualsEqualsEqualsToken, - ts.SyntaxKind.ExclamationEqualsEqualsToken, ts.SyntaxKind.EqualsGreaterThanToken, ts.SyntaxKind.PlusToken, - ts.SyntaxKind.MinusToken, ts.SyntaxKind.AsteriskToken, ts.SyntaxKind.AsteriskAsteriskToken, - ts.SyntaxKind.SlashToken, ts.SyntaxKind.PercentToken, ts.SyntaxKind.PlusPlusToken, ts.SyntaxKind.MinusMinusToken, - ts.SyntaxKind.LessThanLessThanToken, ts.SyntaxKind.GreaterThanGreaterThanToken, - ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken, ts.SyntaxKind.AmpersandToken, ts.SyntaxKind.BarToken, - ts.SyntaxKind.CaretToken, ts.SyntaxKind.ExclamationToken, ts.SyntaxKind.TildeToken, - ts.SyntaxKind.AmpersandAmpersandToken, ts.SyntaxKind.BarBarToken, ts.SyntaxKind.QuestionQuestionToken, - ts.SyntaxKind.QuestionToken, ts.SyntaxKind.ColonToken, ts.SyntaxKind.AtToken, ts.SyntaxKind.BacktickToken, - ts.SyntaxKind.HashToken, ts.SyntaxKind.EqualsToken, ts.SyntaxKind.PlusEqualsToken, ts.SyntaxKind.MinusEqualsToken, - ts.SyntaxKind.AsteriskEqualsToken, ts.SyntaxKind.AsteriskAsteriskEqualsToken, ts.SyntaxKind.SlashEqualsToken, - ts.SyntaxKind.PercentEqualsToken, ts.SyntaxKind.LessThanLessThanEqualsToken, - ts.SyntaxKind.GreaterThanGreaterThanEqualsToken, ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken, - ts.SyntaxKind.AmpersandEqualsToken, ts.SyntaxKind.BarEqualsToken, ts.SyntaxKind.CaretEqualsToken, - ts.SyntaxKind.EndOfFileToken, ts.SyntaxKind.SingleLineCommentTrivia, - ts.SyntaxKind.MultiLineCommentTrivia, ts.SyntaxKind.NewLineTrivia, ts.SyntaxKind.WhitespaceTrivia, - ts.SyntaxKind.ShebangTrivia, /* We detect and preserve #! on the first line */ ts.SyntaxKind.ConflictMarkerTrivia, + ts.SyntaxKind.OpenBraceToken, + ts.SyntaxKind.CloseBraceToken, + ts.SyntaxKind.OpenParenToken, + ts.SyntaxKind.CloseParenToken, + ts.SyntaxKind.OpenBracketToken, + ts.SyntaxKind.CloseBracketToken, + ts.SyntaxKind.DotToken, + ts.SyntaxKind.DotDotDotToken, + ts.SyntaxKind.SemicolonToken, + ts.SyntaxKind.CommaToken, + ts.SyntaxKind.QuestionDotToken, + ts.SyntaxKind.LessThanToken, + ts.SyntaxKind.LessThanSlashToken, + ts.SyntaxKind.GreaterThanToken, + ts.SyntaxKind.LessThanEqualsToken, + ts.SyntaxKind.GreaterThanEqualsToken, + ts.SyntaxKind.EqualsEqualsToken, + ts.SyntaxKind.ExclamationEqualsToken, + ts.SyntaxKind.EqualsEqualsEqualsToken, + ts.SyntaxKind.ExclamationEqualsEqualsToken, + ts.SyntaxKind.EqualsGreaterThanToken, + ts.SyntaxKind.PlusToken, + ts.SyntaxKind.MinusToken, + ts.SyntaxKind.AsteriskToken, + ts.SyntaxKind.AsteriskAsteriskToken, + ts.SyntaxKind.SlashToken, + ts.SyntaxKind.PercentToken, + ts.SyntaxKind.PlusPlusToken, + ts.SyntaxKind.MinusMinusToken, + ts.SyntaxKind.LessThanLessThanToken, + ts.SyntaxKind.GreaterThanGreaterThanToken, + ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken, + ts.SyntaxKind.AmpersandToken, + ts.SyntaxKind.BarToken, + ts.SyntaxKind.CaretToken, + ts.SyntaxKind.ExclamationToken, + ts.SyntaxKind.TildeToken, + ts.SyntaxKind.AmpersandAmpersandToken, + ts.SyntaxKind.BarBarToken, + ts.SyntaxKind.QuestionQuestionToken, + ts.SyntaxKind.QuestionToken, + ts.SyntaxKind.ColonToken, + ts.SyntaxKind.AtToken, + ts.SyntaxKind.BacktickToken, + ts.SyntaxKind.HashToken, + ts.SyntaxKind.EqualsToken, + ts.SyntaxKind.PlusEqualsToken, + ts.SyntaxKind.MinusEqualsToken, + ts.SyntaxKind.AsteriskEqualsToken, + ts.SyntaxKind.AsteriskAsteriskEqualsToken, + ts.SyntaxKind.SlashEqualsToken, + ts.SyntaxKind.PercentEqualsToken, + ts.SyntaxKind.LessThanLessThanEqualsToken, + ts.SyntaxKind.GreaterThanGreaterThanEqualsToken, + ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken, + ts.SyntaxKind.AmpersandEqualsToken, + ts.SyntaxKind.BarEqualsToken, + ts.SyntaxKind.CaretEqualsToken, + ts.SyntaxKind.EndOfFileToken, + ts.SyntaxKind.SingleLineCommentTrivia, + ts.SyntaxKind.MultiLineCommentTrivia, + ts.SyntaxKind.NewLineTrivia, + ts.SyntaxKind.WhitespaceTrivia, + ts.SyntaxKind.ShebangTrivia, + /* We detect and preserve #! on the first line */ ts.SyntaxKind.ConflictMarkerTrivia, ]); // tokens which can be reported without additional parsing static incrementOnlyTokens: Map = new Map([ - [ts.SyntaxKind.AnyKeyword, FaultID.AnyType], [ts.SyntaxKind.SymbolKeyword, FaultID.SymbolType], + [ts.SyntaxKind.AnyKeyword, FaultID.AnyType], + [ts.SyntaxKind.SymbolKeyword, FaultID.SymbolType], [ts.SyntaxKind.ThisType, FaultID.ThisType], - [ts.SyntaxKind.ComputedPropertyName, FaultID.ComputedPropertyName], [ts.SyntaxKind.TypeQuery, FaultID.TypeQuery], [ts.SyntaxKind.DeleteExpression, FaultID.DeleteOperator], [ts.SyntaxKind.RegularExpressionLiteral, FaultID.RegexLiteral], - [ts.SyntaxKind.TypePredicate, FaultID.IsOperator], [ts.SyntaxKind.YieldExpression, FaultID.YieldExpression], - [ts.SyntaxKind.IndexSignature, FaultID.IndexMember], [ts.SyntaxKind.WithStatement, FaultID.WithStatement], - [ts.SyntaxKind.IndexedAccessType, FaultID.IndexedAccessType], [ts.SyntaxKind.UnknownKeyword, FaultID.UnknownType], - [ts.SyntaxKind.InKeyword, FaultID.InOperator], [ts.SyntaxKind.CallSignature, FaultID.CallSignature], + [ts.SyntaxKind.TypePredicate, FaultID.IsOperator], + [ts.SyntaxKind.YieldExpression, FaultID.YieldExpression], + [ts.SyntaxKind.IndexSignature, FaultID.IndexMember], + [ts.SyntaxKind.WithStatement, FaultID.WithStatement], + [ts.SyntaxKind.IndexedAccessType, FaultID.IndexedAccessType], + [ts.SyntaxKind.UnknownKeyword, FaultID.UnknownType], + [ts.SyntaxKind.CallSignature, FaultID.CallSignature], [ts.SyntaxKind.IntersectionType, FaultID.IntersectionType], - [ts.SyntaxKind.TypeLiteral, FaultID.ObjectTypeLiteral], [ts.SyntaxKind.ConstructorType, FaultID.ConstructorFuncs], + [ts.SyntaxKind.TypeLiteral, FaultID.ObjectTypeLiteral], + [ts.SyntaxKind.ConstructorType, FaultID.ConstructorFuncs], [ts.SyntaxKind.PrivateIdentifier, FaultID.PrivateIdentifier], - [ts.SyntaxKind.ConditionalType, FaultID.ConditionalType], [ts.SyntaxKind.MappedType, FaultID.MappedType], - [ts.SyntaxKind.JsxElement, FaultID.JsxElement], [ts.SyntaxKind.JsxSelfClosingElement, FaultID.JsxElement], + [ts.SyntaxKind.ConditionalType, FaultID.ConditionalType], + [ts.SyntaxKind.MappedType, FaultID.MappedType], + [ts.SyntaxKind.JsxElement, FaultID.JsxElement], + [ts.SyntaxKind.JsxSelfClosingElement, FaultID.JsxElement], [ts.SyntaxKind.ImportEqualsDeclaration, FaultID.ImportAssignment], [ts.SyntaxKind.NamespaceExportDeclaration, FaultID.UMDModuleDefinition], ]); diff --git a/linter/src/autofixes/AutofixTitles.ts b/linter/src/autofixes/AutofixTitles.ts index 89bad0381fe8112ffdb123e32e89b96142010523..111157345b7bdda0c27e228acfec54101b333b89 100644 --- a/linter/src/autofixes/AutofixTitles.ts +++ b/linter/src/autofixes/AutofixTitles.ts @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // generated from recipes.rst export const cookBookRefToFixTitle: Map = new Map([ [1, 'Replace property name with identifier'], [29, 'Replace with dot notation'], [46, 'Convert to arrow function'], - [53, 'Replace to \'as\' expression'], + [53, 'Replace to "as" expression'], [79, 'Remove type annotation'], - [87, 'Wrap in \'Error\''], + [87, 'Wrap in "Error"'], [90, 'Annotate return type'], [118, 'Replace with ordinary import'], [120, 'Replace with explicit import'], diff --git a/linter/src/autofixes/ReportAutofixCallback.ts b/linter/src/autofixes/ReportAutofixCallback.ts index 0338538bcbacae5af05b6edb5878a0b41122c2d0..a65764e0ec28543b5812d282bd398fa1210ca99a 100644 --- a/linter/src/autofixes/ReportAutofixCallback.ts +++ b/linter/src/autofixes/ReportAutofixCallback.ts @@ -1,17 +1,17 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import { ProblemInfo } from '../ProblemInfo'; diff --git a/linter/src/ts-compiler/FormTscOptions.ts b/linter/src/ts-compiler/FormTscOptions.ts index 08a04429a759cc8a3831715a834c3cb593266b92..dcfa58bba102da03b098dc90f0446db4fd741c24 100644 --- a/linter/src/ts-compiler/FormTscOptions.ts +++ b/linter/src/ts-compiler/FormTscOptions.ts @@ -16,9 +16,13 @@ import * as ts from 'typescript'; import { CommandLineOptions } from '../CommandLineOptions'; -export function formTscOptions(cmdOptions: CommandLineOptions, extraOptions?: any): ts.CreateProgramOptions { +export function formTscOptions( + cmdOptions: CommandLineOptions, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + extraOptions?: any +): ts.CreateProgramOptions { if (cmdOptions.parsedConfigFile) { - let options: ts.CreateProgramOptions = { + const options: ts.CreateProgramOptions = { rootNames: cmdOptions.parsedConfigFile.fileNames, options: cmdOptions.parsedConfigFile.options, projectReferences: cmdOptions.parsedConfigFile.projectReferences, @@ -29,7 +33,7 @@ export function formTscOptions(cmdOptions: CommandLineOptions, extraOptions?: an } return options; } - let options: ts.CreateProgramOptions = { + const options: ts.CreateProgramOptions = { rootNames: cmdOptions.inputFiles, options: { target: ts.ScriptTarget.Latest, diff --git a/linter/src/ts-diagnostics/GetTscDiagnostics.ts b/linter/src/ts-diagnostics/GetTscDiagnostics.ts index 3b75a69aa48a899d9c67fbab01af16349f8960ed..dd592cff142d3822981423172973325416763b00 100644 --- a/linter/src/ts-diagnostics/GetTscDiagnostics.ts +++ b/linter/src/ts-diagnostics/GetTscDiagnostics.ts @@ -26,12 +26,12 @@ import { TSCCompiledProgram } from './TSCCompiledProgram'; */ export function getTscDiagnostics( tscDiagnosticsLinter: TSCCompiledProgram, - sourceFiles: ts.SourceFile[], + sourceFiles: ts.SourceFile[] ): Map { const strictDiagnostics = new Map(); sourceFiles.forEach(file => { const diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file.fileName); - if (diagnostics.length != 0) { + if (diagnostics.length !== 0) { strictDiagnostics.set(path.normalize(file.fileName), diagnostics); } }); diff --git a/linter/src/ts-diagnostics/TSCCompiledProgram.ts b/linter/src/ts-diagnostics/TSCCompiledProgram.ts index 36faaf7c35e1906207c214a9a0c7958dbc002593..064f2ac53e5511f0a4a502a436cb28a473e03111 100644 --- a/linter/src/ts-diagnostics/TSCCompiledProgram.ts +++ b/linter/src/ts-diagnostics/TSCCompiledProgram.ts @@ -19,7 +19,7 @@ import { ProblemSeverity } from '../ProblemSeverity'; import { LintOptions } from '../LintOptions'; import { TypeScriptDiagnosticsExtractor } from './TypeScriptDiagnosticsExtractor'; import { compile } from '../CompilerWrapper'; -import { FaultID } from '../utils/consts/Problems'; +import { FaultID } from '../Problems'; import { faultsAttrs } from '../FaultAttrs'; export interface TSCCompiledProgram { @@ -38,7 +38,7 @@ export class TSCCompiledProgramSimple implements TSCCompiledProgram { return this.tsProgram; } - public getStrictDiagnostics(fileName: string): ts.Diagnostic[] { + public getStrictDiagnostics(): ts.Diagnostic[] { return []; } } @@ -46,36 +46,46 @@ export class TSCCompiledProgramSimple implements TSCCompiledProgram { export class TSCCompiledProgramWithDiagnostics implements TSCCompiledProgram { private diagnosticsExtractor: TypeScriptDiagnosticsExtractor; private wasStrict: boolean; + private cachedDiagnostics: Map; constructor(program: ts.Program, options: LintOptions) { const { strict, nonStrict, wasStrict } = getTwoCompiledVersions(program, options); this.diagnosticsExtractor = new TypeScriptDiagnosticsExtractor(strict, nonStrict); this.wasStrict = wasStrict; + this.cachedDiagnostics = new Map(); } public getOriginalProgram(): ts.Program { - return this.wasStrict ? this.diagnosticsExtractor.strictProgram : this.diagnosticsExtractor.nonStrictProgram; + return this.wasStrict + ? this.diagnosticsExtractor.strictProgram + : this.diagnosticsExtractor.nonStrictProgram; } public getStrictDiagnostics(fileName: string): ts.Diagnostic[] { - return this.diagnosticsExtractor.getStrictDiagnostics(fileName); + const cachedDiagnostic = this.cachedDiagnostics.get(fileName); + if (cachedDiagnostic) { + return cachedDiagnostic; + } + const diagnostic = this.diagnosticsExtractor.getStrictDiagnostics(fileName); + this.cachedDiagnostics.set(fileName, diagnostic); + return diagnostic; } } -export function getStrictOptions(strict: boolean = true) { +export function getStrictOptions(strict = true) { return { strictNullChecks: strict, strictFunctionTypes: strict, strictPropertyInitialization: strict, noImplicitReturns: strict, - } + }; } function getTwoCompiledVersions( program: ts.Program, - options: LintOptions, + options: LintOptions ): { strict: ts.Program; nonStrict: ts.Program; wasStrict: boolean } { - const compilerOptions = { ...program.getCompilerOptions()}; + const compilerOptions = { ...program.getCompilerOptions() }; const wasStrict = inverseStrictOptions(compilerOptions); const inversedOptions = getStrictOptions(!wasStrict); @@ -85,7 +95,7 @@ function getTwoCompiledVersions( strict: wasStrict ? program : withInversedOptions, nonStrict: wasStrict ? withInversedOptions : program, wasStrict: wasStrict, - } + }; } /** @@ -117,7 +127,7 @@ export function transformDiagnostic(diagnostic: ts.Diagnostic): ProblemInfo { start: startPos, end: endPos, type: 'StrictModeError', - severity: ProblemSeverity.ERROR, // expect strict options to always present + severity: ProblemSeverity.ERROR, // expect strict options to always present problem: FaultID[faultId], suggest: messageText, rule: messageText, @@ -130,10 +140,10 @@ export function transformDiagnostic(diagnostic: ts.Diagnostic): ProblemInfo { * Returns line and column of the position, counts from 1 */ function getLineAndColumn(file: ts.SourceFile, position: number): { line: number; column: number } { - let { line, character } = file.getLineAndCharacterOfPosition(position); + const { line, character } = file.getLineAndCharacterOfPosition(position); // TSC counts lines and columns from zero return { line: line + 1, column: character + 1, - } + }; } diff --git a/linter/src/ts-diagnostics/TransformTscDiagnostics.ts b/linter/src/ts-diagnostics/TransformTscDiagnostics.ts index 9c644117e5455d062eb5960112039987fea1f106..fb3c7c2a055af6a3fc004638abc9b12c8c9e3fc5 100644 --- a/linter/src/ts-diagnostics/TransformTscDiagnostics.ts +++ b/linter/src/ts-diagnostics/TransformTscDiagnostics.ts @@ -21,8 +21,11 @@ export function transformTscDiagnostics( strictDiagnostics: Map ): Map { const problemsInfos = new Map(); - strictDiagnostics.forEach((diagnostics, file, map) => { - problemsInfos.set(file, diagnostics.map(x => transformDiagnostic(x))); + strictDiagnostics.forEach((diagnostics, file) => { + problemsInfos.set( + file, + diagnostics.map(x => transformDiagnostic(x)) + ); }); return problemsInfos; } diff --git a/linter/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts b/linter/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts index 0d5106dd9f116531b356ca406fc9f4fff8ef053a..e9e76b3d18cc4a3489e1ac8737f8fb862e231b6f 100644 --- a/linter/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts +++ b/linter/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts @@ -16,16 +16,16 @@ import * as ts from 'typescript'; export class TypeScriptDiagnosticsExtractor { - constructor(public strictProgram: ts.Program, public nonStrictProgram: ts.Program) { - } + constructor(public strictProgram: ts.Program, public nonStrictProgram: ts.Program) {} /** * Returns diagnostics which appear in strict compilation mode only */ public getStrictDiagnostics(fileName: string): ts.Diagnostic[] { // applying filter is a workaround for tsc bug - const strict = getAllDiagnostics(this.strictProgram, fileName) - .filter(diag => !(diag.length === 0 && diag.start === 0)); + const strict = getAllDiagnostics(this.strictProgram, fileName).filter( + diag => !(diag.length === 0 && diag.start === 0) + ); const nonStrict = getAllDiagnostics(this.nonStrictProgram, fileName); // collect hashes for later easier comparison @@ -39,14 +39,15 @@ export class TypeScriptDiagnosticsExtractor { // return diagnostics which weren't detected in non-strict mode return strict.filter(value => { const hash = hashDiagnostic(value); - return (hash && !nonStrictHashes.has(hash)); + return hash && !nonStrictHashes.has(hash); }); } } function getAllDiagnostics(program: ts.Program, fileName: string): ts.Diagnostic[] { const sourceFile = program.getSourceFile(fileName); - return program.getSemanticDiagnostics(sourceFile) + return program + .getSemanticDiagnostics(sourceFile) .concat(program.getSyntacticDiagnostics(sourceFile)) .filter(diag => diag.file === sourceFile); } diff --git a/linter/src/utils/TsUtils.ts b/linter/src/utils/TsUtils.ts index c2ee9fef0a07aa042a99b1a72659d54ba6aa9ad1..e49bd1f8c02bbbae700b318f6a1db3d9c5f909af 100644 --- a/linter/src/utils/TsUtils.ts +++ b/linter/src/utils/TsUtils.ts @@ -15,33 +15,26 @@ import * as ts from 'typescript'; import * as path from 'node:path'; -import { STANDARD_LIBRARIES } from './consts/StandardLibraries'; -import { TYPED_ARRAYS } from './consts/TypedArrays'; -import { ES_OBJECT } from './consts/ESObject'; -import { isIntrinsicObjectType } from './functions/isIntrinsicObjectType'; -import { isStdLibraryType } from './functions/IsStdLibrary'; -import { isStructDeclaration, isStructDeclarationKind } from './functions/IsStruct'; -import { pathContainsDirectory } from './functions/PathHelper'; -import { ARKTS_IGNORE_DIRS, ARKTS_IGNORE_FILES } from './consts/ArktsIgnorePaths'; -import { isAssignmentOperator } from './functions/isAssignmentOperator'; - -export enum CheckType { - Array, - String = 'String', - Set = 'Set', - Map = 'Map', - Error = 'Error' -}; +import {STANDARD_LIBRARIES} from './consts/StandardLibraries'; +import {TYPED_ARRAYS} from './consts/TypedArrays'; +import {ES_OBJECT} from './consts/ESObject'; +import {isIntrinsicObjectType} from './functions/isIntrinsicObjectType'; +import {isStdLibraryType} from './functions/IsStdLibrary'; +import { + isStructDeclaration, + isStructDeclarationKind, +} from './functions/IsStruct'; +import {pathContainsDirectory} from './functions/PathHelper'; +import {ARKTS_IGNORE_DIRS, ARKTS_IGNORE_FILES} from './consts/ArktsIgnorePaths'; +import {isAssignmentOperator} from './functions/isAssignmentOperator'; + +export type CheckType = (t: ts.Type) => boolean; export class TsUtils { - constructor(private tsTypeChecker: ts.TypeChecker, private testMode: boolean, private advancedClassChecks: boolean) { - } - - public isTypedArray(tsType: ts.TypeNode | undefined): boolean { - if (tsType === undefined || !ts.isTypeReferenceNode(tsType)) { - return false; - } - return TYPED_ARRAYS.includes(this.entityNameToString(tsType.typeName)); - } + constructor( + private tsTypeChecker: ts.TypeChecker, + private testMode: boolean, + private advancedClassChecks: boolean + ) {} public isType(tsType: ts.TypeNode | undefined, checkType: string): boolean { if (tsType === undefined || !ts.isTypeReferenceNode(tsType)) { @@ -54,13 +47,15 @@ export class TsUtils { if (ts.isIdentifier(name)) { return name.escapedText.toString(); } else { - return this.entityNameToString(name.left) + this.entityNameToString(name.right); + return ( + this.entityNameToString(name.left) + this.entityNameToString(name.right) + ); } } public isNumberType(tsType: ts.Type): boolean { if (tsType.isUnion()) { - for (let tsCompType of tsType.types) { + for (const tsCompType of tsType.types) { if ((tsCompType.flags & ts.TypeFlags.NumberLike) === 0) return false; } return true; @@ -74,7 +69,7 @@ export class TsUtils { public isStringLikeType(tsType: ts.Type): boolean { if (tsType.isUnion()) { - for (let tsCompType of tsType.types) { + for (const tsCompType of tsType.types) { if ((tsCompType.flags & ts.TypeFlags.StringLike) === 0) return false; } return true; @@ -86,7 +81,10 @@ export class TsUtils { return (type.getFlags() & ts.TypeFlags.String) !== 0; } - public isPrimitiveEnumType(type: ts.Type, primitiveType: ts.TypeFlags): boolean { + public isPrimitiveEnumType( + type: ts.Type, + primitiveType: ts.TypeFlags + ): boolean { const isNonPrimitive = (type.flags & ts.TypeFlags.NonPrimitive) !== 0; if (!this.isEnumType(type) || !type.isUnion() || isNonPrimitive) { return false; @@ -99,7 +97,10 @@ export class TsUtils { return true; } - public isPrimitiveEnumMemberType(type: ts.Type, primitiveType: ts.TypeFlags): boolean { + public isPrimitiveEnumMemberType( + type: ts.Type, + primitiveType: ts.TypeFlags + ): boolean { const isNonPrimitive = (type.flags & ts.TypeFlags.NonPrimitive) !== 0; if (!this.isEnumMemberType(type) || isNonPrimitive) { return false; @@ -135,14 +136,18 @@ export class TsUtils { let tsCurrentExpr: ts.Node = tsExpr; while (tsParent) { if ( - ts.isBinaryExpression(tsParent) && isAssignmentOperator(tsParent.operatorToken) && + ts.isBinaryExpression(tsParent) && + isAssignmentOperator(tsParent.operatorToken) && tsParent.left === tsCurrentExpr ) return true; if ( - (ts.isForStatement(tsParent) || ts.isForInStatement(tsParent) || ts.isForOfStatement(tsParent)) && - tsParent.initializer && tsParent.initializer === tsCurrentExpr + (ts.isForStatement(tsParent) || + ts.isForInStatement(tsParent) || + ts.isForOfStatement(tsParent)) && + tsParent.initializer && + tsParent.initializer === tsCurrentExpr ) return true; @@ -162,18 +167,26 @@ export class TsUtils { public isEnumMemberType(tsType: ts.Type): boolean { // Note: For some reason, test (tsType.flags & ts.TypeFlags.Enum) != 0 doesn't work here. // Must use SymbolFlags to figure out if this is an enum type. - return tsType.symbol && (tsType.symbol.flags & ts.SymbolFlags.EnumMember) !== 0; + return ( + tsType.symbol && (tsType.symbol.flags & ts.SymbolFlags.EnumMember) !== 0 + ); } public isObjectLiteralType(tsType: ts.Type): boolean { - return tsType.symbol && (tsType.symbol.flags & ts.SymbolFlags.ObjectLiteral) !== 0; + return ( + tsType.symbol && + (tsType.symbol.flags & ts.SymbolFlags.ObjectLiteral) !== 0 + ); } public isNumberLikeType(tsType: ts.Type): boolean { return (tsType.getFlags() & ts.TypeFlags.NumberLike) !== 0; } - public hasModifier(tsModifiers: readonly ts.Modifier[] | undefined, tsModifierKind: number): boolean { + public hasModifier( + tsModifiers: readonly ts.Modifier[] | undefined, + tsModifierKind: number + ): boolean { // Sanity check. if (!tsModifiers) return false; @@ -198,12 +211,12 @@ export class TsUtils { } return sym; } - + private trueSymbolAtLocationCache = new Map(); public trueSymbolAtLocation(node: ts.Node): ts.Symbol | undefined { - let cache = this.trueSymbolAtLocationCache; - let val = cache.get(node); + const cache = this.trueSymbolAtLocationCache; + const val = cache.get(node); if (val !== undefined) { return val !== null ? val : undefined; } @@ -218,14 +231,19 @@ export class TsUtils { } private isTypeDeclSyntaxKind(kind: ts.SyntaxKind) { - return isStructDeclarationKind(kind) || + return ( + isStructDeclarationKind(kind) || kind === ts.SyntaxKind.EnumDeclaration || kind === ts.SyntaxKind.ClassDeclaration || kind === ts.SyntaxKind.InterfaceDeclaration || - kind === ts.SyntaxKind.TypeAliasDeclaration; + kind === ts.SyntaxKind.TypeAliasDeclaration + ); } - public symbolHasDuplicateName(symbol: ts.Symbol, tsDeclKind: ts.SyntaxKind): boolean { + public symbolHasDuplicateName( + symbol: ts.Symbol, + tsDeclKind: ts.SyntaxKind + ): boolean { // Type Checker merges all declarations with the same name in one scope into one symbol. // Thus, check whether the symbol of certain declaration has any declaration with // different syntax kind. @@ -235,12 +253,19 @@ export class TsUtils { const declKind = symDecl.kind; // we relax arkts-unique-names for namespace collision with class/interface/enum/type/struct const isNamespaceTypeCollision = - (this.isTypeDeclSyntaxKind(declKind) && tsDeclKind === ts.SyntaxKind.ModuleDeclaration) || - (this.isTypeDeclSyntaxKind(tsDeclKind) && declKind === ts.SyntaxKind.ModuleDeclaration) + (this.isTypeDeclSyntaxKind(declKind) && + tsDeclKind === ts.SyntaxKind.ModuleDeclaration) || + (this.isTypeDeclSyntaxKind(tsDeclKind) && + declKind === ts.SyntaxKind.ModuleDeclaration); // Don't count declarations with 'Identifier' syntax kind as those // usually depict declaring an object's property through assignment. - if (declKind !== ts.SyntaxKind.Identifier && declKind !== tsDeclKind && !isNamespaceTypeCollision) return true; + if ( + declKind !== ts.SyntaxKind.Identifier && + declKind !== tsDeclKind && + !isNamespaceTypeCollision + ) + return true; } } @@ -250,17 +275,23 @@ export class TsUtils { public isReferenceType(tsType: ts.Type): boolean { const f = tsType.getFlags(); return ( - (f & ts.TypeFlags.InstantiableNonPrimitive) != 0 || (f & ts.TypeFlags.Object) != 0 || - (f & ts.TypeFlags.Boolean) != 0 || (f & ts.TypeFlags.Enum) != 0 || (f & ts.TypeFlags.NonPrimitive) != 0 || - (f & ts.TypeFlags.Number) != 0 || (f & ts.TypeFlags.String) != 0 + (f & ts.TypeFlags.InstantiableNonPrimitive) != 0 || + (f & ts.TypeFlags.Object) != 0 || + (f & ts.TypeFlags.Boolean) != 0 || + (f & ts.TypeFlags.Enum) != 0 || + (f & ts.TypeFlags.NonPrimitive) != 0 || + (f & ts.TypeFlags.Number) != 0 || + (f & ts.TypeFlags.String) != 0 ); } public isPrimitiveType(type: ts.Type): boolean { const f = type.getFlags(); return ( - (f & ts.TypeFlags.Boolean) != 0 || (f & ts.TypeFlags.BooleanLiteral) != 0 || - (f & ts.TypeFlags.Number) != 0 || (f & ts.TypeFlags.NumberLiteral) != 0 + (f & ts.TypeFlags.Boolean) != 0 || + (f & ts.TypeFlags.BooleanLiteral) != 0 || + (f & ts.TypeFlags.Number) != 0 || + (f & ts.TypeFlags.NumberLiteral) != 0 // In ArkTS 'string' is not a primitive type. So for the common subset 'string' // should be considered as a reference type. That is why next line is commented out. //(f & ts.TypeFlags.String) != 0 || (f & ts.TypeFlags.StringLiteral) != 0 @@ -269,37 +300,72 @@ export class TsUtils { public isTypeSymbol(symbol: ts.Symbol | undefined): boolean { return ( - !!symbol && !!symbol.flags && - ((symbol.flags & ts.SymbolFlags.Class) !== 0 || (symbol.flags & ts.SymbolFlags.Interface) !== 0) + !!symbol && + !!symbol.flags && + ((symbol.flags & ts.SymbolFlags.Class) !== 0 || + (symbol.flags & ts.SymbolFlags.Interface) !== 0) ); } // Check whether type is generic 'Array' type defined in TypeScript standard library. public isGenericArrayType(tsType: ts.Type): tsType is ts.TypeReference { return ( - this.isTypeReference(tsType) && tsType.typeArguments?.length === 1 && tsType.target.typeParameters?.length === 1 && + this.isTypeReference(tsType) && + tsType.typeArguments?.length === 1 && + tsType.target.typeParameters?.length === 1 && tsType.getSymbol()?.getName() === 'Array' ); } + public isTypedArray(tsType: ts.Type): boolean { + const symbol = tsType.symbol; + if (!symbol) { + return false; + } + const name = this.tsTypeChecker.getFullyQualifiedName(symbol); + return this.isGlobalSymbol(symbol) && TYPED_ARRAYS.includes(name); + } + + public isArray(tsType: ts.Type): boolean { + return this.isGenericArrayType(tsType) || this.isTypedArray(tsType); + } + + public isTuple(tsType: ts.Type): boolean { + return ( + this.isTypeReference(tsType) && + !!(tsType.objectFlags & ts.ObjectFlags.Tuple) + ); + } + // does something similar to relatedByInheritanceOrIdentical function - public isDerivedFrom(tsType: ts.Type, checkType: CheckType): tsType is ts.TypeReference { - if (this.isTypeReference(tsType) && tsType.target !== tsType) tsType = tsType.target; + public isOrDerivedFrom( + tsType: ts.Type, + checkType: CheckType + ): tsType is ts.TypeReference { + if (this.isTypeReference(tsType) && tsType.target !== tsType) { + tsType = tsType.target; + } - const tsTypeNode = this.tsTypeChecker.typeToTypeNode(tsType, undefined, ts.NodeBuilderFlags.None); - if (checkType == CheckType.Array && (this.isGenericArrayType(tsType) || this.isTypedArray(tsTypeNode))) - return true; - if (checkType != CheckType.Array && this.isType(tsTypeNode, checkType.toString())) + if (checkType.call(this, tsType)) { return true; - if (!tsType.symbol || !tsType.symbol.declarations) return false; + } - for (let tsTypeDecl of tsType.symbol.declarations) { - if ( - (!ts.isClassDeclaration(tsTypeDecl) && !ts.isInterfaceDeclaration(tsTypeDecl)) || - !tsTypeDecl.heritageClauses - ) continue; - for (let heritageClause of tsTypeDecl.heritageClauses) { - if (this.processParentTypesCheck(heritageClause.types, checkType)) return true; + if (!tsType.symbol || !tsType.symbol.declarations) { + return false; + } + + for (const tsTypeDecl of tsType.symbol.declarations) { + const isClassOrInterfaceDecl = + ts.isClassDeclaration(tsTypeDecl) || + ts.isInterfaceDeclaration(tsTypeDecl); + const isDerived = isClassOrInterfaceDecl && !!tsTypeDecl.heritageClauses; + if (!isDerived) { + continue; + } + for (const heritageClause of tsTypeDecl.heritageClauses) { + if (this.processParentTypesCheck(heritageClause.types, checkType)) { + return true; + } } } @@ -314,24 +380,40 @@ export class TsUtils { } public isNullType(tsTypeNode: ts.TypeNode): boolean { - return (ts.isLiteralTypeNode(tsTypeNode) && tsTypeNode.literal.kind === ts.SyntaxKind.NullKeyword); + return ( + ts.isLiteralTypeNode(tsTypeNode) && + tsTypeNode.literal.kind === ts.SyntaxKind.NullKeyword + ); } public isThisOrSuperExpr(tsExpr: ts.Expression): boolean { - return (tsExpr.kind == ts.SyntaxKind.ThisKeyword || tsExpr.kind == ts.SyntaxKind.SuperKeyword); + return ( + tsExpr.kind == ts.SyntaxKind.ThisKeyword || + tsExpr.kind == ts.SyntaxKind.SuperKeyword + ); } public isPrototypeSymbol(symbol: ts.Symbol | undefined): boolean { - return (!!symbol && !!symbol.flags && (symbol.flags & ts.SymbolFlags.Prototype) !== 0); + return ( + !!symbol && + !!symbol.flags && + (symbol.flags & ts.SymbolFlags.Prototype) !== 0 + ); } public isFunctionSymbol(symbol: ts.Symbol | undefined): boolean { - return (!!symbol && !!symbol.flags && (symbol.flags & ts.SymbolFlags.Function) !== 0); + return ( + !!symbol && + !!symbol.flags && + (symbol.flags & ts.SymbolFlags.Function) !== 0 + ); } public isInterfaceType(tsType: ts.Type | undefined): boolean { return ( - !!tsType && !!tsType.symbol && !!tsType.symbol.flags && + !!tsType && + !!tsType.symbol && + !!tsType.symbol.flags && (tsType.symbol.flags & ts.SymbolFlags.Interface) !== 0 ); } @@ -346,7 +428,9 @@ export class TsUtils { public isUnsupportedType(tsType: ts.Type): boolean { return ( - !!tsType.flags && ((tsType.flags & ts.TypeFlags.Any) !== 0 || (tsType.flags & ts.TypeFlags.Unknown) !== 0 || + !!tsType.flags && + ((tsType.flags & ts.TypeFlags.Any) !== 0 || + (tsType.flags & ts.TypeFlags.Unknown) !== 0 || (tsType.flags & ts.TypeFlags.Intersection) !== 0) ); } @@ -354,7 +438,10 @@ export class TsUtils { public isNullableUnionType(type: ts.Type): boolean { if (type.isUnion()) { for (const t of type.types) { - if (!!(t.flags & ts.TypeFlags.Undefined) || !!(t.flags & ts.TypeFlags.Null)) { + if ( + !!(t.flags & ts.TypeFlags.Undefined) || + !!(t.flags & ts.TypeFlags.Null) + ) { return true; } } @@ -365,49 +452,62 @@ export class TsUtils { public isFunctionOrMethod(tsSymbol: ts.Symbol | undefined): boolean { return ( !!tsSymbol && - ((tsSymbol.flags & ts.SymbolFlags.Function) !== 0 || (tsSymbol.flags & ts.SymbolFlags.Method) !== 0) + ((tsSymbol.flags & ts.SymbolFlags.Function) !== 0 || + (tsSymbol.flags & ts.SymbolFlags.Method) !== 0) ); } public isMethodAssignment(tsSymbol: ts.Symbol | undefined): boolean { return ( !!tsSymbol && - ((tsSymbol.flags & ts.SymbolFlags.Method) !== 0 && (tsSymbol.flags & ts.SymbolFlags.Assignment) !== 0) + (tsSymbol.flags & ts.SymbolFlags.Method) !== 0 && + (tsSymbol.flags & ts.SymbolFlags.Assignment) !== 0 ); } - public getDeclaration(tsSymbol: ts.Symbol | undefined): ts.Declaration | undefined { + public getDeclaration( + tsSymbol: ts.Symbol | undefined + ): ts.Declaration | undefined { if (tsSymbol && tsSymbol.declarations && tsSymbol.declarations.length > 0) return tsSymbol.declarations[0]; return undefined; } private isVarDeclaration(tsDecl: ts.Node): boolean { - return ts.isVariableDeclaration(tsDecl) && ts.isVariableDeclarationList(tsDecl.parent); + return ( + ts.isVariableDeclaration(tsDecl) && + ts.isVariableDeclarationList(tsDecl.parent) + ); } public isValidEnumMemberInit(tsExpr: ts.Expression): boolean { - if (this.isNumberConstantValue(tsExpr.parent as ts.EnumMember)) - return true; - if (this.isStringConstantValue(tsExpr.parent as ts.EnumMember)) - return true; + if (this.isNumberConstantValue(tsExpr.parent as ts.EnumMember)) return true; + if (this.isStringConstantValue(tsExpr.parent as ts.EnumMember)) return true; return this.isCompileTimeExpression(tsExpr); } public isCompileTimeExpression(tsExpr: ts.Expression): boolean { if ( ts.isParenthesizedExpression(tsExpr) || - (ts.isAsExpression(tsExpr) && tsExpr.type.kind === ts.SyntaxKind.NumberKeyword)) + (ts.isAsExpression(tsExpr) && + tsExpr.type.kind === ts.SyntaxKind.NumberKeyword) + ) return this.isCompileTimeExpression(tsExpr.expression); switch (tsExpr.kind) { case ts.SyntaxKind.PrefixUnaryExpression: - return this.isPrefixUnaryExprValidEnumMemberInit(tsExpr as ts.PrefixUnaryExpression); + return this.isPrefixUnaryExprValidEnumMemberInit( + tsExpr as ts.PrefixUnaryExpression + ); case ts.SyntaxKind.ParenthesizedExpression: case ts.SyntaxKind.BinaryExpression: - return this.isBinaryExprValidEnumMemberInit(tsExpr as ts.BinaryExpression); + return this.isBinaryExprValidEnumMemberInit( + tsExpr as ts.BinaryExpression + ); case ts.SyntaxKind.ConditionalExpression: - return this.isConditionalExprValidEnumMemberInit(tsExpr as ts.ConditionalExpression); + return this.isConditionalExprValidEnumMemberInit( + tsExpr as ts.ConditionalExpression + ); case ts.SyntaxKind.Identifier: return this.isIdentifierValidEnumMemberInit(tsExpr as ts.Identifier); case ts.SyntaxKind.NumericLiteral: @@ -418,14 +518,13 @@ export class TsUtils { // if enum member is in current enum declaration try to get value // if it comes from another enum consider as constant const propertyAccess = tsExpr as ts.PropertyAccessExpression; - if (this.isNumberConstantValue(propertyAccess)) - return true; - const leftHandSymbol = this.trueSymbolAtLocation(propertyAccess.expression); - if (!leftHandSymbol) - return false; + if (this.isNumberConstantValue(propertyAccess)) return true; + const leftHandSymbol = this.trueSymbolAtLocation( + propertyAccess.expression + ); + if (!leftHandSymbol) return false; const decls = leftHandSymbol.getDeclarations(); - if (!decls || decls.length !== 1) - return false; + if (!decls || decls.length !== 1) return false; return ts.isEnumDeclaration(decls[0]); } default: @@ -433,47 +532,72 @@ export class TsUtils { } } - private isPrefixUnaryExprValidEnumMemberInit(tsExpr: ts.PrefixUnaryExpression): boolean { - return (this.isUnaryOpAllowedForEnumMemberInit(tsExpr.operator) && this.isCompileTimeExpression(tsExpr.operand)); + private isPrefixUnaryExprValidEnumMemberInit( + tsExpr: ts.PrefixUnaryExpression + ): boolean { + return ( + this.isUnaryOpAllowedForEnumMemberInit(tsExpr.operator) && + this.isCompileTimeExpression(tsExpr.operand) + ); } - private isBinaryExprValidEnumMemberInit(tsExpr: ts.BinaryExpression): boolean { + private isBinaryExprValidEnumMemberInit( + tsExpr: ts.BinaryExpression + ): boolean { return ( - this.isBinaryOpAllowedForEnumMemberInit(tsExpr.operatorToken) && this.isCompileTimeExpression(tsExpr.left) && + this.isBinaryOpAllowedForEnumMemberInit(tsExpr.operatorToken) && + this.isCompileTimeExpression(tsExpr.left) && this.isCompileTimeExpression(tsExpr.right) ); } - private isConditionalExprValidEnumMemberInit(tsExpr: ts.ConditionalExpression): boolean { - return (this.isCompileTimeExpression(tsExpr.whenTrue) && this.isCompileTimeExpression(tsExpr.whenFalse)); + private isConditionalExprValidEnumMemberInit( + tsExpr: ts.ConditionalExpression + ): boolean { + return ( + this.isCompileTimeExpression(tsExpr.whenTrue) && + this.isCompileTimeExpression(tsExpr.whenFalse) + ); } private isIdentifierValidEnumMemberInit(tsExpr: ts.Identifier): boolean { - let tsSymbol = this.trueSymbolAtLocation(tsExpr); - let tsDecl = this.getDeclaration(tsSymbol); - return (!!tsDecl && + const tsSymbol = this.trueSymbolAtLocation(tsExpr); + const tsDecl = this.getDeclaration(tsSymbol); + return ( + !!tsDecl && ((this.isVarDeclaration(tsDecl) && this.isConst(tsDecl.parent)) || - (tsDecl.kind === ts.SyntaxKind.EnumMember) - ) + tsDecl.kind === ts.SyntaxKind.EnumMember) ); } - private isUnaryOpAllowedForEnumMemberInit(tsPrefixUnaryOp: ts.PrefixUnaryOperator): boolean { + private isUnaryOpAllowedForEnumMemberInit( + tsPrefixUnaryOp: ts.PrefixUnaryOperator + ): boolean { return ( - tsPrefixUnaryOp === ts.SyntaxKind.PlusToken || tsPrefixUnaryOp === ts.SyntaxKind.MinusToken || + tsPrefixUnaryOp === ts.SyntaxKind.PlusToken || + tsPrefixUnaryOp === ts.SyntaxKind.MinusToken || tsPrefixUnaryOp === ts.SyntaxKind.TildeToken ); } - private isBinaryOpAllowedForEnumMemberInit(tsBinaryOp: ts.BinaryOperatorToken): boolean { + private isBinaryOpAllowedForEnumMemberInit( + tsBinaryOp: ts.BinaryOperatorToken + ): boolean { return ( - tsBinaryOp.kind === ts.SyntaxKind.AsteriskToken || tsBinaryOp.kind === ts.SyntaxKind.SlashToken || - tsBinaryOp.kind === ts.SyntaxKind.PercentToken || tsBinaryOp.kind === ts.SyntaxKind.MinusToken || - tsBinaryOp.kind === ts.SyntaxKind.PlusToken || tsBinaryOp.kind === ts.SyntaxKind.LessThanLessThanToken || - tsBinaryOp.kind === ts.SyntaxKind.GreaterThanGreaterThanToken || tsBinaryOp.kind === ts.SyntaxKind.BarBarToken || - tsBinaryOp.kind === ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken || - tsBinaryOp.kind === ts.SyntaxKind.AmpersandToken || tsBinaryOp.kind === ts.SyntaxKind.CaretToken || - tsBinaryOp.kind === ts.SyntaxKind.BarToken || tsBinaryOp.kind === ts.SyntaxKind.AmpersandAmpersandToken + tsBinaryOp.kind === ts.SyntaxKind.AsteriskToken || + tsBinaryOp.kind === ts.SyntaxKind.SlashToken || + tsBinaryOp.kind === ts.SyntaxKind.PercentToken || + tsBinaryOp.kind === ts.SyntaxKind.MinusToken || + tsBinaryOp.kind === ts.SyntaxKind.PlusToken || + tsBinaryOp.kind === ts.SyntaxKind.LessThanLessThanToken || + tsBinaryOp.kind === ts.SyntaxKind.GreaterThanGreaterThanToken || + tsBinaryOp.kind === ts.SyntaxKind.BarBarToken || + tsBinaryOp.kind === + ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken || + tsBinaryOp.kind === ts.SyntaxKind.AmpersandToken || + tsBinaryOp.kind === ts.SyntaxKind.CaretToken || + tsBinaryOp.kind === ts.SyntaxKind.BarToken || + tsBinaryOp.kind === ts.SyntaxKind.AmpersandAmpersandToken ); } @@ -482,54 +606,80 @@ export class TsUtils { } public isNumberConstantValue( - tsExpr: ts.EnumMember | ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.NumericLiteral + tsExpr: + | ts.EnumMember + | ts.PropertyAccessExpression + | ts.ElementAccessExpression + | ts.NumericLiteral ): boolean { + const tsConstValue = + tsExpr.kind === ts.SyntaxKind.NumericLiteral + ? Number(tsExpr.getText()) + : this.tsTypeChecker.getConstantValue(tsExpr); - const tsConstValue = (tsExpr.kind === ts.SyntaxKind.NumericLiteral) ? - Number(tsExpr.getText()) : - this.tsTypeChecker.getConstantValue(tsExpr); - - return tsConstValue !== undefined && typeof tsConstValue === 'number'; + return tsConstValue !== undefined && typeof tsConstValue === 'number'; } public isIntegerConstantValue( - tsExpr: ts.EnumMember | ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.NumericLiteral + tsExpr: + | ts.EnumMember + | ts.PropertyAccessExpression + | ts.ElementAccessExpression + | ts.NumericLiteral ): boolean { - - const tsConstValue = (tsExpr.kind === ts.SyntaxKind.NumericLiteral) ? - Number(tsExpr.getText()) : - this.tsTypeChecker.getConstantValue(tsExpr); + const tsConstValue = + tsExpr.kind === ts.SyntaxKind.NumericLiteral + ? Number(tsExpr.getText()) + : this.tsTypeChecker.getConstantValue(tsExpr); return ( - tsConstValue !== undefined && typeof tsConstValue === 'number' && + tsConstValue !== undefined && + typeof tsConstValue === 'number' && tsConstValue.toFixed(0) === tsConstValue.toString() ); } public isStringConstantValue( - tsExpr: ts.EnumMember | ts.PropertyAccessExpression | ts.ElementAccessExpression + tsExpr: + | ts.EnumMember + | ts.PropertyAccessExpression + | ts.ElementAccessExpression ): boolean { const tsConstValue = this.tsTypeChecker.getConstantValue(tsExpr); - return ( - tsConstValue !== undefined && typeof tsConstValue === 'string' - ); + return tsConstValue !== undefined && typeof tsConstValue === 'string'; } // Returns true iff typeA is a subtype of typeB - public relatedByInheritanceOrIdentical(typeA: ts.Type, typeB: ts.Type): boolean { - if (this.isTypeReference(typeA) && typeA.target !== typeA) typeA = typeA.target; - if (this.isTypeReference(typeB) && typeB.target !== typeB) typeB = typeB.target; + public relatedByInheritanceOrIdentical( + typeA: ts.Type, + typeB: ts.Type + ): boolean { + if (this.isTypeReference(typeA) && typeA.target !== typeA) + typeA = typeA.target; + if (this.isTypeReference(typeB) && typeB.target !== typeB) + typeB = typeB.target; if (typeA === typeB || this.isObject(typeB)) return true; if (!typeA.symbol || !typeA.symbol.declarations) return false; - for (let typeADecl of typeA.symbol.declarations) { + for (const typeADecl of typeA.symbol.declarations) { if ( - (!ts.isClassDeclaration(typeADecl) && !ts.isInterfaceDeclaration(typeADecl)) || + (!ts.isClassDeclaration(typeADecl) && + !ts.isInterfaceDeclaration(typeADecl)) || !typeADecl.heritageClauses - ) continue; - for (let heritageClause of typeADecl.heritageClauses) { - let processInterfaces = typeA.isClass() ? (heritageClause.token != ts.SyntaxKind.ExtendsKeyword) : true; - if (this.processParentTypes(heritageClause.types, typeB, processInterfaces)) return true; + ) + continue; + for (const heritageClause of typeADecl.heritageClauses) { + const processInterfaces = typeA.isClass() + ? heritageClause.token != ts.SyntaxKind.ExtendsKeyword + : true; + if ( + this.processParentTypes( + heritageClause.types, + typeB, + processInterfaces + ) + ) + return true; } } @@ -537,8 +687,12 @@ export class TsUtils { } // return true if two class types are not related by inheritance and structural identity check is needed - public needToDeduceStructuralIdentity(lhsType: ts.Type, rhsType: ts.Type, rhsExpr: ts.Expression, - allowPromotion: boolean = false): boolean { + public needToDeduceStructuralIdentity( + lhsType: ts.Type, + rhsType: ts.Type, + rhsExpr: ts.Expression, + allowPromotion = false + ): boolean { // Compare non-nullable version of types. lhsType = this.getNonNullableType(lhsType); rhsType = this.getNonNullableType(rhsType); @@ -554,7 +708,14 @@ export class TsUtils { if (rhsType.isUnion()) { // Each Class/Interface of the RHS union type must be compatible with LHS type. for (const compType of rhsType.types) { - if (this.needToDeduceStructuralIdentity(lhsType, compType, rhsExpr, allowPromotion)) { + if ( + this.needToDeduceStructuralIdentity( + lhsType, + compType, + rhsExpr, + allowPromotion + ) + ) { return true; } } @@ -564,19 +725,34 @@ export class TsUtils { if (lhsType.isUnion()) { // RHS type needs to be compatible with at least one type of the LHS union. for (const compType of lhsType.types) { - if (!this.needToDeduceStructuralIdentity(compType, rhsType, rhsExpr, allowPromotion)) { + if ( + !this.needToDeduceStructuralIdentity( + compType, + rhsType, + rhsExpr, + allowPromotion + ) + ) { return false; } } return true; } - if (this.advancedClassChecks && this.isClassValueType(rhsType) && lhsType != rhsType && !this.isObjectType(lhsType)) { + if ( + this.advancedClassChecks && + this.isClassValueType(rhsType) && + lhsType != rhsType && + !this.isObjectType(lhsType) + ) { // missing exact rule return true; } - let res = lhsType.isClassOrInterface() && rhsType.isClassOrInterface() && !this.relatedByInheritanceOrIdentical(rhsType, lhsType); + let res = + lhsType.isClassOrInterface() && + rhsType.isClassOrInterface() && + !this.relatedByInheritanceOrIdentical(rhsType, lhsType); if (allowPromotion) { res &&= !this.relatedByInheritanceOrIdentical(lhsType, rhsType); @@ -585,20 +761,37 @@ export class TsUtils { return res; } - private processParentTypes(parentTypes: ts.NodeArray, typeB: ts.Type, processInterfaces: boolean): boolean { - for (let baseTypeExpr of parentTypes) { + private processParentTypes( + parentTypes: ts.NodeArray, + typeB: ts.Type, + processInterfaces: boolean + ): boolean { + for (const baseTypeExpr of parentTypes) { let baseType = this.tsTypeChecker.getTypeAtLocation(baseTypeExpr); - if (this.isTypeReference(baseType) && baseType.target !== baseType) baseType = baseType.target; - if (baseType && (baseType.isClass() != processInterfaces) && this.relatedByInheritanceOrIdentical(baseType, typeB)) return true; + if (this.isTypeReference(baseType) && baseType.target !== baseType) + baseType = baseType.target; + if ( + baseType && + baseType.isClass() != processInterfaces && + this.relatedByInheritanceOrIdentical(baseType, typeB) + ) + return true; } return false; } - private processParentTypesCheck(parentTypes: ts.NodeArray, checkType: CheckType): boolean { - for (let baseTypeExpr of parentTypes) { + private processParentTypesCheck( + parentTypes: ts.NodeArray, + checkType: CheckType + ): boolean { + for (const baseTypeExpr of parentTypes) { let baseType = this.tsTypeChecker.getTypeAtLocation(baseTypeExpr); - if (this.isTypeReference(baseType) && baseType.target !== baseType) baseType = baseType.target; - if (baseType && this.isDerivedFrom(baseType, checkType)) return true; + if (this.isTypeReference(baseType) && baseType.target !== baseType) { + baseType = baseType.target; + } + if (baseType && this.isOrDerivedFrom(baseType, checkType)) { + return true; + } } return false; } @@ -607,16 +800,24 @@ export class TsUtils { if (!tsType) { return false; } - if (tsType.symbol && (tsType.isClassOrInterface() && tsType.symbol.name === 'Object')) { + if ( + tsType.symbol && + tsType.isClassOrInterface() && + tsType.symbol.name === 'Object' + ) { return true; } - let node = this.tsTypeChecker.typeToTypeNode(tsType, undefined, undefined); + const node = this.tsTypeChecker.typeToTypeNode( + tsType, + undefined, + undefined + ); return node != undefined && node.kind === ts.SyntaxKind.ObjectKeyword; } public isCallToFunctionWithOmittedReturnType(tsExpr: ts.Expression): boolean { if (ts.isCallExpression(tsExpr)) { - let tsCallSignature = this.tsTypeChecker.getResolvedSignature(tsExpr); + const tsCallSignature = this.tsTypeChecker.getResolvedSignature(tsExpr); if (tsCallSignature) { const tsSignDecl = tsCallSignature.getDeclaration(); // `tsSignDecl` is undefined when `getResolvedSignature` returns `unknownSignature` @@ -630,14 +831,17 @@ export class TsUtils { private hasReadonlyFields(type: ts.Type): boolean { if (type.symbol.members === undefined) return false; // No members -> no readonly fields - let result: boolean = false; + let result = false; type.symbol.members.forEach((value, key) => { if ( - value.declarations !== undefined && value.declarations.length > 0 && + value.declarations !== undefined && + value.declarations.length > 0 && ts.isPropertyDeclaration(value.declarations[0]) ) { - let propmMods = ts.getModifiers(value.declarations[0] as ts.PropertyDeclaration); + const propmMods = ts.getModifiers( + value.declarations[0] as ts.PropertyDeclaration + ); if (this.hasModifier(propmMods, ts.SyntaxKind.ReadonlyKeyword)) { result = true; return; @@ -651,15 +855,15 @@ export class TsUtils { private hasDefaultCtor(type: ts.Type): boolean { if (type.symbol.members === undefined) return true; // No members -> no explicite constructors -> there is default ctor - let hasCtor: boolean = false; // has any constructor - let hasDefaultCtor: boolean = false; // has default constructor + let hasCtor = false; // has any constructor + let hasDefaultCtor = false; // has default constructor type.symbol.members.forEach((value, key) => { if ((value.flags & ts.SymbolFlags.Constructor) !== 0) { hasCtor = true; if (value.declarations !== undefined && value.declarations.length > 0) { - let declCtor = value.declarations[0] as ts.ConstructorDeclaration; + const declCtor = value.declarations[0] as ts.ConstructorDeclaration; if (declCtor.parameters.length === 0) { hasDefaultCtor = true; return; @@ -672,9 +876,13 @@ export class TsUtils { } private isAbstractClass(type: ts.Type): boolean { - if (type.isClass() && type.symbol.declarations && type.symbol.declarations.length > 0) { - let declClass = type.symbol.declarations[0] as ts.ClassDeclaration; - let classMods = ts.getModifiers(declClass); + if ( + type.isClass() && + type.symbol.declarations && + type.symbol.declarations.length > 0 + ) { + const declClass = type.symbol.declarations[0] as ts.ClassDeclaration; + const classMods = ts.getModifiers(declClass); if (this.hasModifier(classMods, ts.SyntaxKind.AbstractKeyword)) return true; } @@ -688,8 +896,10 @@ export class TsUtils { } type = this.getTargetType(type); return ( - type.isClassOrInterface() && this.hasDefaultCtor(type) && - !this.hasReadonlyFields(type) && !this.isAbstractClass(type) + type.isClassOrInterface() && + this.hasDefaultCtor(type) && + !this.hasReadonlyFields(type) && + !this.isAbstractClass(type) ); } @@ -714,11 +924,14 @@ export class TsUtils { return undefined; } - public checkTypeSet(uType: ts.Type, predicate: (t: ts.Type) => boolean): boolean { + public checkTypeSet( + uType: ts.Type, + predicate: (t: ts.Type) => boolean + ): boolean { if (!uType.isUnionOrIntersection()) { return predicate(uType); } - for (let elemType of uType.types) { + for (const elemType of uType.types) { if (!this.checkTypeSet(elemType, predicate)) { return false; } @@ -733,7 +946,10 @@ export class TsUtils { return t; } - public isObjectLiteralAssignable(lhsType: ts.Type | undefined, rhsExpr: ts.ObjectLiteralExpression): boolean { + public isObjectLiteralAssignable( + lhsType: ts.Type | undefined, + rhsExpr: ts.ObjectLiteralExpression + ): boolean { if (lhsType === undefined) { return false; } @@ -763,8 +979,15 @@ export class TsUtils { } // For Partial, Required, Readonly types, validate their argument type. - if (this.isStdPartialType(lhsType) || this.isStdRequiredType(lhsType) || this.isStdReadonlyType(lhsType)) { - if (lhsType.aliasTypeArguments && lhsType.aliasTypeArguments.length === 1) { + if ( + this.isStdPartialType(lhsType) || + this.isStdRequiredType(lhsType) || + this.isStdReadonlyType(lhsType) + ) { + if ( + lhsType.aliasTypeArguments && + lhsType.aliasTypeArguments.length === 1 + ) { lhsType = lhsType.aliasTypeArguments[0]; } else { return false; @@ -778,7 +1001,11 @@ export class TsUtils { return this.validateRecordObjectKeys(rhsExpr); } - return this.validateObjectLiteralType(lhsType) && !this.hasMethods(lhsType) && this.validateFields(lhsType, rhsExpr); + return ( + this.validateObjectLiteralType(lhsType) && + !this.hasMethods(lhsType) && + this.validateFields(lhsType, rhsExpr) + ); } isFunctionalType(type: ts.Type): boolean { @@ -786,25 +1013,30 @@ export class TsUtils { return callSigns && callSigns.length > 0; } - private isDynamicObjectAssignedToStdType(lhsType: ts.Type, rhsExpr: ts.Expression): boolean { + private isDynamicObjectAssignedToStdType( + lhsType: ts.Type, + rhsExpr: ts.Expression + ): boolean { if (isStdLibraryType(lhsType) || this.isPrimitiveType(lhsType)) { - let rhsSym = ts.isCallExpression(rhsExpr) + const rhsSym = ts.isCallExpression(rhsExpr) ? this.getSymbolOfCallExpression(rhsExpr) : this.trueSymbolAtLocation(rhsExpr); - if (rhsSym && this.isLibrarySymbol(rhsSym)) - return true; + if (rhsSym && this.isLibrarySymbol(rhsSym)) return true; } return false; } - validateFields(objectType: ts.Type, objectLiteral: ts.ObjectLiteralExpression): boolean { + validateFields( + objectType: ts.Type, + objectLiteral: ts.ObjectLiteralExpression + ): boolean { for (const prop of objectLiteral.properties) { if (ts.isPropertyAssignment(prop)) { if (!this.validateField(objectType, prop)) { return false; } } - }; + } return true; } @@ -816,15 +1048,24 @@ export class TsUtils { return false; } - const propType = this.tsTypeChecker.getTypeOfSymbolAtLocation(propSym, propSym.declarations[0]); + const propType = this.tsTypeChecker.getTypeOfSymbolAtLocation( + propSym, + propSym.declarations[0] + ); const initExpr = this.unwrapParenthesized(prop.initializer); if (ts.isObjectLiteralExpression(initExpr)) { if (!this.isObjectLiteralAssignable(propType, initExpr)) { return false; - } + } } else { // Only check for structural sub-typing. - if (this.needToDeduceStructuralIdentity(propType, this.tsTypeChecker.getTypeAtLocation(initExpr), initExpr)) { + if ( + this.needToDeduceStructuralIdentity( + propType, + this.tsTypeChecker.getTypeAtLocation(initExpr), + initExpr + ) + ) { return false; } } @@ -834,27 +1075,40 @@ export class TsUtils { validateRecordObjectKeys(objectLiteral: ts.ObjectLiteralExpression): boolean { for (const prop of objectLiteral.properties) { - if (!prop.name || (!ts.isStringLiteral(prop.name) && !ts.isNumericLiteral(prop.name))) return false; + if ( + !prop.name || + (!ts.isStringLiteral(prop.name) && !ts.isNumericLiteral(prop.name)) + ) + return false; } return true; } getTargetType(type: ts.Type): ts.Type { - return (type.getFlags() & ts.TypeFlags.Object) && - (type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference ? (type as ts.TypeReference).target : type; + return type.getFlags() & ts.TypeFlags.Object && + (type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference + ? (type as ts.TypeReference).target + : type; } private isSupportedTypeNodeKind(kind: ts.SyntaxKind): boolean { - return kind !== ts.SyntaxKind.AnyKeyword && kind !== ts.SyntaxKind.UnknownKeyword && - kind !== ts.SyntaxKind.SymbolKeyword && kind !== ts.SyntaxKind.IndexedAccessType && - kind !== ts.SyntaxKind.ConditionalType && kind !== ts.SyntaxKind.MappedType && - kind !== ts.SyntaxKind.InferType; + return ( + kind !== ts.SyntaxKind.AnyKeyword && + kind !== ts.SyntaxKind.UnknownKeyword && + kind !== ts.SyntaxKind.SymbolKeyword && + kind !== ts.SyntaxKind.IndexedAccessType && + kind !== ts.SyntaxKind.ConditionalType && + kind !== ts.SyntaxKind.MappedType && + kind !== ts.SyntaxKind.InferType + ); } public isSupportedType(typeNode: ts.TypeNode): boolean { - if (ts.isParenthesizedTypeNode(typeNode)) return this.isSupportedType(typeNode.type); + if (ts.isParenthesizedTypeNode(typeNode)) + return this.isSupportedType(typeNode.type); - if (ts.isArrayTypeNode(typeNode)) return this.isSupportedType(typeNode.elementType); + if (ts.isArrayTypeNode(typeNode)) + return this.isSupportedType(typeNode.elementType); if (ts.isTypeReferenceNode(typeNode) && typeNode.typeArguments) { for (const typeArg of typeNode.typeArguments) @@ -871,20 +1125,33 @@ export class TsUtils { if (ts.isTupleTypeNode(typeNode)) { for (const elem of typeNode.elements) { if (ts.isTypeNode(elem) && !this.isSupportedType(elem)) return false; - if (ts.isNamedTupleMember(elem) && !this.isSupportedType(elem.type)) return false; + if (ts.isNamedTupleMember(elem) && !this.isSupportedType(elem.type)) + return false; } return true; } - return !ts.isTypeLiteralNode(typeNode) && (this.advancedClassChecks || !ts.isTypeQueryNode(typeNode)) && - !ts.isIntersectionTypeNode(typeNode) && this.isSupportedTypeNodeKind(typeNode.kind); + return ( + !ts.isTypeLiteralNode(typeNode) && + (this.advancedClassChecks || !ts.isTypeQueryNode(typeNode)) && + !ts.isIntersectionTypeNode(typeNode) && + this.isSupportedTypeNodeKind(typeNode.kind) + ); } - public isStructObjectInitializer(objectLiteral: ts.ObjectLiteralExpression): boolean { + public isStructObjectInitializer( + objectLiteral: ts.ObjectLiteralExpression + ): boolean { if (ts.isCallLikeExpression(objectLiteral.parent)) { - const signature = this.tsTypeChecker.getResolvedSignature(objectLiteral.parent); + const signature = this.tsTypeChecker.getResolvedSignature( + objectLiteral.parent + ); const signDecl = signature?.declaration; - return !!signDecl && ts.isConstructorDeclaration(signDecl) && isStructDeclaration(signDecl.parent); + return ( + !!signDecl && + ts.isConstructorDeclaration(signDecl) && + isStructDeclaration(signDecl.parent) + ); } return false; } @@ -892,47 +1159,29 @@ export class TsUtils { public getParentSymbolName(symbol: ts.Symbol): string | undefined { const name = this.tsTypeChecker.getFullyQualifiedName(symbol); const dotPosition = name.lastIndexOf('.'); - return (dotPosition === -1) ? undefined : name.substring(0, dotPosition); + return dotPosition === -1 ? undefined : name.substring(0, dotPosition); } public isGlobalSymbol(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); + const parentName = this.getParentSymbolName(symbol); return !parentName || parentName === 'global'; } - public isStdObjectAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'Object'); - } - - public isStdReflectAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'Reflect'); - } - - public isStdProxyHandlerAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'ProxyHandler'); - } - - public isStdArrayAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'Array'); - } - - public isStdArrayBufferAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'ArrayBuffer'); + public isSymbolAPI(symbol: ts.Symbol): boolean { + const parentName = this.getParentSymbolName(symbol); + return ( + !!parentName && + (parentName === 'Symbol' || parentName === 'SymbolConstructor') + ); } public isStdSymbol(symbol: ts.Symbol): boolean { - const name = this.tsTypeChecker.getFullyQualifiedName(symbol) - return name === 'Symbol'; + const name = this.tsTypeChecker.getFullyQualifiedName(symbol); + return name === 'Symbol' && this.isGlobalSymbol(symbol); } - public isStdSymbolAPI(symbol: ts.Symbol): boolean { - let parentName = this.getParentSymbolName(symbol); - return !!parentName && (parentName === 'Symbol'); + public isSymbolIterator(symbol: ts.Symbol): boolean { + return this.isSymbolAPI(symbol) && symbol.name === 'iterator'; } public isDefaultImport(importSpec: ts.ImportSpecifier): boolean { @@ -940,13 +1189,15 @@ export class TsUtils { } public getStartPos(nodeOrComment: ts.Node | ts.CommentRange): number { - return (nodeOrComment.kind === ts.SyntaxKind.SingleLineCommentTrivia || nodeOrComment.kind === ts.SyntaxKind.MultiLineCommentTrivia) + return nodeOrComment.kind === ts.SyntaxKind.SingleLineCommentTrivia || + nodeOrComment.kind === ts.SyntaxKind.MultiLineCommentTrivia ? (nodeOrComment as ts.CommentRange).pos : (nodeOrComment as ts.Node).getStart(); } public getEndPos(nodeOrComment: ts.Node | ts.CommentRange): number { - return (nodeOrComment.kind === ts.SyntaxKind.SingleLineCommentTrivia || nodeOrComment.kind === ts.SyntaxKind.MultiLineCommentTrivia) + return nodeOrComment.kind === ts.SyntaxKind.SingleLineCommentTrivia || + nodeOrComment.kind === ts.SyntaxKind.MultiLineCommentTrivia ? (nodeOrComment as ts.CommentRange).end : (nodeOrComment as ts.Node).getEnd(); } @@ -966,6 +1217,15 @@ export class TsUtils { return false; } + public isStdErrorType(type: ts.Type): boolean { + const symbol = type.symbol; + if (!symbol) { + return false; + } + const name = this.tsTypeChecker.getFullyQualifiedName(symbol); + return name === 'Error' && this.isGlobalSymbol(symbol); + } + public isStdPartialType(type: ts.Type): boolean { const sym = type.aliasSymbol; return !!sym && sym.getName() === 'Partial' && this.isGlobalSymbol(sym); @@ -975,7 +1235,7 @@ export class TsUtils { const sym = type.aliasSymbol; return !!sym && sym.getName() === 'Required' && this.isGlobalSymbol(sym); } - + public isStdReadonlyType(type: ts.Type): boolean { const sym = type.aliasSymbol; return !!sym && sym.getName() === 'Readonly' && this.isGlobalSymbol(sym); @@ -991,7 +1251,9 @@ export class TsUtils { } return true; } - return this.isLibrarySymbol(nonNullableType.aliasSymbol ?? nonNullableType.getSymbol()); + return this.isLibrarySymbol( + nonNullableType.aliasSymbol ?? nonNullableType.getSymbol() + ); } public hasLibraryType(node: ts.Node): boolean { @@ -1004,31 +1266,30 @@ export class TsUtils { if (!srcFile) { return false; } - const fileName = srcFile.fileName + const fileName = srcFile.fileName; // Symbols from both *.ts and *.d.ts files should obey interop rules. // We disable such behavior for *.ts files in the test mode due to lack of 'ets' // extension support. const ext = path.extname(fileName).toLowerCase(); const isThirdPartyCode = - ARKTS_IGNORE_DIRS.some(ignore => pathContainsDirectory(path.normalize(fileName), ignore)) || + ARKTS_IGNORE_DIRS.some(ignore => + pathContainsDirectory(path.normalize(fileName), ignore) + ) || ARKTS_IGNORE_FILES.some(ignore => path.basename(fileName) === ignore); - const isEts = (ext === '.ets'); - const isTs = (ext === '.ts' && !srcFile.isDeclarationFile); + const isEts = ext === '.ets'; + const isTs = ext === '.ts' && !srcFile.isDeclarationFile; const isStatic = (isEts || (isTs && this.testMode)) && !isThirdPartyCode; + const isStdLib = STANDARD_LIBRARIES.includes( + path.basename(fileName).toLowerCase() + ); // We still need to confirm support for certain API from the // TypeScript standard library in ArkTS. Thus, for now do not - // count standard library modules. - return !isStatic && - !STANDARD_LIBRARIES.includes(path.basename(fileName).toLowerCase()); + // count standard library modules as dynamic. + return !isStatic && !isStdLib; } return false; } - public isStdFunctionType(type: ts.Type) { - const sym = type.getSymbol(); - return sym && sym.getName() === 'Function' && this.isGlobalSymbol(sym); - } - public isDynamicType(type: ts.Type | undefined): boolean | undefined { if (type === undefined) { return false; @@ -1043,8 +1304,8 @@ export class TsUtils { type = type.getNonNullableType(); if (type.isUnion()) { - for (let compType of type.types) { - let isDynamic = this.isDynamicType(compType); + for (const compType of type.types) { + const isDynamic = this.isDynamicType(compType); if (isDynamic || isDynamic === undefined) { return isDynamic; } @@ -1056,7 +1317,11 @@ export class TsUtils { return true; } - if (!isStdLibraryType(type) && !isIntrinsicObjectType(type) && !this.isAnyType(type)) { + if ( + !isStdLibraryType(type) && + !isIntrinsicObjectType(type) && + !this.isAnyType(type) + ) { return false; } @@ -1064,7 +1329,7 @@ export class TsUtils { } public isObjectType(type: ts.Type): type is ts.ObjectType { - return !!(type.flags & ts.TypeFlags.Object) + return !!(type.flags & ts.TypeFlags.Object); } private isAnonymous(type: ts.Type): boolean { @@ -1075,17 +1340,23 @@ export class TsUtils { } public isDynamicLiteralInitializer(expr: ts.Expression): boolean { - if (!ts.isObjectLiteralExpression(expr) && !ts.isArrayLiteralExpression(expr)) { + if ( + !ts.isObjectLiteralExpression(expr) && + !ts.isArrayLiteralExpression(expr) + ) { return false; } // Handle nested literals: // { f: { ... } } let curNode: ts.Node = expr; - while (ts.isObjectLiteralExpression(curNode) || ts.isArrayLiteralExpression(curNode)) { + while ( + ts.isObjectLiteralExpression(curNode) || + ts.isArrayLiteralExpression(curNode) + ) { const exprType = this.tsTypeChecker.getContextualType(curNode); if (exprType !== undefined && !this.isAnonymous(exprType)) { - const res = this.isDynamicType(exprType) + const res = this.isDynamicType(exprType); if (res !== undefined) { return res; } @@ -1101,14 +1372,14 @@ export class TsUtils { // foo({ ... }) if (ts.isCallExpression(curNode)) { const callExpr = curNode as ts.CallExpression; - const type = this.tsTypeChecker.getTypeAtLocation(callExpr.expression) + const type = this.tsTypeChecker.getTypeAtLocation(callExpr.expression); if (this.isAnyType(type)) { return true; } let sym: ts.Symbol | undefined = type.symbol; - if(this.isLibrarySymbol(sym)) { + if (this.isLibrarySymbol(sym)) { return true; } @@ -1128,7 +1399,9 @@ export class TsUtils { const binExpr = curNode as ts.BinaryExpression; if (ts.isPropertyAccessExpression(binExpr.left)) { const propAccessExpr = binExpr.left as ts.PropertyAccessExpression; - const type = this.tsTypeChecker.getTypeAtLocation(propAccessExpr.expression); + const type = this.tsTypeChecker.getTypeAtLocation( + propAccessExpr.expression + ); return this.isLibrarySymbol(type.symbol); } } @@ -1136,13 +1409,17 @@ export class TsUtils { return false; } - public isEsObjectType(typeNode: ts.TypeNode): boolean { - return ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName) && - typeNode.typeName.text == ES_OBJECT; + public isEsObjectType(typeNode: ts.TypeNode | undefined): boolean { + return ( + !!typeNode && + ts.isTypeReferenceNode(typeNode) && + ts.isIdentifier(typeNode.typeName) && + typeNode.typeName.text == ES_OBJECT + ); } public isInsideBlock(node: ts.Node): boolean { - let par = node.parent + let par = node.parent; while (par) { if (ts.isBlock(par)) { return true; @@ -1157,15 +1434,20 @@ export class TsUtils { } public isValueAssignableToESObject(node: ts.Node): boolean { - if (ts.isArrayLiteralExpression(node) || ts.isObjectLiteralExpression(node)) { + if ( + ts.isArrayLiteralExpression(node) || + ts.isObjectLiteralExpression(node) + ) { return false; } const valueType = this.tsTypeChecker.getTypeAtLocation(node); - return this.isUnsupportedType(valueType) || this.isAnonymousType(valueType) + return this.isUnsupportedType(valueType) || this.isAnonymousType(valueType); } - public getVariableDeclarationTypeNode(node: ts.Node): ts.TypeNode | undefined { - let sym = this.trueSymbolAtLocation(node); + public getVariableDeclarationTypeNode( + node: ts.Node + ): ts.TypeNode | undefined { + const sym = this.trueSymbolAtLocation(node); if (sym === undefined) { return undefined; } @@ -1181,7 +1463,7 @@ export class TsUtils { } public hasEsObjectType(node: ts.Node): boolean { - const typeNode = this.getVariableDeclarationTypeNode(node) + const typeNode = this.getVariableDeclarationTypeNode(node); return typeNode !== undefined && this.isEsObjectType(typeNode); } @@ -1191,14 +1473,18 @@ export class TsUtils { } public isEsObjectSymbol(sym: ts.Symbol): boolean { - let decl = this.getDeclaration(sym); - return !!decl && ts.isTypeAliasDeclaration(decl) && decl.name.escapedText == ES_OBJECT && - decl.type.kind === ts.SyntaxKind.AnyKeyword; + const decl = this.getDeclaration(sym); + return ( + !!decl && + ts.isTypeAliasDeclaration(decl) && + decl.name.escapedText == ES_OBJECT && + decl.type.kind === ts.SyntaxKind.AnyKeyword + ); } public isAnonymousType(type: ts.Type): boolean { if (type.isUnionOrIntersection()) { - for (let compType of type.types) { + for (const compType of type.types) { if (this.isAnonymousType(compType)) { return true; } @@ -1206,11 +1492,15 @@ export class TsUtils { return false; } - return (type.flags & ts.TypeFlags.Object) !== 0 && - ((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Anonymous) !== 0; + return ( + (type.flags & ts.TypeFlags.Object) !== 0 && + ((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Anonymous) !== 0 + ); } - public getSymbolOfCallExpression(callExpr: ts.CallExpression): ts.Symbol | undefined { + public getSymbolOfCallExpression( + callExpr: ts.CallExpression + ): ts.Symbol | undefined { const signature = this.tsTypeChecker.getResolvedSignature(callExpr); const signDecl = signature?.getDeclaration(); if (signDecl && signDecl.name) { @@ -1220,7 +1510,10 @@ export class TsUtils { } // has to be re-implemented with local loop detection - public typeIsRecursive(topType: ts.Type, type: ts.Type | undefined = undefined): boolean { + public typeIsRecursive( + topType: ts.Type, + type: ts.Type | undefined = undefined + ): boolean { if (type == undefined) { type = topType; } else if (type == topType) { @@ -1230,14 +1523,19 @@ export class TsUtils { } if (type.isUnion()) { - for (let unionElem of type.types) { + for (const unionElem of type.types) { if (this.typeIsRecursive(topType, unionElem)) { return true; } } } - if (type.flags & ts.TypeFlags.Object && (type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference) { - const typeArgs = this.tsTypeChecker.getTypeArguments(type as ts.TypeReference); + if ( + type.flags & ts.TypeFlags.Object && + (type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference + ) { + const typeArgs = this.tsTypeChecker.getTypeArguments( + type as ts.TypeReference + ); if (typeArgs) { for (const typeArg of typeArgs) { if (this.typeIsRecursive(topType, typeArg)) { @@ -1250,7 +1548,10 @@ export class TsUtils { } public isClassValueType(type: ts.Type): boolean { - if ((type.flags & ts.TypeFlags.Object) === 0 || ((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Anonymous) === 0) { + if ( + (type.flags & ts.TypeFlags.Object) === 0 || + ((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Anonymous) === 0 + ) { return false; } return type.symbol && (type.symbol.flags & ts.SymbolFlags.Class) !== 0; @@ -1260,12 +1561,12 @@ export class TsUtils { if (!this.isClassValueType(this.tsTypeChecker.getTypeAtLocation(expr))) { return false; } - let symbol = this.trueSymbolAtLocation(expr); + const symbol = this.trueSymbolAtLocation(expr); return !symbol || (symbol.flags & ts.SymbolFlags.Class) === 0; } public isClassTypeExrepssion(expr: ts.Expression): boolean { - let sym = this.trueSymbolAtLocation(expr); + const sym = this.trueSymbolAtLocation(expr); return sym !== undefined && (sym.flags & ts.SymbolFlags.Class) !== 0; } @@ -1284,7 +1585,9 @@ export class TsUtils { } if (ts.isCallExpression(tsNode) && ts.isIdentifier(tsNode.expression)) { - const callSym = self.tsTypeChecker.getSymbolAtLocation(tsNode.expression); + const callSym = self.tsTypeChecker.getSymbolAtLocation( + tsNode.expression + ); if (callSym && callSym === sym) { found = true; return; @@ -1298,4 +1601,15 @@ export class TsUtils { visitNode(funcExpr); return found; } + + public getTypeOrTypeConstraintAtLocation(expr: ts.Expression): ts.Type { + const type = this.tsTypeChecker.getTypeAtLocation(expr); + if (type.isTypeParameter()) { + const constraint = type.getConstraint(); + if (constraint) { + return constraint; + } + } + return type; + } } diff --git a/linter/src/utils/consts/AllowedStdSymbolAPI.ts b/linter/src/utils/consts/AllowedStdSymbolAPI.ts new file mode 100644 index 0000000000000000000000000000000000000000..6af85d868e1c95704f5a647a26b12cb474db9791 --- /dev/null +++ b/linter/src/utils/consts/AllowedStdSymbolAPI.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const ALLOWED_STD_SYMBOL_API = ['iterator']; diff --git a/linter/src/utils/consts/ArktsIgnorePaths.ts b/linter/src/utils/consts/ArktsIgnorePaths.ts index ca29111acbd80c0ddef33c69535c82997937a355..f1d0bd831e17f696ce50c8693c2ce5164bb5a264 100644 --- a/linter/src/utils/consts/ArktsIgnorePaths.ts +++ b/linter/src/utils/consts/ArktsIgnorePaths.ts @@ -13,5 +13,10 @@ * limitations under the License. */ -export const ARKTS_IGNORE_DIRS = ['node_modules', 'oh_modules', 'build', '.preview']; +export const ARKTS_IGNORE_DIRS = [ + 'node_modules', + 'oh_modules', + 'build', + '.preview', +]; export const ARKTS_IGNORE_FILES = ['hvigorfile.ts']; diff --git a/linter/src/utils/consts/ESObject.ts b/linter/src/utils/consts/ESObject.ts index e1c9a2b10a9a2bafb8b7a716699099f3e38ac319..2837d1ceacb950c2dbd3669cfff7e1f90e8a0461 100644 --- a/linter/src/utils/consts/ESObject.ts +++ b/linter/src/utils/consts/ESObject.ts @@ -13,4 +13,4 @@ * limitations under the License. */ -export const ES_OBJECT = 'ESObject' +export const ES_OBJECT = 'ESObject'; diff --git a/linter/src/utils/consts/LimitedStdGlobalFunc.ts b/linter/src/utils/consts/LimitedStdGlobalFunc.ts new file mode 100644 index 0000000000000000000000000000000000000000..7000b1681d28757f02a09462adcca9f9ce9bdff3 --- /dev/null +++ b/linter/src/utils/consts/LimitedStdGlobalFunc.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const LIMITED_STD_GLOBAL_FUNC = ['eval']; diff --git a/linter/src/utils/consts/LimitedStdApi.ts b/linter/src/utils/consts/LimitedStdObjectAPI.ts similarity index 31% rename from linter/src/utils/consts/LimitedStdApi.ts rename to linter/src/utils/consts/LimitedStdObjectAPI.ts index 1599fbfe9210a7b902bfffac2596ea6a87fe3a28..6c4cccbf2a48888cbdfe066b2901277c7c764533 100644 --- a/linter/src/utils/consts/LimitedStdApi.ts +++ b/linter/src/utils/consts/LimitedStdObjectAPI.ts @@ -13,24 +13,8 @@ * limitations under the License. */ -import { FaultID } from "./Problems"; - -/** - * ArrayBuffer - */ -const LIMITED_STD_ARRAYBUFFER_API = [ - // properties - // methods - 'isView' -]; - -/** - * Object - */ -const LIMITED_STD_OBJECT_API = [ - // properties +export const LIMITED_STD_OBJECT_API = [ '__proto__', - // methods '__defineGetter__', '__defineSetter__', '__lookupGetter__', @@ -56,100 +40,3 @@ const LIMITED_STD_OBJECT_API = [ 'seal', 'setPrototypeOf', ]; - -/** - * Proxy - */ -const LIMITED_STD_PROXYHANDLER_API = [ - // properties - // methods - 'apply', - 'construct', - 'defineProperty', - 'deleteProperty', - 'get', - 'getOwnPropertyDescriptor', - 'getPrototypeOf', - 'has', - 'isExtensible', - 'ownKeys', - 'preventExtensions', - 'set', - 'setPrototypeOf' -]; - -/** - * Reflect - */ -const LIMITED_STD_REFLECT_API = [ - // properties - // methods - 'apply', - 'construct', - 'defineProperty', - 'deleteProperty', - 'getOwnPropertyDescriptor', - 'getPrototypeOf', - 'isExtensible', - 'preventExtensions', - 'setPrototypeOf', -]; - -/** - * Symbol - */ -const LIMITED_STD_SYMBOL_API = [ - 'Symbol', - // properties - 'asyncIterator', - 'description', - 'hasInstance', - 'isConcatSpreadable', - 'match', - 'matchAll', - 'replace', - 'search', - 'species', - 'split', - 'toPrimitive', - 'toStringTag', - 'unscopables', - // methods - 'for', - 'keyFor', - 'toString', - 'valueOf', -]; - -/** - * Function - */ -const LIMITED_STD_FUNCTION_API = [ - // properties - // methods - 'apply', - 'bind', - 'call', -]; - -/** - * Global - */ -export const LIMITED_STD_GLOBAL_API = [ - // properties - // methods - 'eval', -]; - -export const LIMITED_STD_API = new Map, fault: FaultID}> ([ - ['Object', {arr: LIMITED_STD_OBJECT_API, fault: FaultID.LimitedStdLibApi}], - ['ObjectConstructor', {arr: LIMITED_STD_OBJECT_API, fault: FaultID.LimitedStdLibApi}], - ['Reflect', {arr: LIMITED_STD_REFLECT_API, fault: FaultID.LimitedStdLibApi}], - ['ProxyHandler', {arr: LIMITED_STD_PROXYHANDLER_API, fault: FaultID.LimitedStdLibApi}], - ['ArrayBuffer', {arr: LIMITED_STD_ARRAYBUFFER_API, fault: FaultID.LimitedStdLibApi}], - ['ArrayBufferConstructor', {arr: LIMITED_STD_ARRAYBUFFER_API, fault: FaultID.LimitedStdLibApi}], - ['Symbol', {arr: LIMITED_STD_SYMBOL_API, fault: FaultID.SymbolType}], - ['SymbolConstructor', {arr: LIMITED_STD_SYMBOL_API, fault: FaultID.SymbolType}], - ['Function', {arr: LIMITED_STD_FUNCTION_API, fault: FaultID.FunctionApplyBindCall}], - ['CallableFunction', {arr: LIMITED_STD_FUNCTION_API, fault: FaultID.FunctionApplyBindCall}], -]) diff --git a/linter/src/utils/consts/LimitedStdProxyHandlerAPI.ts b/linter/src/utils/consts/LimitedStdProxyHandlerAPI.ts new file mode 100644 index 0000000000000000000000000000000000000000..c13069d3496c96e23d9adc1cf09d919102676319 --- /dev/null +++ b/linter/src/utils/consts/LimitedStdProxyHandlerAPI.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const LIMITED_STD_PROXYHANDLER_API = [ + 'apply', + 'construct', + 'defineProperty', + 'deleteProperty', + 'get', + 'getOwnPropertyDescriptor', + 'getPrototypeOf', + 'has', + 'isExtensible', + 'ownKeys', + 'preventExtensions', + 'set', + 'setPrototypeOf', +]; diff --git a/linter/src/utils/consts/LimitedStdReflectAPI.ts b/linter/src/utils/consts/LimitedStdReflectAPI.ts new file mode 100644 index 0000000000000000000000000000000000000000..7432df0fea3e82592316a19edc840237828a9e48 --- /dev/null +++ b/linter/src/utils/consts/LimitedStdReflectAPI.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const LIMITED_STD_REFLECT_API = [ + 'apply', + 'construct', + 'defineProperty', + 'deleteProperty', + 'getOwnPropertyDescriptor', + 'getPrototypeOf', + 'isExtensible', + 'preventExtensions', + 'setPrototypeOf', +]; diff --git a/linter/src/utils/consts/NonInitializablePropertyDecorators.ts b/linter/src/utils/consts/NonInitializablePropertyDecorators.ts index 251272c1496fc7591d9033d2a9f84c9e7bb49f2a..a0961f01c7379423897a37f331aa2dbdd957b9ad 100644 --- a/linter/src/utils/consts/NonInitializablePropertyDecorators.ts +++ b/linter/src/utils/consts/NonInitializablePropertyDecorators.ts @@ -13,6 +13,12 @@ * limitations under the License. */ -export const NON_INITIALIZABLE_PROPERTY_DECORATORS = ['Link', 'Consume', 'ObjectLink', 'Prop', 'BuilderParam']; +export const NON_INITIALIZABLE_PROPERTY_DECORATORS = [ + 'Link', + 'Consume', + 'ObjectLink', + 'Prop', + 'BuilderParam', +]; -export const NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS = ['CustomDialog'] +export const NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS = ['CustomDialog']; diff --git a/linter/src/utils/consts/NonReturnFunctionDecorators.ts b/linter/src/utils/consts/NonReturnFunctionDecorators.ts index 70cca0ea430c69d298c753e67399b7c973612162..16d4cf10da3d25d1dabb18ca56653684ef94b967 100644 --- a/linter/src/utils/consts/NonReturnFunctionDecorators.ts +++ b/linter/src/utils/consts/NonReturnFunctionDecorators.ts @@ -13,4 +13,9 @@ * limitations under the License. */ -export const NON_RETURN_FUNCTION_DECORATORS = ['AnimatableExtend', 'Builder', 'Extend', 'Styles']; +export const NON_RETURN_FUNCTION_DECORATORS = [ + 'AnimatableExtend', + 'Builder', + 'Extend', + 'Styles', +]; diff --git a/linter/src/utils/consts/StandardLibraries.ts b/linter/src/utils/consts/StandardLibraries.ts index 229ffefbfdf9772d68134e7f5912780d048c19bb..e30ae9a2ad51131eaf1e877a06c73ef68db6854c 100644 --- a/linter/src/utils/consts/StandardLibraries.ts +++ b/linter/src/utils/consts/StandardLibraries.ts @@ -14,18 +14,58 @@ */ export const STANDARD_LIBRARIES = [ - 'lib.dom.d.ts', 'lib.dom.iterable.d.ts', 'lib.webworker.d.ts', 'lib.webworker.importscripts.d.ts', - 'lib.webworker.iterable.d.ts', 'lib.scripthost.d.ts', 'lib.decorators.d.ts', 'lib.decorators.legacy.d.ts', - 'lib.es5.d.ts', 'lib.es2015.core.d.ts', 'lib.es2015.collection.d.ts', 'lib.es2015.generator.d.ts', - 'lib.es2015.iterable.d.ts', 'lib.es2015.promise.d.ts', 'lib.es2015.proxy.d.ts', 'lib.es2015.reflect.d.ts', - 'lib.es2015.symbol.d.ts', 'lib.es2015.symbol.wellknown.d.ts', 'lib.es2016.array.include.d.ts', - 'lib.es2017.object.d.ts', 'lib.es2017.sharedmemory.d.ts', 'lib.es2017.string.d.ts', 'lib.es2017.intl.d.ts', - 'lib.es2017.typedarrays.d.ts', 'lib.es2018.asyncgenerator.d.ts', 'lib.es2018.asynciterable.d.ts', - 'lib.es2018.intl.d.ts', 'lib.es2018.promise.d.ts', 'lib.es2018.regexp.d.ts', 'lib.es2019.array.d.ts', - 'lib.es2019.object.d.ts', 'lib.es2019.string.d.ts', 'lib.es2019.symbol.d.ts', 'lib.es2019.intl.d.ts', - 'lib.es2020.bigint.d.ts', 'lib.es2020.date.d.ts', 'lib.es2020.promise.d.ts', 'lib.es2020.sharedmemory.d.ts', - 'lib.es2020.string.d.ts', 'lib.es2020.symbol.wellknown.d.ts', 'lib.es2020.intl.d.ts', 'lib.es2020.number.d.ts', - 'lib.es2021.promise.d.ts', 'lib.es2021.string.d.ts', 'lib.es2021.weakref.d.ts', 'lib.es2021.intl.d.ts', - 'lib.es2022.array.d.ts', 'lib.es2022.error.d.ts', 'lib.es2022.intl.d.ts', 'lib.es2022.object.d.ts', - 'lib.es2022.sharedmemory.d.ts', 'lib.es2022.string.d.ts', 'lib.es2022.regexp.d.ts', 'lib.es2023.array.d.ts', + 'lib.dom.d.ts', + 'lib.dom.iterable.d.ts', + 'lib.webworker.d.ts', + 'lib.webworker.importscripts.d.ts', + 'lib.webworker.iterable.d.ts', + 'lib.scripthost.d.ts', + 'lib.decorators.d.ts', + 'lib.decorators.legacy.d.ts', + 'lib.es5.d.ts', + 'lib.es2015.core.d.ts', + 'lib.es2015.collection.d.ts', + 'lib.es2015.generator.d.ts', + 'lib.es2015.iterable.d.ts', + 'lib.es2015.promise.d.ts', + 'lib.es2015.proxy.d.ts', + 'lib.es2015.reflect.d.ts', + 'lib.es2015.symbol.d.ts', + 'lib.es2015.symbol.wellknown.d.ts', + 'lib.es2016.array.include.d.ts', + 'lib.es2017.object.d.ts', + 'lib.es2017.sharedmemory.d.ts', + 'lib.es2017.string.d.ts', + 'lib.es2017.intl.d.ts', + 'lib.es2017.typedarrays.d.ts', + 'lib.es2018.asyncgenerator.d.ts', + 'lib.es2018.asynciterable.d.ts', + 'lib.es2018.intl.d.ts', + 'lib.es2018.promise.d.ts', + 'lib.es2018.regexp.d.ts', + 'lib.es2019.array.d.ts', + 'lib.es2019.object.d.ts', + 'lib.es2019.string.d.ts', + 'lib.es2019.symbol.d.ts', + 'lib.es2019.intl.d.ts', + 'lib.es2020.bigint.d.ts', + 'lib.es2020.date.d.ts', + 'lib.es2020.promise.d.ts', + 'lib.es2020.sharedmemory.d.ts', + 'lib.es2020.string.d.ts', + 'lib.es2020.symbol.wellknown.d.ts', + 'lib.es2020.intl.d.ts', + 'lib.es2020.number.d.ts', + 'lib.es2021.promise.d.ts', + 'lib.es2021.string.d.ts', + 'lib.es2021.weakref.d.ts', + 'lib.es2021.intl.d.ts', + 'lib.es2022.array.d.ts', + 'lib.es2022.error.d.ts', + 'lib.es2022.intl.d.ts', + 'lib.es2022.object.d.ts', + 'lib.es2022.sharedmemory.d.ts', + 'lib.es2022.string.d.ts', + 'lib.es2022.regexp.d.ts', + 'lib.es2023.array.d.ts', ]; diff --git a/linter/src/utils/consts/TypedArrays.ts b/linter/src/utils/consts/TypedArrays.ts index 9ef717311061b0620cf751533d6f0ac457a9ca88..47e7336720627e299d3ab2d2b9b726f4fe1c3f62 100644 --- a/linter/src/utils/consts/TypedArrays.ts +++ b/linter/src/utils/consts/TypedArrays.ts @@ -25,4 +25,4 @@ export const TYPED_ARRAYS = [ 'Float64Array', 'BigInt64Array', 'BigUint64Array', -] +]; diff --git a/linter/src/utils/functions/ContainsThis.ts b/linter/src/utils/functions/ContainsThis.ts index 958553f2808093b08b518cb2a1a7ec8a9928819c..a14034305efdb8669b4304e699feb9b42a1b0e60 100644 --- a/linter/src/utils/functions/ContainsThis.ts +++ b/linter/src/utils/functions/ContainsThis.ts @@ -40,4 +40,3 @@ export function scopeContainsThis(tsNode: ts.Node): boolean { visitNode(tsNode); return found; } - \ No newline at end of file diff --git a/linter/src/utils/functions/DiagnosticChecker.ts b/linter/src/utils/functions/DiagnosticChecker.ts index 841d0d5b4f390ea6cdd07da38bd2e58e9e00fa57..820d24a3e142a2f7328ce3581e9f66a0b0cb733e 100644 --- a/linter/src/utils/functions/DiagnosticChecker.ts +++ b/linter/src/utils/functions/DiagnosticChecker.ts @@ -17,4 +17,4 @@ import * as ts from 'typescript'; export interface DiagnosticChecker { checkDiagnosticMessage(msgText: string | ts.DiagnosticMessageChain): boolean; -} \ No newline at end of file +} diff --git a/linter/src/utils/functions/GetScriptKind.ts b/linter/src/utils/functions/GetScriptKind.ts index e1bedc1b38141603517ddf3b4dee0200b73458f0..98643872d1a7e4a7e3cd87e03034ac073bd21fbc 100644 --- a/linter/src/utils/functions/GetScriptKind.ts +++ b/linter/src/utils/functions/GetScriptKind.ts @@ -17,8 +17,8 @@ import * as ts from 'typescript'; import * as path from 'node:path'; export function getScriptKind(srcFile: ts.SourceFile): ts.ScriptKind { - const fileName = srcFile.fileName - const ext = path.extname(fileName).toLowerCase() + const fileName = srcFile.fileName; + const ext = path.extname(fileName).toLowerCase(); switch (ext) { case ts.Extension.Ts: return ts.ScriptKind.TS; @@ -33,4 +33,4 @@ export function getScriptKind(srcFile: ts.SourceFile): ts.ScriptKind { default: return ts.ScriptKind.Unknown; } -} \ No newline at end of file +} diff --git a/linter/src/utils/functions/HasPredecessor.ts b/linter/src/utils/functions/HasPredecessor.ts index 8c389cfa18e8015093195c5495ef653a039e3499..264bf67b1668a7f8c4d74b5f9c7c2140cdee6225 100644 --- a/linter/src/utils/functions/HasPredecessor.ts +++ b/linter/src/utils/functions/HasPredecessor.ts @@ -15,7 +15,10 @@ import * as ts from 'typescript'; -export function hasPredecessor(node: ts.Node, predicate: (node: ts.Node) => boolean): boolean { +export function hasPredecessor( + node: ts.Node, + predicate: (node: ts.Node) => boolean +): boolean { let parent = node.parent; while (parent !== undefined) { if (predicate(parent)) { diff --git a/linter/src/utils/functions/IsStdLibrary.ts b/linter/src/utils/functions/IsStdLibrary.ts index 95c15e4a47cfe719ddb299cac20d84607ea21ce3..fe80cd1712e93fe545d06cba3c6795b97b6f5458 100644 --- a/linter/src/utils/functions/IsStdLibrary.ts +++ b/linter/src/utils/functions/IsStdLibrary.ts @@ -15,7 +15,7 @@ import * as ts from 'typescript'; import * as path from 'node:path'; -import { STANDARD_LIBRARIES } from '../consts/StandardLibraries'; +import {STANDARD_LIBRARIES} from '../consts/StandardLibraries'; export function isStdLibraryType(type: ts.Type): boolean { return isStdLibrarySymbol(type.aliasSymbol ?? type.getSymbol()); @@ -24,7 +24,10 @@ export function isStdLibraryType(type: ts.Type): boolean { export function isStdLibrarySymbol(sym: ts.Symbol | undefined) { if (sym && sym.declarations && sym.declarations.length > 0) { const srcFile = sym.declarations[0].getSourceFile(); - return srcFile && STANDARD_LIBRARIES.includes(path.basename(srcFile.fileName).toLowerCase()); + return ( + srcFile && + STANDARD_LIBRARIES.includes(path.basename(srcFile.fileName).toLowerCase()) + ); } return false; -} \ No newline at end of file +} diff --git a/linter/src/utils/functions/IsStruct.ts b/linter/src/utils/functions/IsStruct.ts index 4ba05fe20d8b1c01751cdc093d8dcd11b9675ccb..3a2205d47521434dbdee3923aff6fbb5cda85590 100644 --- a/linter/src/utils/functions/IsStruct.ts +++ b/linter/src/utils/functions/IsStruct.ts @@ -14,7 +14,7 @@ */ import * as ts from 'typescript'; -import { LinterConfig } from '../../TypeScriptLinterConfig'; +import {LinterConfig} from '../../TypeScriptLinterConfig'; export function isStruct(symbol: ts.Symbol) { if (!symbol.declarations) { diff --git a/linter/src/utils/functions/LibraryTypeCallDiagnosticChecker.ts b/linter/src/utils/functions/LibraryTypeCallDiagnosticChecker.ts index 72778922bfed4c2efc5e60cb04287f342e8344f2..07fe9c7ee2e07e51d598a75e8500fb453c3dbaef 100644 --- a/linter/src/utils/functions/LibraryTypeCallDiagnosticChecker.ts +++ b/linter/src/utils/functions/LibraryTypeCallDiagnosticChecker.ts @@ -14,37 +14,50 @@ */ import * as ts from 'typescript'; -import { DiagnosticChecker } from './DiagnosticChecker'; +import {DiagnosticChecker} from './DiagnosticChecker'; // Current approach relates on error code and error message matching and it is quite fragile, // so this place should be checked thoroughly in the case of typescript upgrade export const TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE = 2322; -export const TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE = /^Type '(.*)\bunknown\b(.*)' is not assignable to type '.*'\.$/; -export const TYPE_NULL_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE = /^Type 'null' is not assignable to type '.*'\.$/; -export const TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE = /^Type 'undefined' is not assignable to type '.*'\.$/; +export const TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE = + /^Type '(.*)\bunknown\b(.*)' is not assignable to type '.*'\.$/; +export const TYPE_NULL_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE = + /^Type 'null' is not assignable to type '.*'\.$/; +export const TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE = + /^Type 'undefined' is not assignable to type '.*'\.$/; export const ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE = 2345; -export const ARGUMENT_OF_TYPE_NULL_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE = /^Argument of type 'null' is not assignable to parameter of type '.*'\.$/; -export const ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE = /^Argument of type 'undefined' is not assignable to parameter of type '.*'\.$/; +export const ARGUMENT_OF_TYPE_NULL_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE = + /^Argument of type 'null' is not assignable to parameter of type '.*'\.$/; +export const ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE = + /^Argument of type 'undefined' is not assignable to parameter of type '.*'\.$/; export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker { - inLibCall: boolean = false; + inLibCall = false; diagnosticMessages: Array | undefined; filteredDiagnosticMessages: Set; constructor(filteredDiagnosticMessages: Set) { this.filteredDiagnosticMessages = filteredDiagnosticMessages; } - - configure(inLibCall: boolean, diagnosticMessages: Array) { + + configure( + inLibCall: boolean, + diagnosticMessages: Array + ) { this.inLibCall = inLibCall; this.diagnosticMessages = diagnosticMessages; } checkMessageText(msg: string): boolean { if (this.inLibCall) { - const match = msg.match(ARGUMENT_OF_TYPE_NULL_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE) || - msg.match(ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE) || + const match = + msg.match( + ARGUMENT_OF_TYPE_NULL_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE + ) || + msg.match( + ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE + ) || msg.match(TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE) || msg.match(TYPE_NULL_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE); return !match; @@ -54,30 +67,43 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker { checkMessageChain(chain: ts.DiagnosticMessageChain): boolean { if (chain.code == TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) { - if (chain.messageText.match(TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) { + if ( + chain.messageText.match(TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE) + ) { return false; } - if (this.inLibCall && chain.messageText.match(TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) { + if ( + this.inLibCall && + chain.messageText.match(TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE) + ) { return false; } - if (this.inLibCall && chain.messageText.match(TYPE_NULL_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) { + if ( + this.inLibCall && + chain.messageText.match(TYPE_NULL_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE) + ) { return false; } } - return chain.next == undefined ? true : this.checkMessageChain(chain.next[0]); - }; + return chain.next == undefined + ? true + : this.checkMessageChain(chain.next[0]); + } checkFilteredDiagnosticMessages(msgText: ts.DiagnosticMessageChain | string) { if (this.filteredDiagnosticMessages.size == 0) { return true; } - if (typeof msgText !== 'string' && this.filteredDiagnosticMessages.has(msgText)) { + if ( + typeof msgText !== 'string' && + this.filteredDiagnosticMessages.has(msgText) + ) { return false; } for (const msgChain of this.filteredDiagnosticMessages) { - if (typeof msgText == 'string') { + if (typeof msgText === 'string') { if (msgText == msgChain.messageText) { return false; } @@ -99,8 +125,10 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker { return true; } - curMsg = curMsg.next ? curMsg.next[0]: undefined; - curFilteredMsg = curFilteredMsg.next ? curFilteredMsg.next[0]: undefined; + curMsg = curMsg.next ? curMsg.next[0] : undefined; + curFilteredMsg = curFilteredMsg.next + ? curFilteredMsg.next[0] + : undefined; } return false; @@ -117,7 +145,7 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker { return false; } - if (typeof msgText == 'string') { + if (typeof msgText === 'string') { return this.checkMessageText(msgText); } @@ -127,4 +155,4 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker { } return true; } -} \ No newline at end of file +} diff --git a/linter/src/utils/functions/LinterInfo.ts b/linter/src/utils/functions/LinterInfo.ts index 9699dab3c78a0b0a2bd4f7b46c5421335e25130a..c2a1c3772e25d5be602a238a242989942f41b811 100644 --- a/linter/src/utils/functions/LinterInfo.ts +++ b/linter/src/utils/functions/LinterInfo.ts @@ -13,15 +13,15 @@ * limitations under the License. */ -import { ProblemInfo } from '../../ProblemInfo'; -import { AutofixInfo } from '../../autofixes/AutofixInfo'; +import {ProblemInfo} from '../../ProblemInfo'; +import {AutofixInfo} from '../../autofixes/AutofixInfo'; export function encodeProblemInfo(problem: ProblemInfo): string { return `${problem.problem}%${problem.start}%${problem.end}`; } export function decodeAutofixInfo(info: string): AutofixInfo { - let infos = info.split('%'); + const infos = info.split('%'); return { problemID: infos[0], start: Number.parseInt(infos[1]), diff --git a/linter/src/utils/functions/LogTscDiagnostic.ts b/linter/src/utils/functions/LogTscDiagnostic.ts index a5b217420a46af4d5ef77b3d1f0c648ddb0c58bf..f33a5df8ecc822bdc9ef5a8b4b8a6aa2c004b623 100644 --- a/linter/src/utils/functions/LogTscDiagnostic.ts +++ b/linter/src/utils/functions/LogTscDiagnostic.ts @@ -15,13 +15,21 @@ import * as ts from 'typescript'; -export function logTscDiagnostic(diagnostics: readonly ts.Diagnostic[], log: (message: any, ...args: any[]) => void) { - diagnostics.forEach((diagnostic) => { +export function logTscDiagnostic( + diagnostics: readonly ts.Diagnostic[], + log: (message: any, ...args: any[]) => void +) { + diagnostics.forEach(diagnostic => { let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); if (diagnostic.file && diagnostic.start) { - const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); - message = `${diagnostic.file.fileName} (${line + 1}, ${character + 1}): ${message}`; + const {line, character} = ts.getLineAndCharacterOfPosition( + diagnostic.file, + diagnostic.start + ); + message = `${diagnostic.file.fileName} (${line + 1}, ${ + character + 1 + }): ${message}`; } log(message); diff --git a/linter/src/utils/functions/PathHelper.ts b/linter/src/utils/functions/PathHelper.ts index d4e3f566aa20b82a2470eac7df01b162c9fec015..46b5ff253c16e022db8d7c428dce0750374a2240 100644 --- a/linter/src/utils/functions/PathHelper.ts +++ b/linter/src/utils/functions/PathHelper.ts @@ -22,4 +22,4 @@ export function pathContainsDirectory(path: string, dir: string): boolean { } } return false; -} \ No newline at end of file +} diff --git a/linter/src/utils/functions/identiferUseInValueContext.ts b/linter/src/utils/functions/identiferUseInValueContext.ts index 43c1389a96b66fc1843d3fc26fc7d0d8415258e1..22da79625428f4646b9ac1bba8c9bb58e8247c06 100644 --- a/linter/src/utils/functions/identiferUseInValueContext.ts +++ b/linter/src/utils/functions/identiferUseInValueContext.ts @@ -16,69 +16,98 @@ import * as ts from 'typescript'; function isInstanceofContext(tsIdentStart: ts.Node): boolean { - return ts.isBinaryExpression(tsIdentStart.parent) && + return ( + ts.isBinaryExpression(tsIdentStart.parent) && tsIdentStart.parent.operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword + ); } function isNewExpressionContext(tsIdentStart: ts.Node): boolean { - return ts.isNewExpression(tsIdentStart.parent) && tsIdentStart === tsIdentStart.parent.expression + return ( + ts.isNewExpression(tsIdentStart.parent) && + tsIdentStart === tsIdentStart.parent.expression + ); } -function isQualifiedNameContext(tsIdentStart: ts.Node, tsIdentifier: ts.Identifier): boolean { +function isQualifiedNameContext( + tsIdentStart: ts.Node, + tsIdentifier: ts.Identifier +): boolean { // rightmost in AST is rightmost in qualified name chain - return ts.isQualifiedName(tsIdentStart) && tsIdentifier !== tsIdentStart.right + return ( + ts.isQualifiedName(tsIdentStart) && tsIdentifier !== tsIdentStart.right + ); } -function isPropertyAccessContext(tsIdentStart: ts.Node, tsIdentifier: ts.Identifier): boolean { +function isPropertyAccessContext( + tsIdentStart: ts.Node, + tsIdentifier: ts.Identifier +): boolean { // rightmost in AST is rightmost in qualified name chain - return ts.isPropertyAccessExpression(tsIdentStart) && tsIdentifier !== tsIdentStart.name + return ( + ts.isPropertyAccessExpression(tsIdentStart) && + tsIdentifier !== tsIdentStart.name + ); } function getQualifiedStart(ident: ts.Node): ts.Node { let qualifiedStart: ts.Node = ident; - while (ts.isPropertyAccessExpression(qualifiedStart.parent) || ts.isQualifiedName(qualifiedStart.parent)) { + while ( + ts.isPropertyAccessExpression(qualifiedStart.parent) || + ts.isQualifiedName(qualifiedStart.parent) + ) { qualifiedStart = qualifiedStart.parent; } return qualifiedStart; } -function isEnumPropAccess(ident: ts.Identifier, tsSym: ts.Symbol, context: ts.Node): boolean { - return ts.isElementAccessExpression(context) && - (context as ts.ElementAccessExpression).expression == ident && - !!(tsSym.flags & ts.SymbolFlags.Enum); +function isEnumPropAccess( + ident: ts.Identifier, + tsSym: ts.Symbol, + context: ts.Node +): boolean { + return ( + ts.isElementAccessExpression(context) && + !!(tsSym.flags & ts.SymbolFlags.Enum) && + (context.expression == ident || + (ts.isPropertyAccessExpression(context.expression) && + context.expression.name == ident)) + ); } - function isValidTypeNode(node: ts.TypeNode): boolean { return !ts.isTypeOfExpression(node); } export function identiferUseInValueContext( - ident: ts.Identifier, tsSym: ts.Symbol + ident: ts.Identifier, + tsSym: ts.Symbol ) { - let qualifiedStart = getQualifiedStart(ident); - let parent = qualifiedStart.parent; + const qualifiedStart = getQualifiedStart(ident); + const parent = qualifiedStart.parent; return !( // treat TypeQuery as valid because it's already forbidden (FaultID.TypeQuery) - ts.isTypeNode(parent) && isValidTypeNode(parent) || - // If identifier is the right-most name of Property Access chain or Qualified name, - // or it's a separate identifier expression, then identifier is being referenced as an value. - isEnumPropAccess(ident, tsSym, parent) || - ts.isExpressionWithTypeArguments(parent) || - ts.isExportAssignment(parent) || - ts.isExportSpecifier(parent) || - ts.isMetaProperty(parent) || - ts.isImportClause(parent) || - ts.isClassLike(parent) || - ts.isInterfaceDeclaration(parent) || - ts.isModuleDeclaration(parent) || - ts.isEnumDeclaration(parent) || - ts.isNamespaceImport(parent) || - ts.isImportSpecifier(parent) || - isQualifiedNameContext(qualifiedStart, ident) || - isPropertyAccessContext(qualifiedStart, ident) || - isNewExpressionContext(qualifiedStart) || - isInstanceofContext(qualifiedStart) || - ts.isImportEqualsDeclaration(parent) + ( + (ts.isTypeNode(parent) && isValidTypeNode(parent)) || + // If identifier is the right-most name of Property Access chain or Qualified name, + // or it's a separate identifier expression, then identifier is being referenced as an value. + isEnumPropAccess(ident, tsSym, parent) || + ts.isExpressionWithTypeArguments(parent) || + ts.isExportAssignment(parent) || + ts.isExportSpecifier(parent) || + ts.isMetaProperty(parent) || + ts.isImportClause(parent) || + ts.isClassLike(parent) || + ts.isInterfaceDeclaration(parent) || + ts.isModuleDeclaration(parent) || + ts.isEnumDeclaration(parent) || + ts.isNamespaceImport(parent) || + ts.isImportSpecifier(parent) || + isQualifiedNameContext(qualifiedStart, ident) || + isPropertyAccessContext(qualifiedStart, ident) || + isNewExpressionContext(qualifiedStart) || + isInstanceofContext(qualifiedStart) || + ts.isImportEqualsDeclaration(parent) + ) ); } diff --git a/linter/src/utils/functions/isAssignmentOperator.ts b/linter/src/utils/functions/isAssignmentOperator.ts index d2476dc2f328b5d80192d5bef8fae56d07dc7958..3813a2bd126b89fc49ce71cac56157870b896910 100644 --- a/linter/src/utils/functions/isAssignmentOperator.ts +++ b/linter/src/utils/functions/isAssignmentOperator.ts @@ -16,5 +16,8 @@ import * as ts from 'typescript'; export function isAssignmentOperator(tsBinOp: ts.BinaryOperatorToken): boolean { - return tsBinOp.kind >= ts.SyntaxKind.FirstAssignment && tsBinOp.kind <= ts.SyntaxKind.LastAssignment; -} \ No newline at end of file + return ( + tsBinOp.kind >= ts.SyntaxKind.FirstAssignment && + tsBinOp.kind <= ts.SyntaxKind.LastAssignment + ); +} diff --git a/linter/test/ambient_module.ts.relax.json b/linter/test/ambient_module.ts.relax.json index a02ca7fc8935464e83947500d0dfc1e6558752dd..543d0a12ae515b61dfce8f85cf2bb8a33b955d0f 100755 --- a/linter/test/ambient_module.ts.relax.json +++ b/linter/test/ambient_module.ts.relax.json @@ -26,7 +26,7 @@ "column": 3, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 20, @@ -47,7 +47,7 @@ "column": 3, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 25, diff --git a/linter/test/ambient_module.ts.strict.json b/linter/test/ambient_module.ts.strict.json index a02ca7fc8935464e83947500d0dfc1e6558752dd..543d0a12ae515b61dfce8f85cf2bb8a33b955d0f 100755 --- a/linter/test/ambient_module.ts.strict.json +++ b/linter/test/ambient_module.ts.strict.json @@ -26,7 +26,7 @@ "column": 3, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 20, @@ -47,7 +47,7 @@ "column": 3, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 25, diff --git a/linter/test/array_literals.ts b/linter/test/array_literals.ts index 4c5e9de197ab904fc53feb06cf4e440e81808066..5889b08baa937a07d7b5130bb742110c9f34fe22 100644 --- a/linter/test/array_literals.ts +++ b/linter/test/array_literals.ts @@ -124,4 +124,3 @@ class P { let a1 = [ { n:1, s:"1" } as P, { n:2, s:"2" } as P ]; // OK let a2: P[] = [ { n:3, s:"3" }, { n:4, s:"4" } ]; // OK let a3 = [ { n:1, s:"1" }, { n:2, s:"2" } ]; // NOT OK - \ No newline at end of file diff --git a/linter/test/class_as_object.ts b/linter/test/class_as_object.ts index e91d6c0246cd4f7ae5b14a230acadc3ae820e676..6fa062cdc16a2496a89a38e2f90b5fd362972d1b 100644 --- a/linter/test/class_as_object.ts +++ b/linter/test/class_as_object.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { Something, SomethingFactory, SomethingBar, Bar } from "./oh_modules/ohos_factory"; +import { Something, SomethingFactory, SomethingBar, Bar, Select } from "./oh_modules/ohos_factory"; class C { static a = 5 @@ -91,3 +91,28 @@ for (let item = 0; item < Object.keys(Color).length; item++) { foo2(() => C); export { C as H }; + +// #14228 +let data = new Select().from(C).eq('key').query(C); // Ok +invalid_func(C); // Ok +let a: any; +a.foo(C); // Ok + +let col = 'WHITE'; +console.log(Color[col]) + +// #14184 +namespace NS { + export enum E { + A = 'A', + B = 'B', + C = 'C' + } +} + +let s: string = 'B'; +let s2: string = NS.E[s]; + +for (let item = 0; item < Object.keys(NS.E).length; item++) { + console.log(item); +} \ No newline at end of file diff --git a/linter/test/class_as_object.ts.relax.json b/linter/test/class_as_object.ts.relax.json index 0fdca907248f03f85893c5f89d279959c5953271..ebe30080e0920cd92ae2320990d9786929a655f9 100644 --- a/linter/test/class_as_object.ts.relax.json +++ b/linter/test/class_as_object.ts.relax.json @@ -15,72 +15,121 @@ { "line": 27, "column": 9, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 28, "column": 5, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 29, "column": 11, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 30, "column": 7, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 38, "column": 20, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 39, "column": 6, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 42, "column": 12, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 45, "column": 20, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 46, "column": 8, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 49, "column": 14, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 58, "column": 22, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 60, "column": 7, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 87, "column": 39, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 91, "column": 12, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + }, + { + "line": 96, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 98, + "column": 8, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 116, + "column": 42, + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" } ] } \ No newline at end of file diff --git a/linter/test/class_as_object.ts.strict.json b/linter/test/class_as_object.ts.strict.json index 0fdca907248f03f85893c5f89d279959c5953271..ebe30080e0920cd92ae2320990d9786929a655f9 100644 --- a/linter/test/class_as_object.ts.strict.json +++ b/linter/test/class_as_object.ts.strict.json @@ -15,72 +15,121 @@ { "line": 27, "column": 9, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 28, "column": 5, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 29, "column": 11, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 30, "column": 7, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 38, "column": 20, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 39, "column": 6, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 42, "column": 12, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 45, "column": 20, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 46, "column": 8, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 49, "column": 14, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 58, "column": 22, - "problem": "TypeQuery" + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" }, { "line": 60, "column": 7, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 87, "column": 39, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" }, { "line": 91, "column": 12, - "problem": "ClassAsObject" + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + }, + { + "line": 96, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 98, + "column": 8, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 116, + "column": 42, + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" } ] } \ No newline at end of file diff --git a/linter/test/default_imports.ts.autofix.json b/linter/test/default_imports.ts.autofix.json index f666c003d98fa83eedd2bc41c6331a7158c3fff2..b083d587f19d1116c31f7ac1486b08dc89500359 100755 --- a/linter/test/default_imports.ts.autofix.json +++ b/linter/test/default_imports.ts.autofix.json @@ -40,19 +40,6 @@ } ] }, - { - "line": 17, - "column": 8, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 655, - "end": 675, - "replacementText": "{ default as D2 }" - } - ] - }, { "line": 18, "column": 9, @@ -92,19 +79,6 @@ } ] }, - { - "line": 20, - "column": 8, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 785, - "end": 811, - "replacementText": "{ C, default as D5, D }" - } - ] - }, { "line": 21, "column": 17, @@ -117,19 +91,6 @@ "replacementText": "D5, { type E, F }" } ] - }, - { - "line": 21, - "column": 9, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 835, - "end": 841, - "replacementText": "E" - } - ] } ] } \ No newline at end of file diff --git a/linter/test/default_imports.ts.strict.json b/linter/test/default_imports.ts.strict.json index 07471ba2bafabe3b366b8d2655a8d79ad90895e7..ffea8cd37a136b792cb2a77f05e5caa14c7634b3 100755 --- a/linter/test/default_imports.ts.strict.json +++ b/linter/test/default_imports.ts.strict.json @@ -24,21 +24,11 @@ "column": 14, "problem": "DefaultImport" }, - { - "line": 17, - "column": 8, - "problem": "TypeOnlyImport" - }, { "line": 18, "column": 9, "problem": "DefaultImport" }, - { - "line": 18, - "column": 9, - "problem": "TypeOnlyImport" - }, { "line": 19, "column": 12, @@ -49,25 +39,10 @@ "column": 17, "problem": "DefaultImport" }, - { - "line": 20, - "column": 8, - "problem": "TypeOnlyImport" - }, { "line": 21, "column": 17, "problem": "DefaultImport" - }, - { - "line": 21, - "column": 9, - "problem": "TypeOnlyImport" - }, - { - "line": 21, - "column": 17, - "problem": "TypeOnlyImport" } ] } \ No newline at end of file diff --git a/linter/test/dynamic_lib.d.ts b/linter/test/dynamic_lib.d.ts index e3da589b5418ec259aa310a41fea0f454f17ede3..843931397eaf4c1fce6ff89f458826d49642771c 100644 --- a/linter/test/dynamic_lib.d.ts +++ b/linter/test/dynamic_lib.d.ts @@ -93,3 +93,7 @@ declare class B { } export declare function bad_func(): A & B; + +export type IndexedSignatureType = { + [key: string]: string; +} \ No newline at end of file diff --git a/linter/test/dynamic_object_literals.ts b/linter/test/dynamic_object_literals.ts index ea7f9759a2e8cf76d1eb0dd81536959bfcf1beeb..fae9413ea1d4ccb581327bddbdda25cb9c805912 100644 --- a/linter/test/dynamic_object_literals.ts +++ b/linter/test/dynamic_object_literals.ts @@ -24,7 +24,8 @@ import { dynamic_array, padding, margin, - position + position, + IndexedSignatureType } from "./dynamic_lib" function main(): void { @@ -84,4 +85,13 @@ dynamic_array.splice(2, 0, {a: 1, b: '2'}); // #13550 - allow literals as property names in dynamic context padding({'top': '0px', 'right': '5px', 'bottom': '10px', 'left': '15px'}); margin({'top': '10px', 'right': '20px', 'bottom': '30px', 'left': '40px'}); -position({'x': '20', 'y': '40'}); \ No newline at end of file +position({'x': '20', 'y': '40'}); + +// allow literal as property name for type aliases that come from interop +function typeAliasLitAsPropName(): IndexedSignatureType { + return { + 'a': '1', + 'b': '2', + 'c': '3' + } +} \ No newline at end of file diff --git a/linter/test/es_object.ts b/linter/test/es_object.ts index 445b5c0c07e1db8eb18c4006d860e3476659f6ae..cd1e530caa0989a80f1226c8b1a1d9a6c6a7c8f3 100644 --- a/linter/test/es_object.ts +++ b/linter/test/es_object.ts @@ -145,7 +145,7 @@ foo4([2, 3]) foo5([2, 3]) foo4(["str1", "str2"]) foo5(["str1", "str2"]) -let n = new ESObject[0] +let n: ESObject n = null foo4(n) diff --git a/linter/test/es_object.ts.relax.json b/linter/test/es_object.ts.relax.json index f3d5acdb48589622baa499e265b74a732fa003f6..5bab1a3eee7a781b35c0996be116badfe9617820 100644 --- a/linter/test/es_object.ts.relax.json +++ b/linter/test/es_object.ts.relax.json @@ -26,231 +26,231 @@ "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 21, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 22, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 25, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 26, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 27, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 21, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 35, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 53, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 60, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 63, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 63, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 65, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 60, @@ -271,175 +271,175 @@ "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 64, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 64, "column": 50, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 66, "column": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 67, "column": 17, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 70, "column": 13, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 71, "column": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 77, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 78, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 79, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 80, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 82, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 83, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 85, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 86, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 87, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 88, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 90, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 91, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 93, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 94, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 95, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 96, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 98, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 99, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 103, @@ -453,28 +453,28 @@ "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 106, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 108, "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 109, "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 114, @@ -488,105 +488,112 @@ "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 119, "column": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 119, "column": 36, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 136, "column": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 136, "column": 38, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 148, "column": 5, - "problem": "AnyType", + "problem": "EsObjectType", "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + }, + { + "line": 149, + "column": 1, + "problem": "EsObjectType", + "suggest": "", + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 45, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 47, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 60, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 170, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 172, "column": 22, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 174, "column": 30, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 176, @@ -600,21 +607,21 @@ "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 178, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 179, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 181, @@ -628,49 +635,49 @@ "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 183, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 184, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 185, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 188, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 189, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 190, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" } ] } \ No newline at end of file diff --git a/linter/test/es_object.ts.strict.json b/linter/test/es_object.ts.strict.json index 5c869e41f36b202e2f7537f9bfa7a312c7073b8a..c0ef7ba377f3807ea65571da92fd87b60f274619 100644 --- a/linter/test/es_object.ts.strict.json +++ b/linter/test/es_object.ts.strict.json @@ -26,231 +26,231 @@ "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 21, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 22, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 25, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 26, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 27, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 21, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 35, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 53, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 60, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 63, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 63, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 65, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 60, @@ -271,175 +271,182 @@ "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 64, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 64, "column": 50, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 66, "column": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 67, "column": 17, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 70, "column": 13, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 71, "column": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 77, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 78, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + }, + { + "line": 79, + "column": 5, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" }, { "line": 79, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 80, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 82, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 83, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 85, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 86, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 87, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 88, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 90, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 91, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 93, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 94, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 95, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 96, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 98, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 99, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 103, @@ -453,28 +460,28 @@ "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 106, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 108, "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 109, "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 114, @@ -488,105 +495,112 @@ "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 119, "column": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 119, "column": 36, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 136, "column": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 136, "column": 38, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 148, "column": 5, - "problem": "AnyType", + "problem": "EsObjectType", "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + }, + { + "line": 149, + "column": 1, + "problem": "EsObjectType", + "suggest": "", + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 45, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 47, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 60, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 170, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 172, "column": 22, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 174, "column": 30, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 176, @@ -600,21 +614,21 @@ "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 178, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 179, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 181, @@ -628,49 +642,63 @@ "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 183, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 184, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 185, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + }, + { + "line": 188, + "column": 5, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" }, { "line": 188, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + }, + { + "line": 189, + "column": 5, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" }, { "line": 189, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" }, { "line": 190, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobject)" + "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" } ] } \ No newline at end of file diff --git a/linter/test/function_expression.ts.autofix.json b/linter/test/function_expression.ts.autofix.json index 90e6f3f3b1843e1b27a91717ae8ec47ced32aeaa..e005781ad91e4c1a3c375d88874c9f64811e06bb 100644 --- a/linter/test/function_expression.ts.autofix.json +++ b/linter/test/function_expression.ts.autofix.json @@ -267,6 +267,14 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 82, + "column": 19, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, { "line": 82, "column": 19, @@ -335,6 +343,14 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 102, + "column": 15, + "problem": "FunctionApplyBindCall", + "autofixable": false, + "suggest": "", + "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" + }, { "line": 102, "column": 15, @@ -350,14 +366,6 @@ "suggest": "", "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" }, - { - "line": 104, - "column": 7, - "problem": "FunctionApplyBindCall", - "autofixable": false, - "suggest": "", - "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" - }, { "line": 108, "column": 16, diff --git a/linter/test/function_expression.ts.relax.json b/linter/test/function_expression.ts.relax.json index 8e60772364f880a2b1734887f006e79ab0075cdd..48f6e1a27f9cde8a9f97bd009fcf972843b37619 100644 --- a/linter/test/function_expression.ts.relax.json +++ b/linter/test/function_expression.ts.relax.json @@ -57,8 +57,8 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { - "line": 104, - "column": 7, + "line": 102, + "column": 15, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" diff --git a/linter/test/function_expression.ts.strict.json b/linter/test/function_expression.ts.strict.json index 1233c4e7db472396252e3157aac380db56d8e583..48723e4cddfa69f67dde850ebe2d3b944276fb9e 100644 --- a/linter/test/function_expression.ts.strict.json +++ b/linter/test/function_expression.ts.strict.json @@ -168,6 +168,13 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 82, + "column": 19, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, { "line": 82, "column": 19, @@ -206,16 +213,16 @@ { "line": 102, "column": 15, - "problem": "FunctionExpression", + "problem": "FunctionApplyBindCall", "suggest": "", - "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" + "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { - "line": 104, - "column": 7, - "problem": "FunctionApplyBindCall", + "line": 102, + "column": 15, + "problem": "FunctionExpression", "suggest": "", - "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" }, { "line": 108, diff --git a/linter/test/function_object_methods.ts.relax.json b/linter/test/function_object_methods.ts.relax.json index 790856d4f7ac64e42723ba8be5a20b7ae18f32a2..96e3fcaf15c33d5b989eb091c20e1961ab3994b9 100644 --- a/linter/test/function_object_methods.ts.relax.json +++ b/linter/test/function_object_methods.ts.relax.json @@ -23,7 +23,7 @@ }, { "line": 29, - "column": 35, + "column": 21, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -37,21 +37,21 @@ }, { "line": 30, - "column": 45, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 37, - "column": 37, + "column": 23, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 38, - "column": 40, + "column": 21, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -65,7 +65,7 @@ }, { "line": 68, - "column": 44, + "column": 22, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -79,42 +79,42 @@ }, { "line": 70, - "column": 35, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 75, - "column": 48, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 78, - "column": 48, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 81, - "column": 31, + "column": 9, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 82, - "column": 31, + "column": 9, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 87, - "column": 32, + "column": 16, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -128,7 +128,7 @@ }, { "line": 94, - "column": 37, + "column": 20, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -142,42 +142,42 @@ }, { "line": 96, - "column": 30, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 101, - "column": 42, + "column": 25, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 104, - "column": 42, + "column": 25, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 107, - "column": 20, + "column": 3, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 108, - "column": 20, + "column": 3, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 113, - "column": 21, + "column": 10, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -226,35 +226,35 @@ }, { "line": 136, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 137, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 138, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 139, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 141, - "column": 5, + "column": 1, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" diff --git a/linter/test/function_object_methods.ts.strict.json b/linter/test/function_object_methods.ts.strict.json index 2a7c8ccd943aded4391752c20d2e26ecc66b4c29..e90572ea9fa1ff6f639076c45d74320d7d9469d6 100644 --- a/linter/test/function_object_methods.ts.strict.json +++ b/linter/test/function_object_methods.ts.strict.json @@ -23,7 +23,7 @@ }, { "line": 29, - "column": 35, + "column": 21, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -37,21 +37,21 @@ }, { "line": 30, - "column": 45, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 37, - "column": 37, + "column": 23, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 38, - "column": 40, + "column": 21, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -65,7 +65,7 @@ }, { "line": 68, - "column": 44, + "column": 22, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -79,42 +79,42 @@ }, { "line": 70, - "column": 35, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 75, - "column": 48, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 78, - "column": 48, + "column": 26, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 81, - "column": 31, + "column": 9, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 82, - "column": 31, + "column": 9, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 87, - "column": 32, + "column": 16, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -128,7 +128,7 @@ }, { "line": 94, - "column": 37, + "column": 20, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -142,42 +142,42 @@ }, { "line": 96, - "column": 30, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 101, - "column": 42, + "column": 25, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 104, - "column": 42, + "column": 25, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 107, - "column": 20, + "column": 3, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 108, - "column": 20, + "column": 3, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 113, - "column": 21, + "column": 10, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" @@ -254,35 +254,35 @@ }, { "line": 136, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 137, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 138, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 139, - "column": 23, + "column": 13, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" }, { "line": 141, - "column": 5, + "column": 1, "problem": "FunctionApplyBindCall", "suggest": "", "rule": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)" diff --git a/linter/test/functions.ts b/linter/test/functions.ts index 8d67f99ff3292a00005ed662c0798ca5ab08801e..fd8646324ae5cec720ba4c189a8dfdac408f85ff 100644 --- a/linter/test/functions.ts +++ b/linter/test/functions.ts @@ -105,4 +105,23 @@ bar(() => { bar(() => { f(null); }, null, f(null)); -}, null, foo(f(null))); \ No newline at end of file +}, null, foo(f(null))); + +type PropDecorator = () => void; +let Builder: PropDecorator; + +// this test is useless until we use custom tsc +@Builder +function buildSwiper() { + f(null) + foo(null) { + f(null) + foo(null) { + f(null) + foo(() => { + f(null) + }) + } + .foo(null) + } +} diff --git a/linter/test/functions.ts.autofix.json b/linter/test/functions.ts.autofix.json index bdec3c538a0a38afa2968f452019ea0cc98ccffe..944c5bf6b00aa3659df8313054492cb1ea47856f 100755 --- a/linter/test/functions.ts.autofix.json +++ b/linter/test/functions.ts.autofix.json @@ -157,6 +157,38 @@ "autofixable": false, "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 116, + "column": 5, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 118, + "column": 7, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 120, + "column": 11, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 122, + "column": 11, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." } ] } \ No newline at end of file diff --git a/linter/test/functions.ts.relax.json b/linter/test/functions.ts.relax.json index e11f7f9c4b4ba8fd83a515d2609ee21e3b7f6c08..1e86ab2f19832ca9bf8a34ad0e3cf11cea54bb8e 100644 --- a/linter/test/functions.ts.relax.json +++ b/linter/test/functions.ts.relax.json @@ -125,6 +125,34 @@ "problem": "StrictDiagnostic", "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 116, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 118, + "column": 7, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 120, + "column": 11, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 122, + "column": 11, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." } ] } \ No newline at end of file diff --git a/linter/test/functions.ts.strict.json b/linter/test/functions.ts.strict.json index d39199ff0024aa2f8a01d89ad214a4e3c83e8212..a1c2214e52d001dfb28b51cd6867ddd774c91cdb 100644 --- a/linter/test/functions.ts.strict.json +++ b/linter/test/functions.ts.strict.json @@ -139,6 +139,34 @@ "problem": "StrictDiagnostic", "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 116, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 118, + "column": 7, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 120, + "column": 11, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." + }, + { + "line": 122, + "column": 11, + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'string'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'string'." } ] } \ No newline at end of file diff --git a/linter/test/limited_stdlib_api.ts b/linter/test/limited_stdlib_api.ts index 500c10c9b1d179d12501a1cd57028ecfddda560e..e0213de3b393291674d76f750d8f818bcfe3f3de 100644 --- a/linter/test/limited_stdlib_api.ts +++ b/linter/test/limited_stdlib_api.ts @@ -28,7 +28,7 @@ decodeURIComponent(''); escape(''); unescape(''); -// global and window are not portable, so they are excluded from test suite. +global.eval('console.log("foo")'); globalThis.eval('console.log("foo")'); const evl = "eval('console.log(1)')"; const res: void = Function(evl)(); @@ -121,9 +121,3 @@ ArrayBuffer.isView({}); let a: number[] = []; let b = new ArrayBuffer(1); Array.isArray(a); - -Number.NaN; -Number.isFinite(1); -Number.isNaN(2); -Number.parseFloat('3'); -Number.parseInt('4', 10); diff --git a/linter/test/limited_stdlib_api.ts.autofix.json b/linter/test/limited_stdlib_api.ts.autofix.json index ddabd1f8994bb6f656b118c4383596b762abe056..5fa775012fb48f18a4851216424f369122f42dfb 100644 --- a/linter/test/limited_stdlib_api.ts.autofix.json +++ b/linter/test/limited_stdlib_api.ts.autofix.json @@ -23,24 +23,32 @@ "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { - "line": 32, + "line": 31, "column": 1, - "problem": "GlobalThis", + "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", - "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 32, - "column": 12, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, + { + "line": 32, + "column": 1, + "problem": "GlobalThis", + "autofixable": false, + "suggest": "", + "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + }, { "line": 56, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -48,7 +56,7 @@ }, { "line": 57, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -56,7 +64,7 @@ }, { "line": 58, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -72,7 +80,7 @@ }, { "line": 59, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -80,7 +88,7 @@ }, { "line": 61, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -88,7 +96,7 @@ }, { "line": 62, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -96,7 +104,7 @@ }, { "line": 63, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -104,7 +112,7 @@ }, { "line": 64, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -112,7 +120,7 @@ }, { "line": 65, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -120,7 +128,7 @@ }, { "line": 66, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -128,7 +136,7 @@ }, { "line": 67, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -136,7 +144,7 @@ }, { "line": 68, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -144,7 +152,7 @@ }, { "line": 69, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -152,7 +160,7 @@ }, { "line": 70, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -160,7 +168,7 @@ }, { "line": 71, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -168,7 +176,7 @@ }, { "line": 72, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -176,7 +184,7 @@ }, { "line": 73, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -184,7 +192,7 @@ }, { "line": 74, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -192,7 +200,7 @@ }, { "line": 75, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -200,7 +208,7 @@ }, { "line": 76, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -208,7 +216,7 @@ }, { "line": 85, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -216,7 +224,7 @@ }, { "line": 86, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -232,7 +240,7 @@ }, { "line": 87, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -248,7 +256,7 @@ }, { "line": 88, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -256,7 +264,7 @@ }, { "line": 90, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -264,7 +272,7 @@ }, { "line": 91, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -272,7 +280,7 @@ }, { "line": 92, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -280,7 +288,7 @@ }, { "line": 93, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -288,7 +296,7 @@ }, { "line": 94, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -304,15 +312,7 @@ }, { "line": 105, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 105, - "column": 28, + "column": 20, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -320,15 +320,7 @@ }, { "line": 106, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 106, - "column": 32, + "column": 24, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -336,15 +328,7 @@ }, { "line": 107, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 107, - "column": 37, + "column": 29, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -360,15 +344,7 @@ }, { "line": 108, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 108, - "column": 37, + "column": 29, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -376,23 +352,7 @@ }, { "line": 109, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 109, - "column": 26, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 110, - "column": 13, + "column": 18, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -400,15 +360,7 @@ }, { "line": 110, - "column": 47, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 111, - "column": 13, + "column": 39, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -416,15 +368,7 @@ }, { "line": 111, - "column": 37, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 112, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -432,15 +376,7 @@ }, { "line": 112, - "column": 26, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 113, - "column": 13, + "column": 18, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -448,7 +384,7 @@ }, { "line": 113, - "column": 35, + "column": 27, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -456,23 +392,7 @@ }, { "line": 114, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 114, - "column": 30, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 115, - "column": 13, + "column": 22, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -480,15 +400,7 @@ }, { "line": 115, - "column": 40, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 116, - "column": 13, + "column": 32, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -496,7 +408,7 @@ }, { "line": 116, - "column": 26, + "column": 18, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", @@ -504,23 +416,7 @@ }, { "line": 117, - "column": 13, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 117, - "column": 37, - "problem": "LimitedStdLibApi", - "autofixable": false, - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 120, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", diff --git a/linter/test/limited_stdlib_api.ts.relax.json b/linter/test/limited_stdlib_api.ts.relax.json index d77e760a87296a86fded6e3d9e77ffd7fa7ffc76..22ad3a0ad0db9e8392f7e99130b121aff255248c 100644 --- a/linter/test/limited_stdlib_api.ts.relax.json +++ b/linter/test/limited_stdlib_api.ts.relax.json @@ -22,36 +22,43 @@ "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { - "line": 32, + "line": 31, "column": 1, - "problem": "GlobalThis", + "problem": "LimitedStdLibApi", "suggest": "", - "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 32, - "column": 12, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, + { + "line": 32, + "column": 1, + "problem": "GlobalThis", + "suggest": "", + "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + }, { "line": 56, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 57, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 58, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -65,133 +72,133 @@ }, { "line": 59, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 61, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 62, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 63, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 64, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 65, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 66, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 67, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 68, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 69, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 70, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 71, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 72, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 73, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 74, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 75, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 76, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 85, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 86, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -205,7 +212,7 @@ }, { "line": 87, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -219,42 +226,42 @@ }, { "line": 88, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 90, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 91, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 92, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 93, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 94, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -268,42 +275,21 @@ }, { "line": 105, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 105, - "column": 28, + "column": 20, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 106, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 106, - "column": 32, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 107, - "column": 13, + "column": 24, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 107, - "column": 37, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -317,147 +303,70 @@ }, { "line": 108, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 108, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 109, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 109, - "column": 26, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 110, - "column": 13, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 110, - "column": 47, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 111, - "column": 13, + "column": 39, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 111, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 112, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 112, - "column": 26, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 113, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 113, - "column": 35, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 114, - "column": 13, + "column": 27, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 114, - "column": 30, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 115, - "column": 13, + "column": 22, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 115, - "column": 40, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 116, - "column": 13, + "column": 32, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 116, - "column": 26, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 117, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 117, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 120, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" diff --git a/linter/test/limited_stdlib_api.ts.strict.json b/linter/test/limited_stdlib_api.ts.strict.json index d77e760a87296a86fded6e3d9e77ffd7fa7ffc76..22ad3a0ad0db9e8392f7e99130b121aff255248c 100644 --- a/linter/test/limited_stdlib_api.ts.strict.json +++ b/linter/test/limited_stdlib_api.ts.strict.json @@ -22,36 +22,43 @@ "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { - "line": 32, + "line": 31, "column": 1, - "problem": "GlobalThis", + "problem": "LimitedStdLibApi", "suggest": "", - "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 32, - "column": 12, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, + { + "line": 32, + "column": 1, + "problem": "GlobalThis", + "suggest": "", + "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + }, { "line": 56, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 57, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 58, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -65,133 +72,133 @@ }, { "line": 59, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 61, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 62, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 63, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 64, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 65, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 66, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 67, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 68, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 69, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 70, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 71, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 72, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 73, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 74, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 75, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 76, - "column": 8, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 85, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 86, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -205,7 +212,7 @@ }, { "line": 87, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -219,42 +226,42 @@ }, { "line": 88, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 90, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 91, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 92, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 93, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 94, - "column": 9, + "column": 1, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -268,42 +275,21 @@ }, { "line": 105, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 105, - "column": 28, + "column": 20, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 106, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 106, - "column": 32, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 107, - "column": 13, + "column": 24, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 107, - "column": 37, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" @@ -317,147 +303,70 @@ }, { "line": 108, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 108, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 109, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 109, - "column": 26, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 110, - "column": 13, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 110, - "column": 47, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 111, - "column": 13, + "column": 39, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 111, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 112, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 112, - "column": 26, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 113, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 113, - "column": 35, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 114, - "column": 13, + "column": 27, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 114, - "column": 30, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 115, - "column": 13, + "column": 22, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 115, - "column": 40, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 116, - "column": 13, + "column": 32, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 116, - "column": 26, + "column": 18, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" }, { "line": 117, - "column": 13, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 117, - "column": 37, - "problem": "LimitedStdLibApi", - "suggest": "", - "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" - }, - { - "line": 120, - "column": 13, + "column": 29, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" diff --git a/linter/test/modules.ts.autofix.json b/linter/test/modules.ts.autofix.json index 3c5ec13d6f685451e8553fcdd3948471d0dd5d16..c78c786038a4bbdbe0aa25169ef04201cde936c3 100755 --- a/linter/test/modules.ts.autofix.json +++ b/linter/test/modules.ts.autofix.json @@ -111,96 +111,18 @@ "problem": "ImportAfterStatement", "autofixable": false }, - { - "line": 92, - "column": 8, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 1923, - "end": 1947, - "replacementText": "{ APIResponseType }" - } - ] - }, { "line": 93, "column": 1, "problem": "ImportAfterStatement", "autofixable": false }, - { - "line": 93, - "column": 8, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 1969, - "end": 1980, - "replacementText": "* as P" - } - ] - }, { "line": 94, "column": 1, "problem": "ImportAfterStatement", "autofixable": false }, - { - "line": 94, - "column": 10, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 2002, - "end": 2009, - "replacementText": "T1" - } - ] - }, - { - "line": 94, - "column": 19, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 2011, - "end": 2024, - "replacementText": "T2 as T3" - } - ] - }, - { - "line": 97, - "column": 1, - "problem": "TypeOnlyExport", - "autofixable": true, - "autofix": [ - { - "start": 2063, - "end": 2094, - "replacementText": "export { TypeA as TypeB };" - } - ] - }, - { - "line": 98, - "column": 10, - "problem": "TypeOnlyExport", - "autofixable": true, - "autofix": [ - { - "start": 2104, - "end": 2127, - "replacementText": "TypeFoo as TypeBar" - } - ] - }, { "line": 106, "column": 1, diff --git a/linter/test/modules.ts.strict.json b/linter/test/modules.ts.strict.json index c13f8f250c733e4a83febe03b93c51b08f61dae7..273338ee9f32ab2cf5c5e1280ab9e3371f9aaa13 100644 --- a/linter/test/modules.ts.strict.json +++ b/linter/test/modules.ts.strict.json @@ -89,46 +89,16 @@ "column": 1, "problem": "ImportAfterStatement" }, - { - "line": 92, - "column": 8, - "problem": "TypeOnlyImport" - }, { "line": 93, "column": 1, "problem": "ImportAfterStatement" }, - { - "line": 93, - "column": 8, - "problem": "TypeOnlyImport" - }, { "line": 94, "column": 1, "problem": "ImportAfterStatement" }, - { - "line": 94, - "column": 10, - "problem": "TypeOnlyImport" - }, - { - "line": 94, - "column": 19, - "problem": "TypeOnlyImport" - }, - { - "line": 97, - "column": 1, - "problem": "TypeOnlyExport" - }, - { - "line": 98, - "column": 10, - "problem": "TypeOnlyExport" - }, { "line": 106, "column": 1, diff --git a/linter/test/new_target.ts.relax.json b/linter/test/new_target.ts.relax.json index 0b83a11983237ced2f41aa64eaaeb370019ee51f..5ec99daa29eeeccfa7c6b5bdcdcefea2f5999fe5 100644 --- a/linter/test/new_target.ts.relax.json +++ b/linter/test/new_target.ts.relax.json @@ -16,7 +16,7 @@ "nodes": [ { "line": 19, - "column": 12, + "column": 5, "problem": "LimitedStdLibApi" }, { diff --git a/linter/test/new_target.ts.strict.json b/linter/test/new_target.ts.strict.json index 0b83a11983237ced2f41aa64eaaeb370019ee51f..5ec99daa29eeeccfa7c6b5bdcdcefea2f5999fe5 100644 --- a/linter/test/new_target.ts.strict.json +++ b/linter/test/new_target.ts.strict.json @@ -16,7 +16,7 @@ "nodes": [ { "line": 19, - "column": 12, + "column": 5, "problem": "LimitedStdLibApi" }, { diff --git a/linter/test/oh_modules/ohos_factory.ts b/linter/test/oh_modules/ohos_factory.ts index e26c4c911ba886e1d930a38404f9a87434d454b3..b4fc3d2d2fe025f7deb68faa0cf3374beece71ee 100644 --- a/linter/test/oh_modules/ohos_factory.ts +++ b/linter/test/oh_modules/ohos_factory.ts @@ -16,3 +16,18 @@ export declare class SomethingBar extends Something { } export declare class Bar { constructor(arg: { new(): T }); } + +export class Select { + public from(cls: any) { + return this; + } + + // we intentionally omit generic argument of 'Select', see #14228 + public eq(name: string): Select { + return this; + } + + public query(cls: any): Promise { + return cls.foo(); + } +} \ No newline at end of file diff --git a/linter/test/property_access_by_index.ts b/linter/test/property_access_by_index.ts new file mode 100644 index 0000000000000000000000000000000000000000..407d7055373017e1d207c0ad4cc5de563ef21474 --- /dev/null +++ b/linter/test/property_access_by_index.ts @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// #14071 +class A { + v: string = ''; +} +function SetProperty(oldObj: T, str: string, obj: Object): void { + oldObj[str] = obj; // Should report error +} +function GetProperty(oldObj: T, str: string): U { + return oldObj[str]; // Should report error +} +function test() { + let a: A = { v: 'abc' }; + SetProperty(a, 'u', 'def'); + return GetProperty(a, 'v') + GetProperty(a, 'u'); +} + +let ar1 = [1, 2, 3, 4]; +let ar2 = [1, '2', 3, 4]; +let ar3: number[] = []; + +ar1[2]; +ar2[2]; +ar3[2]; + +const r0 = [1, 2, 3][1]; +let r1 = [1, 2, 3, 4][0] +let r2 = [1, '2', 3, 4][0] + +function fobject1(o: object) { + o['j'] +} + +function fobject2(o: Object) { + o['k'] +} + +let array1 = [0,1] +let array2 = [1,2,3,4,5] +let array3: number[] = [1,2,3,4,5] +let array4: Array = [1,2,3,4,5] +let array5 = new Array(10) +let array6 = new Int8Array(10) +let array7 = new Uint8Array(10) +let array8 = new Uint8ClampedArray(10) +let array9 = new Int16Array(10) +let array10 = new Uint16Array(10) +let array11 = new Int32Array(10) +let array12 = new Uint32Array(10) +let array13 = new Float32Array(10) +let array14 = new Float64Array(10) +let array15 = new BigInt64Array(10) +let array16 = new BigUint64Array(10) + +array1[0]; +array2[0]; +array3[0]; +array4[0]; +array5[0]; +array6[0]; +array7[0]; +array8[0]; +array9[0]; +array10[0]; +array11[0]; +array12[0]; +array13[0]; +array14[0]; +array15[0]; +array16[0]; + +function fff1(r: Record) { + r['bob'] +} + +enum CCCCCCCCC { + KATE, + BOB, + ROB, +} + +CCCCCCCCC['KATE'] +CCCCCCCCC['BOB'] +CCCCCCCCC['ROB'] + +CCCCCCCCC[CCCCCCCCC.KATE] +CCCCCCCCC[CCCCCCCCC.BOB] +CCCCCCCCC[CCCCCCCCC.ROB] diff --git a/linter/test/property_access_by_index.ts.autofix.json b/linter/test/property_access_by_index.ts.autofix.json new file mode 100644 index 0000000000000000000000000000000000000000..2c4552959c61360287bfced911da4678778738ff --- /dev/null +++ b/linter/test/property_access_by_index.ts.autofix.json @@ -0,0 +1,58 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 21, + "column": 3, + "problem": "PropertyAccessByIndex", + "autofixable": false, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 24, + "column": 10, + "problem": "PropertyAccessByIndex", + "autofixable": false, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 45, + "column": 3, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 49, + "column": 3, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 56, + "column": 5, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter/test/property_access_by_index.ts.relax.json b/linter/test/property_access_by_index.ts.relax.json new file mode 100644 index 0000000000000000000000000000000000000000..6cefe023006258af8a68d625b2b8f2bfeb0ce012 --- /dev/null +++ b/linter/test/property_access_by_index.ts.relax.json @@ -0,0 +1,25 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 56, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter/test/property_access_by_index.ts.strict.json b/linter/test/property_access_by_index.ts.strict.json new file mode 100644 index 0000000000000000000000000000000000000000..6bb2b04001484dde5785ebd81b090e9afcee138f --- /dev/null +++ b/linter/test/property_access_by_index.ts.strict.json @@ -0,0 +1,53 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 21, + "column": 3, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 24, + "column": 10, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 45, + "column": 3, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 49, + "column": 3, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 56, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter/test/symbol_api.ts b/linter/test/symbol_api.ts index 2d33c448f2d46c9150ee43b838b41f7dc5d98a37..8d7d25d3e16a892137741335ce918d61bd964a59 100644 --- a/linter/test/symbol_api.ts +++ b/linter/test/symbol_api.ts @@ -50,3 +50,9 @@ class TestClass { return Symbol(); } } + +class BIter { + [Symbol.iterator] = () => { + return 1; + }; +} diff --git a/linter/test/symbol_api.ts.relax.json b/linter/test/symbol_api.ts.relax.json index e62c8c7b772eb72b7c1c2e435f564313f0be758a..c2211cf10708b2fa141fd797dc845a3553c2e98a 100644 --- a/linter/test/symbol_api.ts.relax.json +++ b/linter/test/symbol_api.ts.relax.json @@ -16,77 +16,77 @@ "nodes": [ { "line": 16, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 17, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 18, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 20, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 21, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 22, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 23, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 24, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 25, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 26, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 27, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" @@ -107,7 +107,7 @@ }, { "line": 33, - "column": 17, + "column": 10, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" diff --git a/linter/test/symbol_api.ts.strict.json b/linter/test/symbol_api.ts.strict.json index e62c8c7b772eb72b7c1c2e435f564313f0be758a..c2211cf10708b2fa141fd797dc845a3553c2e98a 100644 --- a/linter/test/symbol_api.ts.strict.json +++ b/linter/test/symbol_api.ts.strict.json @@ -16,77 +16,77 @@ "nodes": [ { "line": 16, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 17, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 18, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 20, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 21, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 22, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 23, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 24, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 25, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 26, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" }, { "line": 27, - "column": 16, + "column": 9, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" @@ -107,7 +107,7 @@ }, { "line": 33, - "column": 17, + "column": 10, "problem": "SymbolType", "suggest": "", "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" diff --git a/linter/test/ts_ignore.ts.relax.json b/linter/test/ts_ignore.ts.relax.json index d1f5176718b5277f4744fd1d2237f1bec3ddae0e..8e4a16c18b27647b34afc96b9bce3cc271f48477 100644 --- a/linter/test/ts_ignore.ts.relax.json +++ b/linter/test/ts_ignore.ts.relax.json @@ -17,62 +17,86 @@ { "line": 16, "column": 1, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 21, "column": 3, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 25, "column": 19, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 30, "column": 9, - "problem": "ErrorSuppression" - }, - { - "line": 33, - "column": 2, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 43, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 52, "column": 3, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 53, "column": 3, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 55, "column": 22, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 56, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 58, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" + }, + { + "line": 75, + "column": 1, + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 18, "column": 5, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Type 'null' is not assignable to type 'number'.", + "rule": "Type 'null' is not assignable to type 'number'." } ] -} +} \ No newline at end of file diff --git a/linter/test/ts_ignore.ts.strict.json b/linter/test/ts_ignore.ts.strict.json index d1f5176718b5277f4744fd1d2237f1bec3ddae0e..8e4a16c18b27647b34afc96b9bce3cc271f48477 100644 --- a/linter/test/ts_ignore.ts.strict.json +++ b/linter/test/ts_ignore.ts.strict.json @@ -17,62 +17,86 @@ { "line": 16, "column": 1, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 21, "column": 3, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 25, "column": 19, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 30, "column": 9, - "problem": "ErrorSuppression" - }, - { - "line": 33, - "column": 2, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 43, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 52, "column": 3, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 53, "column": 3, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 55, "column": 22, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 56, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 58, "column": 9, - "problem": "ErrorSuppression" + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" + }, + { + "line": 75, + "column": 1, + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" }, { "line": 18, "column": 5, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Type 'null' is not assignable to type 'number'.", + "rule": "Type 'null' is not assignable to type 'number'." } ] -} +} \ No newline at end of file diff --git a/linter/test/types.ts.autofix.json b/linter/test/types.ts.autofix.json index 7833b9da06c47271168dc5b463b35b669eed9910..3263fe4927404003fa9338dcc7806eb519432e2c 100644 --- a/linter/test/types.ts.autofix.json +++ b/linter/test/types.ts.autofix.json @@ -214,6 +214,14 @@ "suggest": "", "rule": "\"in\" operator is not supported (arkts-no-in)" }, + { + "line": 78, + "column": 5, + "problem": "PropertyAccessByIndex", + "autofixable": false, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, { "line": 92, "column": 22, diff --git a/linter/test/types.ts.strict.json b/linter/test/types.ts.strict.json index 12af0241f0080993d1207515856d070dd647e821..50971119921dde92707a4fc5e30b91fe2d2fa2ee 100644 --- a/linter/test/types.ts.strict.json +++ b/linter/test/types.ts.strict.json @@ -189,6 +189,13 @@ "suggest": "", "rule": "\"in\" operator is not supported (arkts-no-in)" }, + { + "line": 78, + "column": 5, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, { "line": 92, "column": 22, diff --git a/linter/test/utility_types.ts.relax.json b/linter/test/utility_types.ts.relax.json index fe6131546f4334735729e5e3c1ab931d44572443..63a56e5cd84e9305c8c9235b62a945faa1f8a75f 100644 --- a/linter/test/utility_types.ts.relax.json +++ b/linter/test/utility_types.ts.relax.json @@ -266,7 +266,7 @@ }, { "line": 178, - "column": 18, + "column": 12, "problem": "FunctionApplyBindCall" }, { @@ -286,7 +286,7 @@ }, { "line": 187, - "column": 60, + "column": 54, "problem": "FunctionApplyBindCall" }, { diff --git a/linter/test/utility_types.ts.strict.json b/linter/test/utility_types.ts.strict.json index c5686de4b4c5b53e4bfe52a623bec80e0c788296..cb2916b9d5d09ea06f98df2322cb84b2bf0d83ae 100644 --- a/linter/test/utility_types.ts.strict.json +++ b/linter/test/utility_types.ts.strict.json @@ -291,7 +291,7 @@ }, { "line": 178, - "column": 18, + "column": 12, "problem": "FunctionApplyBindCall" }, { @@ -316,7 +316,7 @@ }, { "line": 187, - "column": 60, + "column": 54, "problem": "FunctionApplyBindCall" }, { diff --git a/linter/test_rules/rule116.ts.autofix.json b/linter/test_rules/rule116.ts.autofix.json index 8449964f6b0aebed7a3a412a87e959afbcb33487..f3a5f41b3b987383c1f652c7373135cda5df7173 100644 --- a/linter/test_rules/rule116.ts.autofix.json +++ b/linter/test_rules/rule116.ts.autofix.json @@ -6,7 +6,7 @@ "problem": "NonDeclarationInNamespace", "autofixable": false, "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule116.ts.relax.json b/linter/test_rules/rule116.ts.relax.json index a5030d64e8a3e5c962cfc25bcfc7d49e88e73a86..3259498ae75cd5e1f5d128bfeacd40f997681159 100644 --- a/linter/test_rules/rule116.ts.relax.json +++ b/linter/test_rules/rule116.ts.relax.json @@ -5,7 +5,7 @@ "column": 5, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule116.ts.strict.json b/linter/test_rules/rule116.ts.strict.json index a5030d64e8a3e5c962cfc25bcfc7d49e88e73a86..3259498ae75cd5e1f5d128bfeacd40f997681159 100644 --- a/linter/test_rules/rule116.ts.strict.json +++ b/linter/test_rules/rule116.ts.strict.json @@ -5,7 +5,7 @@ "column": 5, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule118.ts.autofix.json b/linter/test_rules/rule118.ts.autofix.json index 3ff68f6c73f0870b0af431b06348497a9bf6a784..13f13363f579325755e8954b4011963971667481 100644 --- a/linter/test_rules/rule118.ts.autofix.json +++ b/linter/test_rules/rule118.ts.autofix.json @@ -1,19 +1,3 @@ { - "nodes": [ - { - "line": 5, - "column": 12, - "problem": "TypeOnlyImport", - "autofixable": true, - "autofix": [ - { - "start": 120, - "end": 144, - "replacementText": "{ APIResponseType }" - } - ], - "suggest": "", - "rule": "Special import type declarations are not supported (arkts-no-special-imports)" - } - ] + "nodes": [] } \ No newline at end of file diff --git a/linter/test_rules/rule118.ts.strict.json b/linter/test_rules/rule118.ts.strict.json index d30836a74acd706fd8fe37f455f2cb38b9d30f96..13f13363f579325755e8954b4011963971667481 100644 --- a/linter/test_rules/rule118.ts.strict.json +++ b/linter/test_rules/rule118.ts.strict.json @@ -1,11 +1,3 @@ { - "nodes": [ - { - "line": 5, - "column": 12, - "problem": "TypeOnlyImport", - "suggest": "", - "rule": "Special import type declarations are not supported (arkts-no-special-imports)" - } - ] + "nodes": [] } \ No newline at end of file diff --git a/linter/test_rules/rule127.ts.autofix.json b/linter/test_rules/rule127.ts.autofix.json index c32c0f461dd55626cd83972b7aa2a8d7bff66f60..13f13363f579325755e8954b4011963971667481 100644 --- a/linter/test_rules/rule127.ts.autofix.json +++ b/linter/test_rules/rule127.ts.autofix.json @@ -1,19 +1,3 @@ { - "nodes": [ - { - "line": 12, - "column": 5, - "problem": "TypeOnlyExport", - "autofixable": true, - "autofix": [ - { - "start": 218, - "end": 240, - "replacementText": "export { Class2 };" - } - ], - "suggest": "", - "rule": "Special \"export type\" declarations are not supported (arkts-no-special-exports)" - } - ] + "nodes": [] } \ No newline at end of file diff --git a/linter/test_rules/rule127.ts.strict.json b/linter/test_rules/rule127.ts.strict.json index 35f1a58896b2262887e713eb7ea091a5342d8b98..13f13363f579325755e8954b4011963971667481 100644 --- a/linter/test_rules/rule127.ts.strict.json +++ b/linter/test_rules/rule127.ts.strict.json @@ -1,11 +1,3 @@ { - "nodes": [ - { - "line": 12, - "column": 5, - "problem": "TypeOnlyExport", - "suggest": "", - "rule": "Special \"export type\" declarations are not supported (arkts-no-special-exports)" - } - ] + "nodes": [] } \ No newline at end of file diff --git a/linter/test_rules/rule129.ts.autofix.json b/linter/test_rules/rule129.ts.autofix.json index 6708658aec6699b02802c0afa208ab7c076c39a4..80fc9c4b1fa0b7d2af2c6a19111f4c1a8102ef3d 100644 --- a/linter/test_rules/rule129.ts.autofix.json +++ b/linter/test_rules/rule129.ts.autofix.json @@ -6,7 +6,7 @@ "problem": "NonDeclarationInNamespace", "autofixable": false, "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 2, diff --git a/linter/test_rules/rule129.ts.relax.json b/linter/test_rules/rule129.ts.relax.json index cc882319377db9e73f996ceb24a77cc508180fdd..ab877e8e921e03d48ab1603fd2146e3f4fe9557f 100644 --- a/linter/test_rules/rule129.ts.relax.json +++ b/linter/test_rules/rule129.ts.relax.json @@ -5,7 +5,7 @@ "column": 9, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 2, diff --git a/linter/test_rules/rule129.ts.strict.json b/linter/test_rules/rule129.ts.strict.json index cc882319377db9e73f996ceb24a77cc508180fdd..ab877e8e921e03d48ab1603fd2146e3f4fe9557f 100644 --- a/linter/test_rules/rule129.ts.strict.json +++ b/linter/test_rules/rule129.ts.strict.json @@ -5,7 +5,7 @@ "column": 9, "problem": "NonDeclarationInNamespace", "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statement) (arkts-no-ns-statements)" }, { "line": 2, diff --git a/linter/test_rules/rule132.ts.autofix.json b/linter/test_rules/rule132.ts.autofix.json index d1868ca7f895576a790a872e83c05b3f7b619086..9002b4276ade0505b91332d17e0d7c64608c6e8f 100644 --- a/linter/test_rules/rule132.ts.autofix.json +++ b/linter/test_rules/rule132.ts.autofix.json @@ -2,7 +2,7 @@ "nodes": [ { "line": 7, - "column": 16, + "column": 9, "problem": "LimitedStdLibApi", "autofixable": false, "suggest": "", diff --git a/linter/test_rules/rule132.ts.relax.json b/linter/test_rules/rule132.ts.relax.json index 21468ce90773221bb8d0e37917a8f9a5eb974223..192c3aa101f830da08961e07bd44fabed0c97d54 100644 --- a/linter/test_rules/rule132.ts.relax.json +++ b/linter/test_rules/rule132.ts.relax.json @@ -2,7 +2,7 @@ "nodes": [ { "line": 7, - "column": 16, + "column": 9, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" diff --git a/linter/test_rules/rule132.ts.strict.json b/linter/test_rules/rule132.ts.strict.json index 21468ce90773221bb8d0e37917a8f9a5eb974223..192c3aa101f830da08961e07bd44fabed0c97d54 100644 --- a/linter/test_rules/rule132.ts.strict.json +++ b/linter/test_rules/rule132.ts.strict.json @@ -2,7 +2,7 @@ "nodes": [ { "line": 7, - "column": 16, + "column": 9, "problem": "LimitedStdLibApi", "suggest": "", "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" diff --git a/linter/webpack.config.js b/linter/webpack.config.js index 51cb261b5f215cffdc71b767298c77a62ba14a4a..d13a33d32f7bc53962c55802949587980ec395cd 100644 --- a/linter/webpack.config.js +++ b/linter/webpack.config.js @@ -1,15 +1,13 @@ -let path = require('path'); - module.exports = { - mode: "development", - target: "node", - entry: './build/src/main.js', - externalsType: 'commonjs', - externals: { - typescript: "typescript", - log4js: "log4js" - }, - output: { - filename: "tslinter.js" - } -} + mode: 'development', + target: 'node', + entry: './build/src/main.js', + externalsType: 'commonjs', + externals: { + typescript: 'typescript', + log4js: 'log4js', + }, + output: { + filename: 'tslinter.js', + }, +};