From 6ef3e81973fde0d4cf15764e1bcb90b6f026b1d8 Mon Sep 17 00:00:00 2001 From: Orlovsky Maxim Date: Tue, 5 Sep 2023 11:23:06 +0300 Subject: [PATCH] [linter] Removed already covered/excessive recipes from linter. Also removed relevant FaultID entries and their respective tests. Signed-off-by: Orlovsky Maxim --- linter-4.2/docs/rules/recipe109.md | 68 ---------- linter-4.2/docs/rules/recipe31.md | 84 ------------ linter-4.2/docs/rules/recipe32.md | 88 ------------ linter-4.2/docs/rules/recipe35.md | 103 -------------- linter-4.2/docs/rules/recipe52.md | 59 -------- linter-4.2/docs/rules/recipe63.md | 67 --------- linter-4.2/docs/rules/recipe76.md | 37 ----- linter-4.2/docs/rules/recipe81.md | 18 --- linter-4.2/docs/rules/recipe85.md | 57 -------- linter-4.2/docs/rules/recipe86.md | 49 ------- linter-4.2/src/Problems.ts | 10 +- linter-4.2/src/TypeScriptLinter.ts | 27 ---- linter-4.2/src/TypeScriptLinterConfig.ts | 6 +- linter-4.2/test/binary_wrong_types.ts | 115 ---------------- .../test/binary_wrong_types.ts.autofix.skip | 0 .../test/binary_wrong_types.ts.relax.json | 81 ----------- .../test/binary_wrong_types.ts.strict.json | 81 ----------- linter-4.2/test/switch_statements.ts | 127 ------------------ .../test/switch_statements.ts.autofix.skip | 0 .../test/switch_statements.ts.relax.json | 93 ------------- .../test/switch_statements.ts.strict.json | 93 ------------- linter/docs/rules/recipe109.md | 68 ---------- linter/docs/rules/recipe31.md | 84 ------------ linter/docs/rules/recipe32.md | 88 ------------ linter/docs/rules/recipe35.md | 103 -------------- linter/docs/rules/recipe52.md | 59 -------- linter/docs/rules/recipe63.md | 67 --------- linter/docs/rules/recipe76.md | 37 ----- linter/docs/rules/recipe81.md | 18 --- linter/docs/rules/recipe85.md | 57 -------- linter/docs/rules/recipe86.md | 49 ------- linter/src/FaultAttrs.ts | 4 - linter/src/FaultDesc.ts | 4 - linter/src/Problems.ts | 6 +- linter/src/TypeScriptLinter.ts | 43 ------ linter/src/TypeScriptLinterConfig.ts | 2 +- linter/test/binary_wrong_types.ts.relax.json | 28 ---- linter/test/binary_wrong_types.ts.strict.json | 28 ---- linter/test/switch_statements.ts | 127 ------------------ linter/test/switch_statements.ts.autofix.skip | 0 linter/test/switch_statements.ts.relax.json | 93 ------------- linter/test/switch_statements.ts.strict.json | 93 ------------- linter/test_rules/rule22.ts.autofix.json | 10 +- linter/test_rules/rule22.ts.relax.json | 9 +- linter/test_rules/rule22.ts.strict.json | 9 +- linter/test_rules/rule63.ts.autofix.json | 26 +--- linter/test_rules/rule63.ts.relax.json | 23 +--- linter/test_rules/rule63.ts.strict.json | 23 +--- linter/test_rules/rule85.ts | 30 ----- linter/test_rules/rule85.ts.autofix.json | 12 -- linter/test_rules/rule85.ts.relax.json | 11 -- linter/test_rules/rule85.ts.strict.json | 11 -- linter/test_rules/rule86.ts | 15 --- linter/test_rules/rule86.ts.autofix.json | 20 --- linter/test_rules/rule86.ts.relax.json | 18 --- linter/test_rules/rule86.ts.strict.json | 18 --- 56 files changed, 14 insertions(+), 2542 deletions(-) delete mode 100644 linter-4.2/docs/rules/recipe109.md delete mode 100644 linter-4.2/docs/rules/recipe31.md delete mode 100644 linter-4.2/docs/rules/recipe32.md delete mode 100644 linter-4.2/docs/rules/recipe35.md delete mode 100644 linter-4.2/docs/rules/recipe52.md delete mode 100644 linter-4.2/docs/rules/recipe63.md delete mode 100644 linter-4.2/docs/rules/recipe76.md delete mode 100644 linter-4.2/docs/rules/recipe81.md delete mode 100644 linter-4.2/docs/rules/recipe85.md delete mode 100644 linter-4.2/docs/rules/recipe86.md delete mode 100644 linter-4.2/test/binary_wrong_types.ts delete mode 100644 linter-4.2/test/binary_wrong_types.ts.autofix.skip delete mode 100644 linter-4.2/test/binary_wrong_types.ts.relax.json delete mode 100644 linter-4.2/test/binary_wrong_types.ts.strict.json delete mode 100644 linter-4.2/test/switch_statements.ts delete mode 100644 linter-4.2/test/switch_statements.ts.autofix.skip delete mode 100644 linter-4.2/test/switch_statements.ts.relax.json delete mode 100644 linter-4.2/test/switch_statements.ts.strict.json delete mode 100644 linter/docs/rules/recipe109.md delete mode 100644 linter/docs/rules/recipe31.md delete mode 100644 linter/docs/rules/recipe32.md delete mode 100644 linter/docs/rules/recipe35.md delete mode 100644 linter/docs/rules/recipe52.md delete mode 100644 linter/docs/rules/recipe63.md delete mode 100644 linter/docs/rules/recipe76.md delete mode 100644 linter/docs/rules/recipe81.md delete mode 100644 linter/docs/rules/recipe85.md delete mode 100644 linter/docs/rules/recipe86.md delete mode 100644 linter/test/switch_statements.ts delete mode 100644 linter/test/switch_statements.ts.autofix.skip delete mode 100644 linter/test/switch_statements.ts.relax.json delete mode 100644 linter/test/switch_statements.ts.strict.json delete mode 100644 linter/test_rules/rule85.ts delete mode 100644 linter/test_rules/rule85.ts.autofix.json delete mode 100644 linter/test_rules/rule85.ts.relax.json delete mode 100644 linter/test_rules/rule85.ts.strict.json delete mode 100644 linter/test_rules/rule86.ts delete mode 100644 linter/test_rules/rule86.ts.autofix.json delete mode 100644 linter/test_rules/rule86.ts.relax.json delete mode 100644 linter/test_rules/rule86.ts.strict.json diff --git a/linter-4.2/docs/rules/recipe109.md b/linter-4.2/docs/rules/recipe109.md deleted file mode 100644 index df205d6b4..000000000 --- a/linter-4.2/docs/rules/recipe109.md +++ /dev/null @@ -1,68 +0,0 @@ -# Dynamic property declaration is not supported - -Rule ``arkts-no-dyn-prop-decl`` - -**Severity: error** - -ArkTS does not support dynamic property declaration. Declare all object -properties immediately in the class. While replacement for an array of -objects is possible, it is still better to adhere to the static language -paradigm, and declare fields, their names and types explicitly. - - -## TypeScript - - -``` - - class Person { - name: string = "" - age: number = 0; // semicolon is required here - [key: string]: string | number - } - - let person: Person = { - name: "John", - age: 30, - email: "***@example.com", - phoneNumber: "18*********", - } - -``` - -## ArkTS - - -``` - - class Person { - name: string - age: number - email: string - phoneNumber: string - - constructor(name: string, age: number, email: string, - phoneNumber: string) { - this.name = name - this.age = age - this.email = email - this.phoneNumber = phoneNumber - } - } - - let person = new Person("John", 30, "***@example.com", "18*********") - -``` - -## See also - -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-identifiers-as-prop-names``) -- Recipe 002: ``Symbol()`` API is not supported (``arkts-no-symbol``) -- Recipe 052: Attempt to access an undefined property is a compile-time error (``arkts-no-undefined-prop-access``) -- Recipe 059: ``delete`` operator is not supported (``arkts-no-delete``) -- Recipe 060: ``typeof`` operator is allowed only in expression contexts (``arkts-no-type-query``) -- Recipe 066: ``in`` operator is not supported (``arkts-no-in``) -- Recipe 105: Property-based runtime type checks are not supported (``arkts-no-prop-existence-check``) -- Recipe 144: Usage of standard library is restricted (``arkts-limited-stdlib``) - - diff --git a/linter-4.2/docs/rules/recipe31.md b/linter-4.2/docs/rules/recipe31.md deleted file mode 100644 index d2eef94fb..000000000 --- a/linter-4.2/docs/rules/recipe31.md +++ /dev/null @@ -1,84 +0,0 @@ -# Structural typing is not supported for subtyping / supertyping - -Rule ``arkts-no-structural-subtyping`` - -**Severity: error** - -Currently, ArkTS does not check structural equivalence for type inference, -i.e., the compiler cannot compare public APIs of two types and decide whether -such types are identical. Use other mechanisms (inheritance or interfaces) -instead. - - -## TypeScript - - -``` - - class X { - public foo: number - - constructor() { - this.foo = 0 - } - } - - class Y { - public foo: number - - constructor() { - this.foo = 0 - } - } - - let x = new X() - let y = new Y() - - console.log("Assign X to Y") - y = x - - console.log("Assign Y to X") - x = y - - -``` - -## ArkTS - - -``` - - class X { - public foo: number - - constructor() { - this.foo = 0 - } - } - - // Y is derived from X, which explicitly set subtype / supertype relations: - class Y extends X { - constructor() { - super() - } - } - - let x = new X() - let y = new Y() - - console.log("Assign Y to X") - x = y // ok, X is the super class of Y - - // Cannot assign X to Y - //y = x - compile-time error - - -``` - -## See also - -- Recipe 030: Structural identity is not supported (``arkts-no-structural-identity``) -- Recipe 032: Structural typing is not supported for assignability checks (``arkts-no-structural-assignability``) -- Recipe 035: Structural typing is not supported for type inference (``arkts-no-structural-inference``) - - diff --git a/linter-4.2/docs/rules/recipe32.md b/linter-4.2/docs/rules/recipe32.md deleted file mode 100644 index cc7e41628..000000000 --- a/linter-4.2/docs/rules/recipe32.md +++ /dev/null @@ -1,88 +0,0 @@ -# Structural typing is not supported for assignability checks - -Rule ``arkts-no-structural-assignability`` - -**Severity: error** - -Currently, ArkTS does not check structural equivalence when checking if types -are assignable to each other, i.e., the compiler cannot compare public APIs of -two types and decide whether such types are identical. Use other mechanisms -(inheritance or interfaces) instead. - - -## TypeScript - - -``` - - class X { - public foo: number - - constructor() { - this.foo = 0 - } - } - - class Y { - public foo: number - constructor() { - this.foo = 0 - } - } - - let x = new X() - let y = new Y() - - console.log("Assign X to Y") - y = x - - console.log("Assign Y to X") - x = y - -``` - -## ArkTS - - -``` - - interface Z { - foo: number - } - - // X implements interface Z, which makes relation between X and Y explicit. - class X implements Z { - public foo: number - - constructor() { - this.foo = 0 - } - } - - // Y implements interface Z, which makes relation between X and Y explicit. - class Y implements Z { - public foo: number - - constructor() { - this.foo = 0 - } - } - - let x: Z = new X() - let y: Z = new Y() - - console.log("Assign X to Y") - y = x // ok, both are of the same type - - console.log("Assign Y to X") - x = y // ok, both are of the same type - -``` - -## See also - -- Recipe 030: Structural identity is not supported (``arkts-no-structural-identity``) -- Recipe 031: Structural typing is not supported for subtyping / supertyping (``arkts-no-structural-subtyping``) -- Recipe 035: Structural typing is not supported for type inference (``arkts-no-structural-inference``) - - diff --git a/linter-4.2/docs/rules/recipe35.md b/linter-4.2/docs/rules/recipe35.md deleted file mode 100644 index 9645463e7..000000000 --- a/linter-4.2/docs/rules/recipe35.md +++ /dev/null @@ -1,103 +0,0 @@ -# Structural typing is not supported for type inference - -Rule ``arkts-no-structural-inference`` - -**Severity: error** - -Currently, ArkTS does not support structural typing, i.e., the compiler cannot -compare public APIs of two types and decide whether such types are identical. -Use inheritance and interfaces to specify the relation between the types -explicitly. - - -## TypeScript - - -``` - - class X { - public foo: number - private s: string - - constructor (f: number) { - this.foo = f - this.s = "" - } - - public say(): void { - console.log("X = ", this.foo) - } - } - - class Y { - public foo: number - - constructor (f: number) { - this.foo = f - } - public say(): void { - console.log("Y = ", this.foo) - } - } - - function bar(z: X): void { - z.say() - } - - // X and Y are equivalent because their public API is equivalent. - // Thus the second call is allowed: - bar(new X(1)) - bar(new Y(2) as X) - -``` - -## ArkTS - - -``` - - interface Z { - say(): void - } - - class X implements Z { - public foo: number - private s: string - - constructor (f: number) { - this.foo = f - this.s = "" - } - public say(): void { - console.log("X = ", this.foo) - } - } - - class Y implements Z { - public foo: number - - constructor (f: number) { - this.foo = f - } - public say(): void { - console.log("Y = ", this.foo) - } - } - - function bar(z: Z): void { - z.say() - } - - // X and Y implement the same interface Z, thus both calls are allowed: - bar(new X(1)) - bar(new Y(2)) - -``` - -## See also - -- Recipe 030: Structural identity is not supported (``arkts-no-structural-identity``) -- Recipe 031: Structural typing is not supported for subtyping / supertyping (``arkts-no-structural-subtyping``) -- Recipe 032: Structural typing is not supported for assignability checks (``arkts-no-structural-assignability``) - - diff --git a/linter-4.2/docs/rules/recipe52.md b/linter-4.2/docs/rules/recipe52.md deleted file mode 100644 index fd7e53ae8..000000000 --- a/linter-4.2/docs/rules/recipe52.md +++ /dev/null @@ -1,59 +0,0 @@ -# Attempt to access an undefined property is a compile-time error - -Rule ``arkts-no-undefined-prop-access`` - -**Severity: error** - -ArkTS supports accessing only those class properties that are either declared -in the class, or accessible via inheritance. Accessing any other properties is -prohibited, and causes compile-time errors. Use proper types to check property -existence during compilation. - - -## TypeScript - - -``` - - let person = {name: "Bob", isEmployee: true} - - let n = person["name"] - let e = person["isEmployee"] - let s = person["office"] // Compile-time error only with noImplicitAny - -``` - -## ArkTS - - -``` - - class Person { - constructor(name: string, isEmployee: boolean) { - this.name = name - this.isEmployee = isEmployee - } - - name: string - isEmployee: boolean - } - - let person = new Person("Bob", true) - let n = person.name - let e = person.isEmployee - let s = person.office // Compile-time error - -``` - -## See also - -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-identifiers-as-prop-names``) -- Recipe 002: ``Symbol()`` API is not supported (``arkts-no-symbol``) -- Recipe 059: ``delete`` operator is not supported (``arkts-no-delete``) -- Recipe 060: ``typeof`` operator is allowed only in expression contexts (``arkts-no-type-query``) -- Recipe 066: ``in`` operator is not supported (``arkts-no-in``) -- Recipe 105: Property-based runtime type checks are not supported (``arkts-no-prop-existence-check``) -- Recipe 109: Dynamic property declaration is not supported (``arkts-no-dyn-prop-decl``) -- Recipe 144: Usage of standard library is restricted (``arkts-limited-stdlib``) - - diff --git a/linter-4.2/docs/rules/recipe63.md b/linter-4.2/docs/rules/recipe63.md deleted file mode 100644 index 1b9bca2fd..000000000 --- a/linter-4.2/docs/rules/recipe63.md +++ /dev/null @@ -1,67 +0,0 @@ -# Binary ``+`` operator supports implicit casts only for numbers, enums and strings - -Rule ``arkts-no-polymorphic-plus`` - -**Severity: error** - -If one of the operands of the binary ``+`` operator is of the string type -(including enum string constant), then the other operand can be of any type, -and its value is implicitly converted to string. -Otherwise, ArkTS supports implicit casts with ``+`` only for numbers and -numeric enum constants. -ArkTS, like TypeScript, does not support the operator ``+`` for the booleans. -Elsewhere, any form of an explicit cast is required. - - -## TypeScript - - -``` - - enum E { E1, E2 } - - let a = 10 + 32 // 42 - let b = E.E1 + 10 // 10 - let c = 10 + "5" // "105" - - let d = "5" + E.E2 // "51" - let e = "Hello, " + "world!" // "Hello, world!" - let f = "string" + true // "stringtrue" - - let g = (new Object()) + "string" // "[object Object]string" - - let i = true + true // Compile-time error - let j = true + 2 // Compile-time error - let k = E.E1 + true // Compile-time error - -``` - -## ArkTS - - -``` - - enum E { E1, E2 } - - let a = 10 + 32 // 42 - let b = E.E1 + 10 // 10 - let c = 10 + "5" // "105" - - let d = "5" + E.E2 // "51" - let e = "Hello, " + "world!" // "Hello, world!" - let f = "string" + true // "stringtrue" - - let g = (new Object()).toString() + "string" - - let i = true + true // Compile-time error - let j = true + 2 // Compile-time error - let k = E.E1 + true // Compile-time error - -``` - -## See also - -- Recipe 055: Unary operators ``+``, ``-`` and ``~`` work only on numbers (``arkts-no-polymorphic-unops``) - - - diff --git a/linter-4.2/docs/rules/recipe76.md b/linter-4.2/docs/rules/recipe76.md deleted file mode 100644 index e620ace6b..000000000 --- a/linter-4.2/docs/rules/recipe76.md +++ /dev/null @@ -1,37 +0,0 @@ -# Inference of implied types is not supported - -Rule ``arkts-no-implied-inference`` - -**Severity: error** - -Currently, ArkTS does not support inference of implied types. -Use explicit type notation instead. -Use ``Object[]`` if you need containers that hold data of mixed types. - - -## TypeScript - - -``` - - let [a, b, c] = [1, "hello", true] - -``` - -## ArkTS - - -``` - - let a = 1 - let b = "hello" - let c = true - - let arr: Object[] = [1, "hello", true] - let a1 = arr[0] - let b1 = arr[1] - let c1 = arr[2] - -``` - - diff --git a/linter-4.2/docs/rules/recipe81.md b/linter-4.2/docs/rules/recipe81.md deleted file mode 100644 index 541ab965a..000000000 --- a/linter-4.2/docs/rules/recipe81.md +++ /dev/null @@ -1,18 +0,0 @@ -# Iterable interfaces are not supported - -Rule ``arkts-no-iterable`` - -**Severity: error** - -ArkTS does not support the ``Symbol`` API, ``Symbol.iterator`` and -eventually iterable interfaces. Use arrays and library-level containers to -iterate over data. - - -## See also - -- Recipe 002: ``Symbol()`` API is not supported (``arkts-no-symbol``) -- Recipe 080: ``for .. in`` is not supported (``arkts-no-for-in``) -- Recipe 082: ``for-of`` is supported only for arrays and strings (``arkts-for-of-str-arr``) - - diff --git a/linter-4.2/docs/rules/recipe85.md b/linter-4.2/docs/rules/recipe85.md deleted file mode 100644 index e4ea44798..000000000 --- a/linter-4.2/docs/rules/recipe85.md +++ /dev/null @@ -1,57 +0,0 @@ -# Values computed at runtime are not supported in ``case`` statements - -Rule ``arkts-no-computed-case`` - -**Severity: error** - -ArkTS supports ``case`` statements that contain only compile-time values, -top-level scope ``const`` values, and ``static readonly`` class fields. -Use ``if`` statements as an alternative. - - -## TypeScript - - -``` - - let x = 2 - let y = 3 - switch (x) { - case 1: - console.log(1) - break - case 2: - console.log(2) - break - case y: - console.log(y) - break - default: - console.log("other") - } - -``` - -## ArkTS - - -``` - - let x = 2 - switch (x) { - case 1: - console.log(1) - break - case 2: - console.log(2) - break - case 3: - console.log(3) - break - default: - console.log("other") - } - -``` - - diff --git a/linter-4.2/docs/rules/recipe86.md b/linter-4.2/docs/rules/recipe86.md deleted file mode 100644 index 9daf45688..000000000 --- a/linter-4.2/docs/rules/recipe86.md +++ /dev/null @@ -1,49 +0,0 @@ -# ``switch`` statements cannot accept values of arbitrary types - -Rule ``arkts-limited-switch`` - -**Severity: error** - -ArkTS restricts the types that are supported in ``switch`` statements. In -particular, values of the types ``number``, ``Number``, ``string``, ``String`` -or ``enum`` are supported. Use ``if`` statements in case of unsupported types. - - -## TypeScript - - -``` - - class Point { - x: number = 0 - y: number = 0 - } - - let a = new Point() - - switch (a) { - case null: break - default: console.log("not null") - } - -``` - -## ArkTS - - -``` - - class Point { - x: number = 0 - y: number = 0 - } - - let a = new Point() - - if (a != null) { - console.log("not null") - } - -``` - - diff --git a/linter-4.2/src/Problems.ts b/linter-4.2/src/Problems.ts index 9a1bcd8fc..f41064837 100644 --- a/linter-4.2/src/Problems.ts +++ b/linter-4.2/src/Problems.ts @@ -19,14 +19,14 @@ export enum FaultID { DestructuringParameter, YieldExpression, InterfaceMerging, EnumMerging, InterfaceExtendsClass, IndexMember, WithStatement, ThrowStatement, IndexedAccessType, UnknownType, ForInStatement, InOperator, KeyOfOperator, ImportFromPath, FunctionExpression, IntersectionType, - ObjectTypeLiteral, AddWithWrongType, CommaOperator, LimitedReturnTypeInference, + ObjectTypeLiteral, CommaOperator, LimitedReturnTypeInference, LambdaWithTypeParameters, ClassExpression, DestructuringAssignment, DestructuringDeclaration, ForOfNonArray, VarDeclaration, CatchWithUnsupportedType, DeleteOperator, DeclWithDuplicateName, UnaryArithmNotNumber, ConstructorType, ConstructorIface, ConstructorFuncs, CallSignature, TypeAssertion, PrivateIdentifier, LocalFunction, - SwitchSelectorInvalidType, CaseExpressionNonConst, ConditionalType, MappedType, NamespaceAsObject, ClassAsObject, + ConditionalType, MappedType, NamespaceAsObject, ClassAsObject, NonDeclarationInNamespace, GeneratorFunction, FunctionContainsThis, PropertyAccessByIndex, JsxElement, - EnumMemberNonConstInit, ImplementsClass, MultipleStaticBlocks, ThisType, InferType, + EnumMemberNonConstInit, ImplementsClass, MultipleStaticBlocks, ThisType, IntefaceExtendDifProps, StructuralIdentity, TypeOnlyImport, TypeOnlyExport, DefaultImport, LimitedReExporting, ExportAssignment, ImportAssignment, PropertyRuntimeCheck, GenericCallNoTypeArgs, ParameterProperties, @@ -82,20 +82,16 @@ faultsAttrs[FaultID.UnaryArithmNotNumber] = {cookBookRef: '55',}; faultsAttrs[FaultID.DeleteOperator] = {cookBookRef: '59',}; faultsAttrs[FaultID.TypeQuery] = {cookBookRef: '60',}; // remove as rule#61: FaultID.BitOpWithWrongType => {cookBookRef: '61',}; -faultsAttrs[FaultID.AddWithWrongType] = {cookBookRef: '63',}; faultsAttrs[FaultID.InstanceofUnsupported] = {cookBookRef: '65',}; faultsAttrs[FaultID.InOperator] = {cookBookRef: '66',}; faultsAttrs[FaultID.DestructuringAssignment] = {migratable: true, cookBookRef: '69',}; faultsAttrs[FaultID.CommaOperator] = {cookBookRef: '71',}; faultsAttrs[FaultID.DestructuringDeclaration] = {migratable: true, cookBookRef: '74',}; -faultsAttrs[FaultID.InferType] = {cookBookRef: '76',}; faultsAttrs[FaultID.CatchWithUnsupportedType] = {migratable: true, cookBookRef: '79',}; faultsAttrs[FaultID.ForInStatement] = {cookBookRef: '80',}; faultsAttrs[FaultID.ForOfNonArray] = {migratable: true, cookBookRef: '82',}; faultsAttrs[FaultID.MappedType] = {cookBookRef: '83',}; faultsAttrs[FaultID.WithStatement] = {cookBookRef: '84',}; -faultsAttrs[FaultID.CaseExpressionNonConst] = {cookBookRef: '85',}; -faultsAttrs[FaultID.SwitchSelectorInvalidType] = {cookBookRef: '86',}; faultsAttrs[FaultID.ThrowStatement] = {migratable: true, cookBookRef: '87',}; faultsAttrs[FaultID.LimitedReturnTypeInference] = {migratable: true, cookBookRef: '90',}; faultsAttrs[FaultID.DestructuringParameter] = {cookBookRef: '91',}; diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index d7622bcc4..b236758a4 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -1162,7 +1162,6 @@ export class TypeScriptLinter { rightOperandType.getFlags() & ts.TypeFlags.StringLike) ) return; - else this.incrementCounters(node, FaultID.AddWithWrongType); } else if ( this.tsUtils.isNumberType(leftOperandType) && this.tsUtils.isNumberType(rightOperandType) @@ -1173,7 +1172,6 @@ export class TypeScriptLinter { this.tsUtils.isStringLikeType(rightOperandType) ) return; - else this.incrementCounters(node, FaultID.AddWithWrongType); } else if ( tsBinaryExpr.operatorToken.kind === ts.SyntaxKind.AmpersandToken || tsBinaryExpr.operatorToken.kind === ts.SyntaxKind.BarToken || @@ -1518,23 +1516,9 @@ export class TypeScriptLinter { private handleSwitchStatement(node: ts.Node) { let tsSwitchStmt = node as ts.SwitchStatement; - let tsSwitchExprType = this.tsTypeChecker.getTypeAtLocation( - tsSwitchStmt.expression - ); - const isSwitchableNumeric = (type: ts.Type) => { - return !!(type.getFlags() & ts.TypeFlags.NumberLike); - } - const isSwitchableString = (type: ts.Type) => { - return !!(type.getFlags() & ts.TypeFlags.StringLike); - } - if (!this.tsUtils.checkTypeSet(tsSwitchExprType, isSwitchableNumeric) && - !this.tsUtils.checkTypeSet(tsSwitchExprType, isSwitchableString)) { - this.incrementCounters(tsSwitchStmt.expression, FaultID.SwitchSelectorInvalidType); - } for (const tsCaseClause of tsSwitchStmt.caseBlock.clauses) { if (ts.isCaseClause(tsCaseClause)) { const tsCaseExpr = tsCaseClause.expression; - const tsCaseExprType = this.tsTypeChecker.getTypeAtLocation(tsCaseExpr); const tsCaseSym = this.tsTypeChecker.getSymbolAtLocation(tsCaseExpr); let isConstOrStaticReadonlyField: boolean = false; @@ -1570,17 +1554,6 @@ export class TypeScriptLinter { : isConstOrStaticReadonlyField; } } - - if ( - !( - isConstOrStaticReadonlyField || - ts.isNumericLiteral(tsCaseExpr) || - ts.isStringLiteralLike(tsCaseExpr) || - tsCaseExprType.flags & ts.TypeFlags.EnumLike - ) - ) { - this.incrementCounters(tsCaseExpr, FaultID.CaseExpressionNonConst); - } } } } diff --git a/linter-4.2/src/TypeScriptLinterConfig.ts b/linter-4.2/src/TypeScriptLinterConfig.ts index 9482de3dd..217f9440d 100644 --- a/linter-4.2/src/TypeScriptLinterConfig.ts +++ b/linter-4.2/src/TypeScriptLinterConfig.ts @@ -60,7 +60,6 @@ export class LinterConfig { LinterConfig.nodeDesc[FaultID.FunctionExpression] = 'function expressions'; LinterConfig.nodeDesc[FaultID.IntersectionType] = 'intersection types and type literals'; LinterConfig.nodeDesc[FaultID.ObjectTypeLiteral] = 'Object type literals'; - LinterConfig.nodeDesc[FaultID.AddWithWrongType] = 'binary "+" with wrong operand'; // LinterConfig.nodeDesc[FaultID.BitOpWithWrongType] = 'bit operation with wrong operand'; LinterConfig.nodeDesc[FaultID.CommaOperator] = 'comma operator'; LinterConfig.nodeDesc[FaultID.LimitedReturnTypeInference] = 'Functions with limited return type inference'; @@ -81,8 +80,6 @@ export class LinterConfig { LinterConfig.nodeDesc[FaultID.TypeAssertion] = 'Type assertion expressions'; LinterConfig.nodeDesc[FaultID.PrivateIdentifier] = 'Private identifiers (with "#" prefix)'; LinterConfig.nodeDesc[FaultID.LocalFunction] = 'Local function declarations'; - LinterConfig.nodeDesc[FaultID.SwitchSelectorInvalidType] ='Switch selectors with invalid type'; - LinterConfig.nodeDesc[FaultID.CaseExpressionNonConst] = '"case" clause with non-constant expression'; LinterConfig.nodeDesc[FaultID.ConditionalType] = 'Conditional type'; LinterConfig.nodeDesc[FaultID.MappedType] = 'Mapped type'; LinterConfig.nodeDesc[FaultID.NamespaceAsObject] = 'Namespaces used as objects'; @@ -96,7 +93,6 @@ export class LinterConfig { LinterConfig.nodeDesc[FaultID.ImplementsClass] = 'Class type mentioned in "implements" clause'; LinterConfig.nodeDesc[FaultID.MultipleStaticBlocks] = 'Multiple static blocks'; LinterConfig.nodeDesc[FaultID.ThisType] = '"this" type'; - LinterConfig.nodeDesc[FaultID.InferType] = 'Infer 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'; @@ -177,7 +173,7 @@ export class LinterConfig { // 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.ThisType, FaultID.ThisType], [ts.SyntaxKind.InferType, FaultID.InferType], + [ts.SyntaxKind.ThisType, FaultID.ThisType], [ts.SyntaxKind.TupleType, FaultID.TupleType], [ts.SyntaxKind.ComputedPropertyName, FaultID.ComputedPropertyName], [ts.SyntaxKind.TypeQuery, FaultID.TypeQuery], [ts.SyntaxKind.DeleteExpression, FaultID.DeleteOperator], diff --git a/linter-4.2/test/binary_wrong_types.ts b/linter-4.2/test/binary_wrong_types.ts deleted file mode 100644 index d34dc7b1c..000000000 --- a/linter-4.2/test/binary_wrong_types.ts +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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. - */ - -function gets(): string { - return 'ss'; -} - -const b0 = true; - -const c0 = b0 && true; -const c1 = true && '3'; -const c2 = gets() && false; -const c3 = 5 && 6; - -const d0 = false || b0; -const d1 = ~'3' || true; -const d2 = false || gets(); -const d3 = 4 || 5; - -console.log(c1); -console.log(c2); -console.log(c3); -console.log(d1); -console.log(d2); -console.log(d3); - -const varAny: any = null; - -const add0 = 2 + 2; -const add1 = '2' + '2'; -const add2 = '2' + varAny; -const add3 = varAny + '2'; -const add4 = varAny + 2; -const add5 = 6 + varAny; -const add6 = '2' + 2; -const add7 = 2 + '2'; - -enum Const { - PI = 3.14, - E = 2.7818, -} -enum State { - OK = 'ok', - FAULT = 'fail', -} - -const b1 = 7 ^ varAny; -const b2 = 7 | varAny; -const b3 = 7 & varAny; - -const b4 = 7 << varAny; -const b5 = 7 >> varAny; -const b6 = 7 >>> varAny; - -const b7 = varAny << 1; -const b8 = varAny >> 2; -const b9 = varAny >>> 3; - -const b11 = 7 ^ Const.PI; -const b12 = 7 | Const.E; -const b13 = 7 & Const.PI; - -const b14 = 7 << Const.PI; -const b15 = 7 >> Const.E; -const b16 = 7 >>> Const.PI; - -const b17 = Const.PI << 1; -const b18 = Const.E >> 2; -const b19 = Const.PI >>> 3; - -const b31 = State.OK ^ 7; -const b32 = 7 | State.FAULT; -const b33 = 7 & State.OK; - -const b34 = 7 << State.OK; -const b35 = 7 >> State.FAULT; -const b36 = 7 >>> State.OK; - -const b37 = State.FAULT << 1; -const b38 = State.OK >> 2; -const b39 = State.FAULT >>> 3; - -const a000 = ((k = 10), 2 + 7); - -function foo(n: number, m: number): number { - return (n/m) + ((n%m) ? 1 : 0); -} - -const b40 = 7 & 5.5; -const b41 = 5.5 & b40; -const b42 = 2 | 5.5; -const b43 = 5.5 | b42; -const b44 = 4 ^ 5.5; -const b45 = 5.5 ^ b44; - - -let e1 = Const.PI + Const.E; // OK -let e2 = State.FAULT + State.OK; // OK -let e3 = "State: " + State.FAULT; // OK -let e4 = "Const = " + Const.PI; // OK - -let f1 = Const.PI + State.FAULT; // Error -let f2 = State.OK + Const.E; // Error diff --git a/linter-4.2/test/binary_wrong_types.ts.autofix.skip b/linter-4.2/test/binary_wrong_types.ts.autofix.skip deleted file mode 100644 index e69de29bb..000000000 diff --git a/linter-4.2/test/binary_wrong_types.ts.relax.json b/linter-4.2/test/binary_wrong_types.ts.relax.json deleted file mode 100644 index 729e4f6ff..000000000 --- a/linter-4.2/test/binary_wrong_types.ts.relax.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "copyright": [ - "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." - ], - "nodes": [ - { - "line": 28, - "column": 12, - "problem": "UnaryArithmNotNumber", - "suggest": "", - "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" - }, - { - "line": 39, - "column": 15, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" - }, - { - "line": 45, - "column": 7, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" - }, - { - "line": 45, - "column": 14, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, - { - "line": 46, - "column": 7, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" - }, - { - "line": 46, - "column": 14, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, - { - "line": 95, - "column": 15, - "problem": "CommaOperator", - "suggest": "", - "rule": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)" - }, - { - "line": 114, - "column": 10, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, - { - "line": 115, - "column": 10, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - } - ] -} diff --git a/linter-4.2/test/binary_wrong_types.ts.strict.json b/linter-4.2/test/binary_wrong_types.ts.strict.json deleted file mode 100644 index 729e4f6ff..000000000 --- a/linter-4.2/test/binary_wrong_types.ts.strict.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "copyright": [ - "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." - ], - "nodes": [ - { - "line": 28, - "column": 12, - "problem": "UnaryArithmNotNumber", - "suggest": "", - "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" - }, - { - "line": 39, - "column": 15, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" - }, - { - "line": 45, - "column": 7, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" - }, - { - "line": 45, - "column": 14, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, - { - "line": 46, - "column": 7, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" - }, - { - "line": 46, - "column": 14, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, - { - "line": 95, - "column": 15, - "problem": "CommaOperator", - "suggest": "", - "rule": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)" - }, - { - "line": 114, - "column": 10, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, - { - "line": 115, - "column": 10, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - } - ] -} diff --git a/linter-4.2/test/switch_statements.ts b/linter-4.2/test/switch_statements.ts deleted file mode 100644 index cef30c267..000000000 --- a/linter-4.2/test/switch_statements.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -interface I { - f: number; -} - -function foo(a: string, b: string, i: I): void { - switch (a) { - case '0': - console.log('0'); - break; - case b: - console.log(b); - break; - } - - switch (i) { - case null: - console.log('null interace'); - break; - } - - switch (undefined) { - case console.log(1): - case console.log(2): - void console.log(3); - } - - const x = 10, - y = 20, - z = 30; - const foo = (n: number) => n; - switch (x) { - case x + y: - console.log('x + y = ' + (x + y)); - break; - case foo(z): - console.log('foo(z) = ' + foo(z)); - break; - default: - console.log('default case'); - } -} - -enum E { - Ea = "a", - Eb = "b" -} - -let a0: string = "234"; -const x0: string = "123"; -const x1 = a0; -const x2 = x0; - -class TestClass { - static readonly y:string = "2"; - readonly z:string = "3"; - - f(s: string) { - const z1 = this.z; - const z2 = s; - - switch (s) { - case E.Ea: - break; - case E.Eb: - break; - case a0: - break; - case x0: - break; - case x1: - break; - case x2: - break; - case TestClass.y: - break; - case this.z: - break; - case z1: - break; - case z2: - break; - case s: - break; - default: - } - } -} - -enum COLORS { Red, Green, Blue }; - -function bar(color: COLORS) { - if (color == COLORS.Blue) { - return 0; - } - switch (color) { - case COLORS.Red: - return 1; - case COLORS.Green: - return 2; - default: - return 3; - } -} - -function car(color: COLORS | 'a') { - switch (color) { - case COLORS.Red: - return 1; - default: - return 3; - } -} diff --git a/linter-4.2/test/switch_statements.ts.autofix.skip b/linter-4.2/test/switch_statements.ts.autofix.skip deleted file mode 100644 index e69de29bb..000000000 diff --git a/linter-4.2/test/switch_statements.ts.relax.json b/linter-4.2/test/switch_statements.ts.relax.json deleted file mode 100644 index ebeb015d4..000000000 --- a/linter-4.2/test/switch_statements.ts.relax.json +++ /dev/null @@ -1,93 +0,0 @@ -{ - "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": 25, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 30, - "column": 11, - "problem": "SwitchSelectorInvalidType" - }, - { - "line": 31, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 36, - "column": 11, - "problem": "SwitchSelectorInvalidType" - }, - { - "line": 37, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 38, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 47, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 50, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 81, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 85, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 91, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 93, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 95, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 97, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 121, - "column": 13, - "problem": "SwitchSelectorInvalidType" - } - ] -} diff --git a/linter-4.2/test/switch_statements.ts.strict.json b/linter-4.2/test/switch_statements.ts.strict.json deleted file mode 100644 index ebeb015d4..000000000 --- a/linter-4.2/test/switch_statements.ts.strict.json +++ /dev/null @@ -1,93 +0,0 @@ -{ - "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": 25, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 30, - "column": 11, - "problem": "SwitchSelectorInvalidType" - }, - { - "line": 31, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 36, - "column": 11, - "problem": "SwitchSelectorInvalidType" - }, - { - "line": 37, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 38, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 47, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 50, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 81, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 85, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 91, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 93, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 95, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 97, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 121, - "column": 13, - "problem": "SwitchSelectorInvalidType" - } - ] -} diff --git a/linter/docs/rules/recipe109.md b/linter/docs/rules/recipe109.md deleted file mode 100644 index df205d6b4..000000000 --- a/linter/docs/rules/recipe109.md +++ /dev/null @@ -1,68 +0,0 @@ -# Dynamic property declaration is not supported - -Rule ``arkts-no-dyn-prop-decl`` - -**Severity: error** - -ArkTS does not support dynamic property declaration. Declare all object -properties immediately in the class. While replacement for an array of -objects is possible, it is still better to adhere to the static language -paradigm, and declare fields, their names and types explicitly. - - -## TypeScript - - -``` - - class Person { - name: string = "" - age: number = 0; // semicolon is required here - [key: string]: string | number - } - - let person: Person = { - name: "John", - age: 30, - email: "***@example.com", - phoneNumber: "18*********", - } - -``` - -## ArkTS - - -``` - - class Person { - name: string - age: number - email: string - phoneNumber: string - - constructor(name: string, age: number, email: string, - phoneNumber: string) { - this.name = name - this.age = age - this.email = email - this.phoneNumber = phoneNumber - } - } - - let person = new Person("John", 30, "***@example.com", "18*********") - -``` - -## See also - -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-identifiers-as-prop-names``) -- Recipe 002: ``Symbol()`` API is not supported (``arkts-no-symbol``) -- Recipe 052: Attempt to access an undefined property is a compile-time error (``arkts-no-undefined-prop-access``) -- Recipe 059: ``delete`` operator is not supported (``arkts-no-delete``) -- Recipe 060: ``typeof`` operator is allowed only in expression contexts (``arkts-no-type-query``) -- Recipe 066: ``in`` operator is not supported (``arkts-no-in``) -- Recipe 105: Property-based runtime type checks are not supported (``arkts-no-prop-existence-check``) -- Recipe 144: Usage of standard library is restricted (``arkts-limited-stdlib``) - - diff --git a/linter/docs/rules/recipe31.md b/linter/docs/rules/recipe31.md deleted file mode 100644 index d2eef94fb..000000000 --- a/linter/docs/rules/recipe31.md +++ /dev/null @@ -1,84 +0,0 @@ -# Structural typing is not supported for subtyping / supertyping - -Rule ``arkts-no-structural-subtyping`` - -**Severity: error** - -Currently, ArkTS does not check structural equivalence for type inference, -i.e., the compiler cannot compare public APIs of two types and decide whether -such types are identical. Use other mechanisms (inheritance or interfaces) -instead. - - -## TypeScript - - -``` - - class X { - public foo: number - - constructor() { - this.foo = 0 - } - } - - class Y { - public foo: number - - constructor() { - this.foo = 0 - } - } - - let x = new X() - let y = new Y() - - console.log("Assign X to Y") - y = x - - console.log("Assign Y to X") - x = y - - -``` - -## ArkTS - - -``` - - class X { - public foo: number - - constructor() { - this.foo = 0 - } - } - - // Y is derived from X, which explicitly set subtype / supertype relations: - class Y extends X { - constructor() { - super() - } - } - - let x = new X() - let y = new Y() - - console.log("Assign Y to X") - x = y // ok, X is the super class of Y - - // Cannot assign X to Y - //y = x - compile-time error - - -``` - -## See also - -- Recipe 030: Structural identity is not supported (``arkts-no-structural-identity``) -- Recipe 032: Structural typing is not supported for assignability checks (``arkts-no-structural-assignability``) -- Recipe 035: Structural typing is not supported for type inference (``arkts-no-structural-inference``) - - diff --git a/linter/docs/rules/recipe32.md b/linter/docs/rules/recipe32.md deleted file mode 100644 index cc7e41628..000000000 --- a/linter/docs/rules/recipe32.md +++ /dev/null @@ -1,88 +0,0 @@ -# Structural typing is not supported for assignability checks - -Rule ``arkts-no-structural-assignability`` - -**Severity: error** - -Currently, ArkTS does not check structural equivalence when checking if types -are assignable to each other, i.e., the compiler cannot compare public APIs of -two types and decide whether such types are identical. Use other mechanisms -(inheritance or interfaces) instead. - - -## TypeScript - - -``` - - class X { - public foo: number - - constructor() { - this.foo = 0 - } - } - - class Y { - public foo: number - constructor() { - this.foo = 0 - } - } - - let x = new X() - let y = new Y() - - console.log("Assign X to Y") - y = x - - console.log("Assign Y to X") - x = y - -``` - -## ArkTS - - -``` - - interface Z { - foo: number - } - - // X implements interface Z, which makes relation between X and Y explicit. - class X implements Z { - public foo: number - - constructor() { - this.foo = 0 - } - } - - // Y implements interface Z, which makes relation between X and Y explicit. - class Y implements Z { - public foo: number - - constructor() { - this.foo = 0 - } - } - - let x: Z = new X() - let y: Z = new Y() - - console.log("Assign X to Y") - y = x // ok, both are of the same type - - console.log("Assign Y to X") - x = y // ok, both are of the same type - -``` - -## See also - -- Recipe 030: Structural identity is not supported (``arkts-no-structural-identity``) -- Recipe 031: Structural typing is not supported for subtyping / supertyping (``arkts-no-structural-subtyping``) -- Recipe 035: Structural typing is not supported for type inference (``arkts-no-structural-inference``) - - diff --git a/linter/docs/rules/recipe35.md b/linter/docs/rules/recipe35.md deleted file mode 100644 index 9645463e7..000000000 --- a/linter/docs/rules/recipe35.md +++ /dev/null @@ -1,103 +0,0 @@ -# Structural typing is not supported for type inference - -Rule ``arkts-no-structural-inference`` - -**Severity: error** - -Currently, ArkTS does not support structural typing, i.e., the compiler cannot -compare public APIs of two types and decide whether such types are identical. -Use inheritance and interfaces to specify the relation between the types -explicitly. - - -## TypeScript - - -``` - - class X { - public foo: number - private s: string - - constructor (f: number) { - this.foo = f - this.s = "" - } - - public say(): void { - console.log("X = ", this.foo) - } - } - - class Y { - public foo: number - - constructor (f: number) { - this.foo = f - } - public say(): void { - console.log("Y = ", this.foo) - } - } - - function bar(z: X): void { - z.say() - } - - // X and Y are equivalent because their public API is equivalent. - // Thus the second call is allowed: - bar(new X(1)) - bar(new Y(2) as X) - -``` - -## ArkTS - - -``` - - interface Z { - say(): void - } - - class X implements Z { - public foo: number - private s: string - - constructor (f: number) { - this.foo = f - this.s = "" - } - public say(): void { - console.log("X = ", this.foo) - } - } - - class Y implements Z { - public foo: number - - constructor (f: number) { - this.foo = f - } - public say(): void { - console.log("Y = ", this.foo) - } - } - - function bar(z: Z): void { - z.say() - } - - // X and Y implement the same interface Z, thus both calls are allowed: - bar(new X(1)) - bar(new Y(2)) - -``` - -## See also - -- Recipe 030: Structural identity is not supported (``arkts-no-structural-identity``) -- Recipe 031: Structural typing is not supported for subtyping / supertyping (``arkts-no-structural-subtyping``) -- Recipe 032: Structural typing is not supported for assignability checks (``arkts-no-structural-assignability``) - - diff --git a/linter/docs/rules/recipe52.md b/linter/docs/rules/recipe52.md deleted file mode 100644 index fd7e53ae8..000000000 --- a/linter/docs/rules/recipe52.md +++ /dev/null @@ -1,59 +0,0 @@ -# Attempt to access an undefined property is a compile-time error - -Rule ``arkts-no-undefined-prop-access`` - -**Severity: error** - -ArkTS supports accessing only those class properties that are either declared -in the class, or accessible via inheritance. Accessing any other properties is -prohibited, and causes compile-time errors. Use proper types to check property -existence during compilation. - - -## TypeScript - - -``` - - let person = {name: "Bob", isEmployee: true} - - let n = person["name"] - let e = person["isEmployee"] - let s = person["office"] // Compile-time error only with noImplicitAny - -``` - -## ArkTS - - -``` - - class Person { - constructor(name: string, isEmployee: boolean) { - this.name = name - this.isEmployee = isEmployee - } - - name: string - isEmployee: boolean - } - - let person = new Person("Bob", true) - let n = person.name - let e = person.isEmployee - let s = person.office // Compile-time error - -``` - -## See also - -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-identifiers-as-prop-names``) -- Recipe 002: ``Symbol()`` API is not supported (``arkts-no-symbol``) -- Recipe 059: ``delete`` operator is not supported (``arkts-no-delete``) -- Recipe 060: ``typeof`` operator is allowed only in expression contexts (``arkts-no-type-query``) -- Recipe 066: ``in`` operator is not supported (``arkts-no-in``) -- Recipe 105: Property-based runtime type checks are not supported (``arkts-no-prop-existence-check``) -- Recipe 109: Dynamic property declaration is not supported (``arkts-no-dyn-prop-decl``) -- Recipe 144: Usage of standard library is restricted (``arkts-limited-stdlib``) - - diff --git a/linter/docs/rules/recipe63.md b/linter/docs/rules/recipe63.md deleted file mode 100644 index 1b9bca2fd..000000000 --- a/linter/docs/rules/recipe63.md +++ /dev/null @@ -1,67 +0,0 @@ -# Binary ``+`` operator supports implicit casts only for numbers, enums and strings - -Rule ``arkts-no-polymorphic-plus`` - -**Severity: error** - -If one of the operands of the binary ``+`` operator is of the string type -(including enum string constant), then the other operand can be of any type, -and its value is implicitly converted to string. -Otherwise, ArkTS supports implicit casts with ``+`` only for numbers and -numeric enum constants. -ArkTS, like TypeScript, does not support the operator ``+`` for the booleans. -Elsewhere, any form of an explicit cast is required. - - -## TypeScript - - -``` - - enum E { E1, E2 } - - let a = 10 + 32 // 42 - let b = E.E1 + 10 // 10 - let c = 10 + "5" // "105" - - let d = "5" + E.E2 // "51" - let e = "Hello, " + "world!" // "Hello, world!" - let f = "string" + true // "stringtrue" - - let g = (new Object()) + "string" // "[object Object]string" - - let i = true + true // Compile-time error - let j = true + 2 // Compile-time error - let k = E.E1 + true // Compile-time error - -``` - -## ArkTS - - -``` - - enum E { E1, E2 } - - let a = 10 + 32 // 42 - let b = E.E1 + 10 // 10 - let c = 10 + "5" // "105" - - let d = "5" + E.E2 // "51" - let e = "Hello, " + "world!" // "Hello, world!" - let f = "string" + true // "stringtrue" - - let g = (new Object()).toString() + "string" - - let i = true + true // Compile-time error - let j = true + 2 // Compile-time error - let k = E.E1 + true // Compile-time error - -``` - -## See also - -- Recipe 055: Unary operators ``+``, ``-`` and ``~`` work only on numbers (``arkts-no-polymorphic-unops``) - - - diff --git a/linter/docs/rules/recipe76.md b/linter/docs/rules/recipe76.md deleted file mode 100644 index e620ace6b..000000000 --- a/linter/docs/rules/recipe76.md +++ /dev/null @@ -1,37 +0,0 @@ -# Inference of implied types is not supported - -Rule ``arkts-no-implied-inference`` - -**Severity: error** - -Currently, ArkTS does not support inference of implied types. -Use explicit type notation instead. -Use ``Object[]`` if you need containers that hold data of mixed types. - - -## TypeScript - - -``` - - let [a, b, c] = [1, "hello", true] - -``` - -## ArkTS - - -``` - - let a = 1 - let b = "hello" - let c = true - - let arr: Object[] = [1, "hello", true] - let a1 = arr[0] - let b1 = arr[1] - let c1 = arr[2] - -``` - - diff --git a/linter/docs/rules/recipe81.md b/linter/docs/rules/recipe81.md deleted file mode 100644 index 541ab965a..000000000 --- a/linter/docs/rules/recipe81.md +++ /dev/null @@ -1,18 +0,0 @@ -# Iterable interfaces are not supported - -Rule ``arkts-no-iterable`` - -**Severity: error** - -ArkTS does not support the ``Symbol`` API, ``Symbol.iterator`` and -eventually iterable interfaces. Use arrays and library-level containers to -iterate over data. - - -## See also - -- Recipe 002: ``Symbol()`` API is not supported (``arkts-no-symbol``) -- Recipe 080: ``for .. in`` is not supported (``arkts-no-for-in``) -- Recipe 082: ``for-of`` is supported only for arrays and strings (``arkts-for-of-str-arr``) - - diff --git a/linter/docs/rules/recipe85.md b/linter/docs/rules/recipe85.md deleted file mode 100644 index e4ea44798..000000000 --- a/linter/docs/rules/recipe85.md +++ /dev/null @@ -1,57 +0,0 @@ -# Values computed at runtime are not supported in ``case`` statements - -Rule ``arkts-no-computed-case`` - -**Severity: error** - -ArkTS supports ``case`` statements that contain only compile-time values, -top-level scope ``const`` values, and ``static readonly`` class fields. -Use ``if`` statements as an alternative. - - -## TypeScript - - -``` - - let x = 2 - let y = 3 - switch (x) { - case 1: - console.log(1) - break - case 2: - console.log(2) - break - case y: - console.log(y) - break - default: - console.log("other") - } - -``` - -## ArkTS - - -``` - - let x = 2 - switch (x) { - case 1: - console.log(1) - break - case 2: - console.log(2) - break - case 3: - console.log(3) - break - default: - console.log("other") - } - -``` - - diff --git a/linter/docs/rules/recipe86.md b/linter/docs/rules/recipe86.md deleted file mode 100644 index 9daf45688..000000000 --- a/linter/docs/rules/recipe86.md +++ /dev/null @@ -1,49 +0,0 @@ -# ``switch`` statements cannot accept values of arbitrary types - -Rule ``arkts-limited-switch`` - -**Severity: error** - -ArkTS restricts the types that are supported in ``switch`` statements. In -particular, values of the types ``number``, ``Number``, ``string``, ``String`` -or ``enum`` are supported. Use ``if`` statements in case of unsupported types. - - -## TypeScript - - -``` - - class Point { - x: number = 0 - y: number = 0 - } - - let a = new Point() - - switch (a) { - case null: break - default: console.log("not null") - } - -``` - -## ArkTS - - -``` - - class Point { - x: number = 0 - y: number = 0 - } - - let a = new Point() - - if (a != null) { - console.log("not null") - } - -``` - - diff --git a/linter/src/FaultAttrs.ts b/linter/src/FaultAttrs.ts index 27f2c23d4..606263154 100644 --- a/linter/src/FaultAttrs.ts +++ b/linter/src/FaultAttrs.ts @@ -59,20 +59,16 @@ faultsAttrs[FaultID.JsxElement] = {cookBookRef: '54',}; faultsAttrs[FaultID.UnaryArithmNotNumber] = {cookBookRef: '55',}; faultsAttrs[FaultID.DeleteOperator] = {cookBookRef: '59',}; faultsAttrs[FaultID.TypeQuery] = {cookBookRef: '60',}; -faultsAttrs[FaultID.AddWithWrongType] = {cookBookRef: '63',}; faultsAttrs[FaultID.InstanceofUnsupported] = {cookBookRef: '65',}; faultsAttrs[FaultID.InOperator] = {cookBookRef: '66',}; faultsAttrs[FaultID.DestructuringAssignment] = {migratable: true, cookBookRef: '69',}; faultsAttrs[FaultID.CommaOperator] = {cookBookRef: '71',}; faultsAttrs[FaultID.DestructuringDeclaration] = {migratable: true, cookBookRef: '74',}; -faultsAttrs[FaultID.InferType] = {cookBookRef: '76',}; faultsAttrs[FaultID.CatchWithUnsupportedType] = {migratable: true, cookBookRef: '79',}; faultsAttrs[FaultID.ForInStatement] = {cookBookRef: '80',}; faultsAttrs[FaultID.ForOfNonArray] = {migratable: true, cookBookRef: '82',}; faultsAttrs[FaultID.MappedType] = {cookBookRef: '83',}; faultsAttrs[FaultID.WithStatement] = {cookBookRef: '84',}; -faultsAttrs[FaultID.CaseExpressionNonConst] = {cookBookRef: '85',}; -faultsAttrs[FaultID.SwitchSelectorInvalidType] = {cookBookRef: '86',}; faultsAttrs[FaultID.ThrowStatement] = {migratable: true, cookBookRef: '87',}; faultsAttrs[FaultID.LimitedReturnTypeInference] = {migratable: true, cookBookRef: '90',}; faultsAttrs[FaultID.DestructuringParameter] = {cookBookRef: '91',}; diff --git a/linter/src/FaultDesc.ts b/linter/src/FaultDesc.ts index befb4cf76..58bb3ef79 100644 --- a/linter/src/FaultDesc.ts +++ b/linter/src/FaultDesc.ts @@ -45,7 +45,6 @@ faultDesc[FaultID.ImportFromPath] = 'imports from path'; faultDesc[FaultID.FunctionExpression] = 'function expressions'; faultDesc[FaultID.IntersectionType] = 'intersection types and type literals'; faultDesc[FaultID.ObjectTypeLiteral] = 'Object type literals'; -faultDesc[FaultID.AddWithWrongType] = 'binary "+" with wrong operand'; faultDesc[FaultID.CommaOperator] = 'comma operator'; faultDesc[FaultID.LimitedReturnTypeInference] = 'Functions with limited return type inference'; faultDesc[FaultID.LambdaWithTypeParameters] = 'Lambda function with type parameters'; @@ -65,8 +64,6 @@ faultDesc[FaultID.CallSignature] = 'Call signatures'; faultDesc[FaultID.TypeAssertion] = 'Type assertion expressions'; faultDesc[FaultID.PrivateIdentifier] = 'Private identifiers (with "#" prefix)'; faultDesc[FaultID.LocalFunction] = 'Local function declarations'; -faultDesc[FaultID.SwitchSelectorInvalidType] = 'Switch selectors with invalid type'; -faultDesc[FaultID.CaseExpressionNonConst] = '"case" clause with non-constant expression'; faultDesc[FaultID.ConditionalType] = 'Conditional type'; faultDesc[FaultID.MappedType] = 'Mapped type'; faultDesc[FaultID.NamespaceAsObject] = 'Namespaces used as objects'; @@ -80,7 +77,6 @@ faultDesc[FaultID.EnumMemberNonConstInit] = 'Enum members with non-constant init faultDesc[FaultID.ImplementsClass] = 'Class type mentioned in "implements" clause'; faultDesc[FaultID.MultipleStaticBlocks] = 'Multiple static blocks'; faultDesc[FaultID.ThisType] = '"this" type'; -faultDesc[FaultID.InferType] = 'Infer type'; faultDesc[FaultID.IntefaceExtendDifProps] = 'Extends same properties with different types'; faultDesc[FaultID.StructuralIdentity] = 'Use of type structural identity'; faultDesc[FaultID.TypeOnlyImport] = 'Type-only imports'; diff --git a/linter/src/Problems.ts b/linter/src/Problems.ts index ef4618dea..a062ce352 100644 --- a/linter/src/Problems.ts +++ b/linter/src/Problems.ts @@ -19,14 +19,14 @@ export enum FaultID { DestructuringParameter, YieldExpression, InterfaceMerging, EnumMerging, InterfaceExtendsClass, IndexMember, WithStatement, ThrowStatement, IndexedAccessType, UnknownType, ForInStatement, InOperator, KeyOfOperator, ImportFromPath, FunctionExpression, IntersectionType, - ObjectTypeLiteral, AddWithWrongType, CommaOperator, LimitedReturnTypeInference, + ObjectTypeLiteral, CommaOperator, LimitedReturnTypeInference, LambdaWithTypeParameters, ClassExpression, DestructuringAssignment, DestructuringDeclaration, ForOfNonArray, VarDeclaration, CatchWithUnsupportedType, DeleteOperator, DeclWithDuplicateName, UnaryArithmNotNumber, ConstructorType, ConstructorIface, ConstructorFuncs, CallSignature, TypeAssertion, PrivateIdentifier, LocalFunction, - SwitchSelectorInvalidType, CaseExpressionNonConst, ConditionalType, MappedType, NamespaceAsObject, ClassAsObject, + ConditionalType, MappedType, NamespaceAsObject, ClassAsObject, NonDeclarationInNamespace, GeneratorFunction, FunctionContainsThis, PropertyAccessByIndex, JsxElement, - EnumMemberNonConstInit, ImplementsClass, MultipleStaticBlocks, ThisType, InferType, + EnumMemberNonConstInit, ImplementsClass, MultipleStaticBlocks, ThisType, IntefaceExtendDifProps, StructuralIdentity, TypeOnlyImport, TypeOnlyExport, DefaultImport, LimitedReExporting, ExportAssignment, ImportAssignment, PropertyRuntimeCheck, GenericCallNoTypeArgs, ParameterProperties, diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index ee117b90f..ddaeea234 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -887,9 +887,6 @@ export class TypeScriptLinter { let rightOperandType = this.tsTypeChecker.getTypeAtLocation(tsRhsExpr); switch (tsBinaryExpr.operatorToken.kind) { // FaultID.BitOpWithWrongType - removed as rule #61 - case ts.SyntaxKind.PlusToken: - this.processBinaryAddition(node, leftOperandType, rightOperandType); - break; case ts.SyntaxKind.CommaToken: this.processBinaryComma(tsBinaryExpr); break; @@ -923,24 +920,6 @@ export class TypeScriptLinter { } } - private processBinaryAddition(node: ts.Node, leftOperandType: ts.Type, rightOperandType: ts.Type) { - if (this.tsUtils.isEnumMemberType(leftOperandType) && this.tsUtils.isEnumMemberType(rightOperandType)) { - if ( - ( (leftOperandType.getFlags() & (ts.TypeFlags.NumberLike)) && (rightOperandType.getFlags() & (ts.TypeFlags.NumberLike ) ) ) || - ( (leftOperandType.getFlags() & (ts.TypeFlags.StringLike)) && (rightOperandType.getFlags() & (ts.TypeFlags.StringLike ) ) ) - ) - return; - else - this.incrementCounters(node, FaultID.AddWithWrongType); - } else if (this.tsUtils.isNumberType(leftOperandType) && this.tsUtils.isNumberType(rightOperandType)) { - return; - } else if (this.tsUtils.isStringLikeType(leftOperandType) || this.tsUtils.isStringLikeType(rightOperandType)) { - return; - } else { - this.incrementCounters(node, FaultID.AddWithWrongType); - } - } - private processBinaryComma(tsBinaryExpr: ts.BinaryExpression) { // CommaOpertor is allowed in 'for' statement initalizer and incrementor let tsExprNode: ts.Node = tsBinaryExpr; @@ -1210,21 +1189,9 @@ export class TypeScriptLinter { private handleSwitchStatement(node: ts.Node) { let tsSwitchStmt = node as ts.SwitchStatement; - let tsSwitchExprType = this.tsTypeChecker.getTypeAtLocation(tsSwitchStmt.expression); - const isSwitchableNumeric = (type: ts.Type) => { - return !!(type.getFlags() & ts.TypeFlags.NumberLike); - } - const isSwitchableString = (type: ts.Type) => { - return !!(type.getFlags() & ts.TypeFlags.StringLike); - } - if (!this.tsUtils.checkTypeSet(tsSwitchExprType, isSwitchableNumeric) && - !this.tsUtils.checkTypeSet(tsSwitchExprType, isSwitchableString)) { - this.incrementCounters(tsSwitchStmt.expression, FaultID.SwitchSelectorInvalidType); - } for (const tsCaseClause of tsSwitchStmt.caseBlock.clauses) { if (ts.isCaseClause(tsCaseClause)) { const tsCaseExpr = tsCaseClause.expression; - const tsCaseExprType = this.tsTypeChecker.getTypeAtLocation(tsCaseExpr); const tsCaseSym = this.tsTypeChecker.getSymbolAtLocation(tsCaseExpr); let isConstOrStaticReadonlyField: boolean = false; if (tsCaseSym?.valueDeclaration) { @@ -1246,16 +1213,6 @@ export class TypeScriptLinter { (isConstOrStaticReadonlyField); } } - if ( - !( - isConstOrStaticReadonlyField || - ts.isNumericLiteral(tsCaseExpr) || - ts.isStringLiteralLike(tsCaseExpr) || - tsCaseExprType.flags & ts.TypeFlags.EnumLike - ) - ) { - this.incrementCounters(tsCaseExpr, FaultID.CaseExpressionNonConst); - } } } } diff --git a/linter/src/TypeScriptLinterConfig.ts b/linter/src/TypeScriptLinterConfig.ts index 6dc89c014..40ce33cd1 100644 --- a/linter/src/TypeScriptLinterConfig.ts +++ b/linter/src/TypeScriptLinterConfig.ts @@ -73,7 +73,7 @@ export class LinterConfig { // 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.ThisType, FaultID.ThisType], [ts.SyntaxKind.InferType, FaultID.InferType], + [ts.SyntaxKind.ThisType, FaultID.ThisType], [ts.SyntaxKind.TupleType, FaultID.TupleType], [ts.SyntaxKind.ComputedPropertyName, FaultID.ComputedPropertyName], [ts.SyntaxKind.TypeQuery, FaultID.TypeQuery], [ts.SyntaxKind.DeleteExpression, FaultID.DeleteOperator], diff --git a/linter/test/binary_wrong_types.ts.relax.json b/linter/test/binary_wrong_types.ts.relax.json index 729e4f6ff..30ed120e9 100644 --- a/linter/test/binary_wrong_types.ts.relax.json +++ b/linter/test/binary_wrong_types.ts.relax.json @@ -35,13 +35,6 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, - { - "line": 45, - "column": 14, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, { "line": 46, "column": 7, @@ -49,33 +42,12 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, - { - "line": 46, - "column": 14, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, { "line": 95, "column": 15, "problem": "CommaOperator", "suggest": "", "rule": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)" - }, - { - "line": 114, - "column": 10, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, - { - "line": 115, - "column": 10, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" } ] } diff --git a/linter/test/binary_wrong_types.ts.strict.json b/linter/test/binary_wrong_types.ts.strict.json index 729e4f6ff..30ed120e9 100644 --- a/linter/test/binary_wrong_types.ts.strict.json +++ b/linter/test/binary_wrong_types.ts.strict.json @@ -35,13 +35,6 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, - { - "line": 45, - "column": 14, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, { "line": 46, "column": 7, @@ -49,33 +42,12 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, - { - "line": 46, - "column": 14, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, { "line": 95, "column": 15, "problem": "CommaOperator", "suggest": "", "rule": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)" - }, - { - "line": 114, - "column": 10, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, - { - "line": 115, - "column": 10, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" } ] } diff --git a/linter/test/switch_statements.ts b/linter/test/switch_statements.ts deleted file mode 100644 index cef30c267..000000000 --- a/linter/test/switch_statements.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -interface I { - f: number; -} - -function foo(a: string, b: string, i: I): void { - switch (a) { - case '0': - console.log('0'); - break; - case b: - console.log(b); - break; - } - - switch (i) { - case null: - console.log('null interace'); - break; - } - - switch (undefined) { - case console.log(1): - case console.log(2): - void console.log(3); - } - - const x = 10, - y = 20, - z = 30; - const foo = (n: number) => n; - switch (x) { - case x + y: - console.log('x + y = ' + (x + y)); - break; - case foo(z): - console.log('foo(z) = ' + foo(z)); - break; - default: - console.log('default case'); - } -} - -enum E { - Ea = "a", - Eb = "b" -} - -let a0: string = "234"; -const x0: string = "123"; -const x1 = a0; -const x2 = x0; - -class TestClass { - static readonly y:string = "2"; - readonly z:string = "3"; - - f(s: string) { - const z1 = this.z; - const z2 = s; - - switch (s) { - case E.Ea: - break; - case E.Eb: - break; - case a0: - break; - case x0: - break; - case x1: - break; - case x2: - break; - case TestClass.y: - break; - case this.z: - break; - case z1: - break; - case z2: - break; - case s: - break; - default: - } - } -} - -enum COLORS { Red, Green, Blue }; - -function bar(color: COLORS) { - if (color == COLORS.Blue) { - return 0; - } - switch (color) { - case COLORS.Red: - return 1; - case COLORS.Green: - return 2; - default: - return 3; - } -} - -function car(color: COLORS | 'a') { - switch (color) { - case COLORS.Red: - return 1; - default: - return 3; - } -} diff --git a/linter/test/switch_statements.ts.autofix.skip b/linter/test/switch_statements.ts.autofix.skip deleted file mode 100644 index e69de29bb..000000000 diff --git a/linter/test/switch_statements.ts.relax.json b/linter/test/switch_statements.ts.relax.json deleted file mode 100644 index ebeb015d4..000000000 --- a/linter/test/switch_statements.ts.relax.json +++ /dev/null @@ -1,93 +0,0 @@ -{ - "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": 25, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 30, - "column": 11, - "problem": "SwitchSelectorInvalidType" - }, - { - "line": 31, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 36, - "column": 11, - "problem": "SwitchSelectorInvalidType" - }, - { - "line": 37, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 38, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 47, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 50, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 81, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 85, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 91, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 93, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 95, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 97, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 121, - "column": 13, - "problem": "SwitchSelectorInvalidType" - } - ] -} diff --git a/linter/test/switch_statements.ts.strict.json b/linter/test/switch_statements.ts.strict.json deleted file mode 100644 index ebeb015d4..000000000 --- a/linter/test/switch_statements.ts.strict.json +++ /dev/null @@ -1,93 +0,0 @@ -{ - "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": 25, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 30, - "column": 11, - "problem": "SwitchSelectorInvalidType" - }, - { - "line": 31, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 36, - "column": 11, - "problem": "SwitchSelectorInvalidType" - }, - { - "line": 37, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 38, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 47, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 50, - "column": 10, - "problem": "CaseExpressionNonConst" - }, - { - "line": 81, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 85, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 91, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 93, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 95, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 97, - "column": 16, - "problem": "CaseExpressionNonConst" - }, - { - "line": 121, - "column": 13, - "problem": "SwitchSelectorInvalidType" - } - ] -} diff --git a/linter/test_rules/rule22.ts.autofix.json b/linter/test_rules/rule22.ts.autofix.json index 56ef77a1a..2493216ba 100644 --- a/linter/test_rules/rule22.ts.autofix.json +++ b/linter/test_rules/rule22.ts.autofix.json @@ -15,14 +15,6 @@ "autofixable": false, "suggest": "", "rule": "Conditional types are not supported (arkts-no-conditional-types)" - }, - { - "line": 3, - "column": 29, - "problem": "InferType", - "autofixable": false, - "suggest": "", - "rule": "Inference of implied types is not supported (arkts-no-implied-inference)" } ] -} \ No newline at end of file +} diff --git a/linter/test_rules/rule22.ts.relax.json b/linter/test_rules/rule22.ts.relax.json index 995d3e580..4e1ebe000 100644 --- a/linter/test_rules/rule22.ts.relax.json +++ b/linter/test_rules/rule22.ts.relax.json @@ -13,13 +13,6 @@ "problem": "ConditionalType", "suggest": "", "rule": "Conditional types are not supported (arkts-no-conditional-types)" - }, - { - "line": 3, - "column": 29, - "problem": "InferType", - "suggest": "", - "rule": "Inference of implied types is not supported (arkts-no-implied-inference)" } ] -} \ No newline at end of file +} diff --git a/linter/test_rules/rule22.ts.strict.json b/linter/test_rules/rule22.ts.strict.json index 995d3e580..4e1ebe000 100644 --- a/linter/test_rules/rule22.ts.strict.json +++ b/linter/test_rules/rule22.ts.strict.json @@ -13,13 +13,6 @@ "problem": "ConditionalType", "suggest": "", "rule": "Conditional types are not supported (arkts-no-conditional-types)" - }, - { - "line": 3, - "column": 29, - "problem": "InferType", - "suggest": "", - "rule": "Inference of implied types is not supported (arkts-no-implied-inference)" } ] -} \ No newline at end of file +} diff --git a/linter/test_rules/rule63.ts.autofix.json b/linter/test_rules/rule63.ts.autofix.json index e1bcaa09b..c7b928233 100644 --- a/linter/test_rules/rule63.ts.autofix.json +++ b/linter/test_rules/rule63.ts.autofix.json @@ -8,14 +8,6 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, - { - "line": 13, - "column": 9, - "problem": "AddWithWrongType", - "autofixable": false, - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, { "line": 14, "column": 5, @@ -24,14 +16,6 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, - { - "line": 14, - "column": 9, - "problem": "AddWithWrongType", - "autofixable": false, - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, { "line": 15, "column": 5, @@ -39,14 +23,6 @@ "autofixable": false, "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" - }, - { - "line": 15, - "column": 9, - "problem": "AddWithWrongType", - "autofixable": false, - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" } ] -} \ No newline at end of file +} diff --git a/linter/test_rules/rule63.ts.relax.json b/linter/test_rules/rule63.ts.relax.json index 650d0073d..324172c39 100644 --- a/linter/test_rules/rule63.ts.relax.json +++ b/linter/test_rules/rule63.ts.relax.json @@ -7,13 +7,6 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, - { - "line": 13, - "column": 9, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, { "line": 14, "column": 5, @@ -21,26 +14,12 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, - { - "line": 14, - "column": 9, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, { "line": 15, "column": 5, "problem": "AnyType", "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" - }, - { - "line": 15, - "column": 9, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" } ] -} \ No newline at end of file +} diff --git a/linter/test_rules/rule63.ts.strict.json b/linter/test_rules/rule63.ts.strict.json index 650d0073d..324172c39 100644 --- a/linter/test_rules/rule63.ts.strict.json +++ b/linter/test_rules/rule63.ts.strict.json @@ -7,13 +7,6 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, - { - "line": 13, - "column": 9, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, { "line": 14, "column": 5, @@ -21,26 +14,12 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, - { - "line": 14, - "column": 9, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" - }, { "line": 15, "column": 5, "problem": "AnyType", "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" - }, - { - "line": 15, - "column": 9, - "problem": "AddWithWrongType", - "suggest": "", - "rule": "Binary \"+\" operator supports implicit casts only for numbers, enums and strings (arkts-no-polymorphic-plus)" } ] -} \ No newline at end of file +} diff --git a/linter/test_rules/rule85.ts b/linter/test_rules/rule85.ts deleted file mode 100644 index a0ff6ba89..000000000 --- a/linter/test_rules/rule85.ts +++ /dev/null @@ -1,30 +0,0 @@ -let x = 2 -let y = 3 -switch (x) { - case 1: - console.log(1) - break - case 2: - console.log(2) - break - case y: - console.log(y) - break - default: - console.log("other") -} - -let x2 = 2 -switch (x2) { - case 1: - console.log(1) - break - case 2: - console.log(2) - break - case 3: - console.log(3) - break - default: - console.log("other") -} diff --git a/linter/test_rules/rule85.ts.autofix.json b/linter/test_rules/rule85.ts.autofix.json deleted file mode 100644 index f82758346..000000000 --- a/linter/test_rules/rule85.ts.autofix.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nodes": [ - { - "line": 10, - "column": 10, - "problem": "CaseExpressionNonConst", - "autofixable": false, - "suggest": "", - "rule": "Values computed at runtime are not supported in \"case\" statements (arkts-no-computed-case)" - } - ] -} \ No newline at end of file diff --git a/linter/test_rules/rule85.ts.relax.json b/linter/test_rules/rule85.ts.relax.json deleted file mode 100644 index 70314c7f6..000000000 --- a/linter/test_rules/rule85.ts.relax.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "nodes": [ - { - "line": 10, - "column": 10, - "problem": "CaseExpressionNonConst", - "suggest": "", - "rule": "Values computed at runtime are not supported in \"case\" statements (arkts-no-computed-case)" - } - ] -} \ No newline at end of file diff --git a/linter/test_rules/rule85.ts.strict.json b/linter/test_rules/rule85.ts.strict.json deleted file mode 100644 index 70314c7f6..000000000 --- a/linter/test_rules/rule85.ts.strict.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "nodes": [ - { - "line": 10, - "column": 10, - "problem": "CaseExpressionNonConst", - "suggest": "", - "rule": "Values computed at runtime are not supported in \"case\" statements (arkts-no-computed-case)" - } - ] -} \ No newline at end of file diff --git a/linter/test_rules/rule86.ts b/linter/test_rules/rule86.ts deleted file mode 100644 index 4fce0a2cd..000000000 --- a/linter/test_rules/rule86.ts +++ /dev/null @@ -1,15 +0,0 @@ -class Point { - x: number = 0 - y: number = 0 -} - -let a = new Point() - -switch (a) { - case null: break - default: console.log("not null") -} - -if (a != null) { - console.log("not null") -} \ No newline at end of file diff --git a/linter/test_rules/rule86.ts.autofix.json b/linter/test_rules/rule86.ts.autofix.json deleted file mode 100644 index a05e9bda7..000000000 --- a/linter/test_rules/rule86.ts.autofix.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "nodes": [ - { - "line": 8, - "column": 9, - "problem": "SwitchSelectorInvalidType", - "autofixable": false, - "suggest": "", - "rule": "\"switch\" statements cannot accept values of arbitrary types (arkts-limited-switch)" - }, - { - "line": 9, - "column": 10, - "problem": "CaseExpressionNonConst", - "autofixable": false, - "suggest": "", - "rule": "Values computed at runtime are not supported in \"case\" statements (arkts-no-computed-case)" - } - ] -} \ No newline at end of file diff --git a/linter/test_rules/rule86.ts.relax.json b/linter/test_rules/rule86.ts.relax.json deleted file mode 100644 index 92d9eb867..000000000 --- a/linter/test_rules/rule86.ts.relax.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "nodes": [ - { - "line": 8, - "column": 9, - "problem": "SwitchSelectorInvalidType", - "suggest": "", - "rule": "\"switch\" statements cannot accept values of arbitrary types (arkts-limited-switch)" - }, - { - "line": 9, - "column": 10, - "problem": "CaseExpressionNonConst", - "suggest": "", - "rule": "Values computed at runtime are not supported in \"case\" statements (arkts-no-computed-case)" - } - ] -} \ No newline at end of file diff --git a/linter/test_rules/rule86.ts.strict.json b/linter/test_rules/rule86.ts.strict.json deleted file mode 100644 index 92d9eb867..000000000 --- a/linter/test_rules/rule86.ts.strict.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "nodes": [ - { - "line": 8, - "column": 9, - "problem": "SwitchSelectorInvalidType", - "suggest": "", - "rule": "\"switch\" statements cannot accept values of arbitrary types (arkts-limited-switch)" - }, - { - "line": 9, - "column": 10, - "problem": "CaseExpressionNonConst", - "suggest": "", - "rule": "Values computed at runtime are not supported in \"case\" statements (arkts-no-computed-case)" - } - ] -} \ No newline at end of file -- Gitee