diff --git a/linter-4.2/docs/rules/recipe1.md b/linter-4.2/docs/rules/recipe1.md index c67cc90d075811adc29ea05b1ad6e879c3c90851..317d04c6bd75c5d7c80e2e19a7553595833174ac 100644 --- a/linter-4.2/docs/rules/recipe1.md +++ b/linter-4.2/docs/rules/recipe1.md @@ -1,12 +1,12 @@ # Objects with property names that are not identifiers are not supported -Rule ``arkts-no-computed-props`` +Rule ``arkts-identifiers-as-prop-names`` **Severity: error** ArkTS does not support Objects with name properties that are numbers or -strings. Use classes to access data by property names. Use arrays to access data -by numeric indices. +strings. Use classes to access data by property names. Use arrays to access +data by numeric indices. ## TypeScript @@ -50,9 +50,10 @@ by numeric indices. - 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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/recipe105.md b/linter-4.2/docs/rules/recipe105.md index 599c1e61d052403b16e78dd4a0997171cd40a8ed..e7e9d47bd4ddee7855a9b3261376434ed844ee85 100644 --- a/linter-4.2/docs/rules/recipe105.md +++ b/linter-4.2/docs/rules/recipe105.md @@ -53,19 +53,21 @@ will result in a compile-time error. let obj: A = tmp as A obj.foo() // OK obj.bar() // OK - obj.some_foo() // Compile-time error: Method some_foo does not exist on this type + obj.some_foo() // Compile-time error: Method some_foo does not + // exist on this type } ``` ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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 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/recipe106.md b/linter-4.2/docs/rules/recipe106.md index 207e857bd9890cfff83413e00b6fbfd07ebc07ef..f98f5dcdfef698cd6c6612439f543f9d69364560 100644 --- a/linter-4.2/docs/rules/recipe106.md +++ b/linter-4.2/docs/rules/recipe106.md @@ -5,7 +5,7 @@ Rule ``arkts-no-ctor-signatures-funcs`` **Severity: error** ArkTS does not support the usage of the constructor function type. -Use lambdas instead, as they can be generalized to several types of objects. +Use lambdas instead. ## TypeScript @@ -19,10 +19,10 @@ Use lambdas instead, as they can be generalized to several types of objects. age: number ) {} } + type PersonCtor = new (name: string, age: number) => Person - type PersonConstructor = new (name: string, age: number) => Person - - function createPerson(Ctor: PersonConstructor, name: string, age: number): Person { + function createPerson(Ctor: PersonCtor, name: string, age: number): Person + { return new Ctor(name, age) } @@ -41,18 +41,17 @@ Use lambdas instead, as they can be generalized to several types of objects. age: number ) {} } + type PersonCtor = (n: string, a: number) => Person - let PersonConstructor: (name: string, age: number) => Person = (name: string, age: number): Person => { - return new Person(name, age) + function createPerson(Ctor: PersonCtor, n: string, a: number): Person { + return Ctor(n, a) } - function createPerson(Ctor: (name: string, age: number) => Person, name: string, age: number): Person { - return PersonConstructor(name, age) + let Impersonizer: PersonCtor = (n: string, a: number): Person => { + return new Person(n, a) } - function main(): void { - const person = createPerson(PersonConstructor, "John", 30) - } + const person = createPerson(Impersonizer, "John", 30) ``` diff --git a/linter-4.2/docs/rules/recipe109.md b/linter-4.2/docs/rules/recipe109.md index 591526e2be42d8a654767cb78da2b253be0179ee..05dd754c2161ecbca46bdb90943e9049fdad2cfb 100644 --- a/linter-4.2/docs/rules/recipe109.md +++ b/linter-4.2/docs/rules/recipe109.md @@ -57,12 +57,13 @@ declare fields, their names and types explicitly. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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/recipe111.md b/linter-4.2/docs/rules/recipe111.md index 2e7f4a7f1d3fabe0497bbb07fee69e0d817cc144..9100095fc4980f7ce6d782a2e97a8815f821666b 100644 --- a/linter-4.2/docs/rules/recipe111.md +++ b/linter-4.2/docs/rules/recipe111.md @@ -1,10 +1,12 @@ -# Explicit values for enumeration constants are not supported +# Enumeration members can be initialized only with compile time expressions of the same type -Rule ``arkts-no-explicit-enum-init`` +Rule ``arkts-no-enum-mixed-types`` **Severity: error** -Currently, ArkTS does not support assigning explicit values for ``enums``. +ArkTS does not support initializing members of enumerations with expressions +that are evaluated during program runtime. Besides, all explicitly set +initializers must be of the same type. ## TypeScript @@ -12,11 +14,19 @@ Currently, ArkTS does not support assigning explicit values for ``enums``. ``` - enum E { - A, - B, - C = 10, - D + enum E1 { + A = 0xa, + B = 0xb, + C = Math.random(), + D = 0xd, + E // 0xe inferred + } + + enum E2 { + A = 0xa, + B = "0xb", + C = 0xc, + D = "0xd" } ``` @@ -26,18 +36,19 @@ Currently, ArkTS does not support assigning explicit values for ``enums``. ``` - enum E { - A, - B, - C = 10, // Compile-time error: assigning out of order values for enums is not supported - D + enum E1 { + A = 0xa, + B = 0xb, + C = 0xc, + D = 0xd, + E // 0xe inferred } - enum E_fixed { - A, - B, - C, // OK - D + enum E2 { + A = "0xa", + B = "0xb", + C = "0xc", + D = "0xd" } ``` diff --git a/linter-4.2/docs/rules/recipe115.md b/linter-4.2/docs/rules/recipe115.md index b7ed86e5f2733a979db425cc239c2fc5ea22e15e..ee73f68fd25bfc22657de9f15ea50dd826f62462 100644 --- a/linter-4.2/docs/rules/recipe115.md +++ b/linter-4.2/docs/rules/recipe115.md @@ -13,10 +13,9 @@ Differences are described in separate recipes. - Recipe 118: Special import type declarations are not supported (``arkts-no-special-imports``) - 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`` is not supported (``arkts-no-require``) -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) +- Recipe 121: ``require`` and ``import`` assignment are not supported (``arkts-no-require``) - Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) -- Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) +- Recipe 125: Re-exporting is supported with restrictions (``arkts-limited-reexport``) - Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) diff --git a/linter-4.2/docs/rules/recipe118.md b/linter-4.2/docs/rules/recipe118.md index 5cd2e85ed0781ccf7b15d67a9c67109468464b0f..0041552fdb013d8acf3a5c3078f2ebc668725250 100644 --- a/linter-4.2/docs/rules/recipe118.md +++ b/linter-4.2/docs/rules/recipe118.md @@ -34,6 +34,6 @@ Use ordinary import instead. - 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`` is not supported (``arkts-no-require``) +- Recipe 121: ``require`` and ``import`` assignment are not supported (``arkts-no-require``) diff --git a/linter-4.2/docs/rules/recipe121.md b/linter-4.2/docs/rules/recipe121.md index 918ae2aed90d941443f0d25a701af1d3af56bfdd..ef4631c12d6b3523a67e1a709ac545268a8bcc8d 100644 --- a/linter-4.2/docs/rules/recipe121.md +++ b/linter-4.2/docs/rules/recipe121.md @@ -1,10 +1,11 @@ -# ``require`` is not supported +# ``require`` and ``import`` assignment are not supported Rule ``arkts-no-require`` **Severity: error** -ArkTS does not support importing via ``require``. Use ``import`` instead. +ArkTS does not support importing via ``require``. ``import`` assignment are +not supported either. Use regular ``import`` instead. ## TypeScript @@ -25,4 +26,8 @@ ArkTS does not support importing via ``require``. Use ``import`` instead. ``` +## See also + +- Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) + diff --git a/linter-4.2/docs/rules/recipe124.md b/linter-4.2/docs/rules/recipe124.md index d86e3f384c80fc59d1f1bc2f309421f18cffa9af..b1a80dc42b5afd5d926351050b452986d9c7161c 100644 --- a/linter-4.2/docs/rules/recipe124.md +++ b/linter-4.2/docs/rules/recipe124.md @@ -33,8 +33,7 @@ entities must be explicitly annotated with the ``export`` keyword. ## See also -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) -- Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) +- Recipe 125: Re-exporting is supported with restrictions (``arkts-limited-reexport``) - Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) diff --git a/linter-4.2/docs/rules/recipe125.md b/linter-4.2/docs/rules/recipe125.md index 47ee1ddd34953caa7df805a24ce9f52dc3c38497..4aa7cec5d9d73203e8d1f8c54f74d4353899e904 100644 --- a/linter-4.2/docs/rules/recipe125.md +++ b/linter-4.2/docs/rules/recipe125.md @@ -1,11 +1,12 @@ -# Re-exporting is not supported +# Re-exporting is supported with restrictions -Rule ``arkts-no-reexport`` +Rule ``arkts-limited-reexport`` **Severity: error** -ArkTS does not support re-exporting. All desired entities must be -imported explicitly from the modules that export them. +ArkTS supports re-exporting syntax which covers most common cases of re-export: +re-exporting imported entities and re-exporting which is combined with renaming. +Other syntax flavors like ``export * as ...`` are not supported. ## TypeScript @@ -14,17 +15,18 @@ imported explicitly from the modules that export them. ``` // module1 - export class MyClass { + export class Class1 { + // ... + } + export class Class2 { // ... } // module2 - export { MyClass } from "module1" + export * as utilities from "module1" // consumer module - import { MyClass } from "module2" - - const myInstance = new MyClass() + import { utilities } from "module2" ``` @@ -34,24 +36,24 @@ imported explicitly from the modules that export them. ``` // module1 - export class MyClass { - // ... + export class Class1 { + // ... + } + export class C2 { + // ... } // module2 - // some stuff + export { Class1 } from "module1" + export { C2 as Class2 } from "module1" // consumer module - import { MyClass } from "module1" - import * from "module2" - - const myInstance = new MyClass() + import { Class1, Class2 } from "module2" ``` ## See also -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) - Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) - Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) diff --git a/linter-4.2/docs/rules/recipe126.md b/linter-4.2/docs/rules/recipe126.md index 94f88de58cd467215d24383ad9ad64012569398a..59a9551cae1c65460da88d2b6b098b6c597a6f74 100644 --- a/linter-4.2/docs/rules/recipe126.md +++ b/linter-4.2/docs/rules/recipe126.md @@ -48,8 +48,8 @@ Use regular ``export`` / ``import`` instead. ## See also -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) +- Recipe 121: ``require`` and ``import`` assignment are not supported (``arkts-no-require``) - Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) -- Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) +- Recipe 125: Re-exporting is supported with restrictions (``arkts-limited-reexport``) diff --git a/linter-4.2/docs/rules/recipe127.md b/linter-4.2/docs/rules/recipe127.md index 0a307add90b19cecdc701c9f42296c71ee8adc96..c89d24fbac4b50b1e68937ea99e7e979ae8c1452 100644 --- a/linter-4.2/docs/rules/recipe127.md +++ b/linter-4.2/docs/rules/recipe127.md @@ -1,11 +1,11 @@ -# Special export type declarations are not supported +# Special ``export type`` declarations are not supported Rule ``arkts-no-special-exports`` **Severity: error** -ArkTS does not have a special notation for exporting types. -Use ordinary export instead. +ArkTS does not have a special notation for exporting types through +``export type ...``. Use ordinary export instead. ## TypeScript @@ -13,8 +13,18 @@ Use ordinary export instead. ``` - class C {} - export type { C } + // Explicitly exported class: + export class Class1 { + // ... + } + + // Declared class later exported through export type ... + class Class2 { + // ... + } + + // This is not supported: + export type { Class2 } ``` @@ -23,7 +33,15 @@ Use ordinary export instead. ``` - export class C {} + // Explicitly exported class: + export class Class1 { + // ... + } + + // Explicitly exported class: + export class Class2 { + // ... + } ``` diff --git a/linter-4.2/docs/rules/recipe13.md b/linter-4.2/docs/rules/recipe13.md index 768c3f27ca3dfa94b5e6f3b79ab23a9b09c07a4f..1fcf6c6f558b41d7a10c0cd6e0727163cb3bb4e3 100644 --- a/linter-4.2/docs/rules/recipe13.md +++ b/linter-4.2/docs/rules/recipe13.md @@ -30,8 +30,4 @@ Currently, ArkTS does not support tuples. You can use arrays of ``Object`` ``` -## See also - -- Recipe 013: Use ``Object[]`` instead of tuples (``arkts-no-tuples``) - diff --git a/linter-4.2/docs/rules/recipe137.md b/linter-4.2/docs/rules/recipe137.md index 2ba40ccc7fc7f2621f31772463274d8925b709db..588cc70f46e523414ec8c99dc61aad374f963c14 100644 --- a/linter-4.2/docs/rules/recipe137.md +++ b/linter-4.2/docs/rules/recipe137.md @@ -39,5 +39,6 @@ objects with dynamically changed layout are not supported. ## See also - Recipe 139: Declaring properties on functions is not supported (``arkts-no-func-props``) +- Recipe 144: Usage of standard library is restricted (``arkts-limited-stdlib``) diff --git a/linter-4.2/docs/rules/recipe138.md b/linter-4.2/docs/rules/recipe138.md index d0f2210810806965fd1508d07e8f899ffe289f65..f97ec50ae8cf49b9c6d2ed321ed69e7603f3f779 100644 --- a/linter-4.2/docs/rules/recipe138.md +++ b/linter-4.2/docs/rules/recipe138.md @@ -1,12 +1,12 @@ -# Utility types are not supported +# Some of utility types are not supported Rule ``arkts-no-utility-types`` **Severity: error** Currently ArkTS does not support utility types from TypeScript extensions to the -standard library (``Omit``, ``Partial``, ``Readonly``, ``Record``, ``Pick``, -etc.). +standard library (``Omit``, ``Pick``, etc.). Exceptions are: ``Partial``, +``Record``. ## TypeScript diff --git a/linter-4.2/docs/rules/recipe139.md b/linter-4.2/docs/rules/recipe139.md index 3477c74442cfda4a6b751b12c0686235d2a394cc..5b27d1ebfa1009bd3986a339da8172aec5b19fef 100644 --- a/linter-4.2/docs/rules/recipe139.md +++ b/linter-4.2/docs/rules/recipe139.md @@ -18,7 +18,10 @@ this rule and their layout cannot be changed in runtime. // ... } - function readImage(path: string, callback: (err: any, image: MyImage) => void) { + function readImage( + path: string, callback: (err: any, image: MyImage) => void + ) + { // ... } @@ -46,7 +49,10 @@ this rule and their layout cannot be changed in runtime. // ... } - function readImage(path: string, callback: (err: Error, image: MyImage) => void) : Promise { + function readImage( + path: string, callback: (err: Error, image: MyImage) => void + ) : Promise + { // async implementation } diff --git a/linter-4.2/docs/rules/recipe142.md b/linter-4.2/docs/rules/recipe142.md index af28e8ef855fd735d00f18701fed5c30dda5c270..cca78dc76637bdb0eda7fa5750cb6a3bc51bc497 100644 --- a/linter-4.2/docs/rules/recipe142.md +++ b/linter-4.2/docs/rules/recipe142.md @@ -46,3 +46,5 @@ does not support literal types. } ``` + + diff --git a/linter-4.2/docs/rules/recipe144.md b/linter-4.2/docs/rules/recipe144.md new file mode 100644 index 0000000000000000000000000000000000000000..7a2ed2363221289e447529fe31ec777d25d39e44 --- /dev/null +++ b/linter-4.2/docs/rules/recipe144.md @@ -0,0 +1,54 @@ +# Usage of standard library is restricted + +Rule ``arkts-limited-stdlib`` + +**Severity: error** + +ArkTS does not allow usage of some APIs from the TypeScript/JavaScript standard library. +The most part of the restricted APIs relates to manipulating objects in +dynamic manner, which is not compatible with the static typing. Following APIs +are prohibited from usage: + +Properties and functions of the global object: ``eval``, +``Infinity``, ``NaN``, ``isFinite``, ``isNaN``, ``parseFloat``, ``parseInt``, +``encodeURI``, ``encodeURIComponent``, ``Encode``, +``decodeURI``, ``decodeURIComponent``, ``Decode``, +``escape``, ``unescape``, ``ParseHexOctet`` + +``Object``: ``__proto__``, ``__defineGetter__``, ``__defineSetter__``, +``__lookupGetter__``, ``__lookupSetter__``, ``assign``, ``create``, +``defineProperties``, ``defineProperty``, ``entries``, ``freeze``, +``fromEntries``, ``getOwnPropertyDescriptor``, ``getOwnPropertyDescriptors``, +``getOwnPropertyNames``, ``getOwnPropertySymbols``, ``getPrototypeOf``, +``hasOwn``, ``hasOwnProperty``, ``is``, ``isExtensible``, ``isFrozen``, +``isPrototypeOf``, ``isSealed``, ``keys``, ``preventExtensions``, +``propertyIsEnumerable``, ``seal``, ``setPrototypeOf``, ``values`` + +``Reflect``: ``apply``, ``construct``, ``defineProperty``, ``deleteProperty``, +``get``, ``getOwnPropertyDescriptor``, ``getPrototypeOf``, ``has``, +``isExtensible``, ``ownKeys``, ``preventExtensions``, ``set``, +``setPrototypeOf`` + +``Proxy``: ``handler.apply()``, ``handler.construct()``, +``handler.defineProperty()``, ``handler.deleteProperty()``, ``handler.get()``, +``handler.getOwnPropertyDescriptor()``, ``handler.getPrototypeOf()``, +``handler.has()``, ``handler.isExtensible()``, ``handler.ownKeys()``, +``handler.preventExtensions()``, ``handler.set()``, ``handler.setPrototypeOf()`` + +``Array``: ``isArray`` + +``ArrayBuffer``: ``isView`` + + +## 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 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 137: ``globalThis`` is not supported (``arkts-no-globalthis``) + + diff --git a/linter-4.2/docs/rules/recipe145.md b/linter-4.2/docs/rules/recipe145.md new file mode 100644 index 0000000000000000000000000000000000000000..37e7be51f165a952926ccaf4efa3e2876798a817 --- /dev/null +++ b/linter-4.2/docs/rules/recipe145.md @@ -0,0 +1,56 @@ +# Strict type checking is enforced + +Rule ``arkts-strict-typing`` + +**Severity: error** + +Type checker in ArkTS is not optional, the code must be explicitly and +correctly types to be compiled and run. When porting from the standard TypeScript, +following flags should be turned on: ``noImplicitReturns``, +``strictFunctionTypes``, ``strictNullChecks``, ``strictPropertyInitialization``. + + +## TypeScript + + +``` + + class C { + n: number + s: string + } + + function foo(s: string): string { + console.log(s) + } + + let n: number = null + +``` + +## ArkTS + + +``` + + class C { + n: number = 0 + s: string = "" + } + + function foo(s: string): string { + console.log(s) + return s + } + + let n1: number | null = null + let n2: number = 0 + +``` + +## See also + +- Recipe 008: Use explicit types instead of ``any``, ``unknown`` (``arkts-no-any-undefined-unknown``) +- Recipe 146: Switching off type checks with in-place comments is not allowed (``arkts-strict-typing-required``) + + diff --git a/linter-4.2/docs/rules/recipe146.md b/linter-4.2/docs/rules/recipe146.md new file mode 100644 index 0000000000000000000000000000000000000000..f00a66b1563b5c3d4fac8f031a578988df342655 --- /dev/null +++ b/linter-4.2/docs/rules/recipe146.md @@ -0,0 +1,44 @@ +# Switching off type checks with in-place comments is not allowed + +Rule ``arkts-strict-typing-required`` + +**Severity: error** + +Type checker in ArkTS is not optional, the code must be explicitly and +correctly types to be compiled and run. "Suppressing" type checker in-place +with special comments is not allowed. In particular, ``@ts-ignore`` and +``@ts-nocheck`` annotations are not supported. + + +## TypeScript + + +``` + + // @ts-nocheck + // ... + // Some code with switched off type checker + // ... + + // @ts-ignore + let s1: string = null // No error, type checker suppressed + let s2: string = null // Compile-time error + +``` + +## ArkTS + + +``` + + let s1: string | null = null // No error, properly types + let s2: string = null // Compile-time error + +``` + +## See also + +- Recipe 008: Use explicit types instead of ``any``, ``unknown`` (``arkts-no-any-undefined-unknown``) +- Recipe 145: Strict type checking is enforced (``arkts-strict-typing``) + + diff --git a/linter-4.2/docs/rules/recipe147.md b/linter-4.2/docs/rules/recipe147.md new file mode 100644 index 0000000000000000000000000000000000000000..6a81f41c8e315e4530e5fe285ca02d2cbbf24414 --- /dev/null +++ b/linter-4.2/docs/rules/recipe147.md @@ -0,0 +1,27 @@ +# No dependencies on |TS| code are currently allowed + +Rule ``arkts-no-ts-deps`` + +**Severity: error** + +Code base implemented in the standard TypeScript currently should not depend on ArkTS +through importing ArkTS code base. Imports in reverse direction are supported. + + +## TypeScript + + +``` + + // app.ets + export class C { + // ... + } + + // lib.ts + import { C } from "app" + +``` + + + diff --git a/linter-4.2/docs/rules/recipe2.md b/linter-4.2/docs/rules/recipe2.md index 2073d6c6379345939f5dcabf87a40751faa8c73e..623cbff522305e062b19fe33f58679239e9afd37 100644 --- a/linter-4.2/docs/rules/recipe2.md +++ b/linter-4.2/docs/rules/recipe2.md @@ -37,12 +37,13 @@ and cannot be changed at runtime. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-identifiers-as-prop-names``) - 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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/recipe21.md b/linter-4.2/docs/rules/recipe21.md index 75024ca7b7cb8e5a703fe15eb93a1cf1e746ea3a..942907dfd37e059fd9be40444f1c8465ae72c83d 100644 --- a/linter-4.2/docs/rules/recipe21.md +++ b/linter-4.2/docs/rules/recipe21.md @@ -1,6 +1,6 @@ -# Returning ``this`` type is not supported +# Type notation using ``this`` is not supported -Rule ``arkts-no-this-as-return-type`` +Rule ``arkts-no-typing-with-this`` **Severity: error** @@ -16,6 +16,14 @@ ArkTS does not support the returning ``this`` type. Use explicit type instead. getHead(): this } + class C { + n: number = 0 + + m(c: this) { + console.log(c) + } + } + ``` ## ArkTS @@ -27,6 +35,14 @@ ArkTS does not support the returning ``this`` type. Use explicit type instead. getHead(): ListItem } + class C { + n: number = 0 + + m(c: C) { + console.log(c) + } + } + ``` diff --git a/linter-4.2/docs/rules/recipe22.md b/linter-4.2/docs/rules/recipe22.md index 0b3bb748d5c820ab1dfd0ad2f553fc558ea78e4a..1ea9a18cba4a8c3a8266404deeb4813963df4313 100644 --- a/linter-4.2/docs/rules/recipe22.md +++ b/linter-4.2/docs/rules/recipe22.md @@ -31,7 +31,8 @@ keyword is not supported. // Rewrite with Object. Less type control, need more type checks for safety type X2 = Object - // Item has to be used as a generic parameter and need to be properly instantiated + // Item has to be used as a generic parameter and need to be properly + // instantiated type YI> = Item ``` diff --git a/linter-4.2/docs/rules/recipe3.md b/linter-4.2/docs/rules/recipe3.md index 94348f064adbc7dcd3bfd09f7fd1326e87573f6d..3611a35c26e4a565c3d896bae9d7ca0fa7ccec3c 100644 --- a/linter-4.2/docs/rules/recipe3.md +++ b/linter-4.2/docs/rules/recipe3.md @@ -13,9 +13,12 @@ keyword instead. ``` + /* + * Such notation for private fields is not supported: class C { - foo = 1 + #foo: number = 42 } + */ ``` @@ -25,10 +28,9 @@ keyword instead. ``` class C { - private foo = 1 + private foo: number = 42 } - ``` diff --git a/linter-4.2/docs/rules/recipe31.md b/linter-4.2/docs/rules/recipe31.md index cf4767dff52c99bc15141315ed1d00ca61c36dd1..bd8337a3c10d6777cb8de0336f455a571071136f 100644 --- a/linter-4.2/docs/rules/recipe31.md +++ b/linter-4.2/docs/rules/recipe31.md @@ -66,11 +66,11 @@ instead. let x = new X() let y = new Y() - console.log("Assign X to Y") - y = x // ok, X is the super class of X + console.log("Assign Y to X") + x = y // ok, X is the super class of Y - // Cannot assign Y to X - //x = y - compile-time error + // Cannot assign X to Y + //y = x - compile-time error ``` diff --git a/linter-4.2/docs/rules/recipe34.md b/linter-4.2/docs/rules/recipe34.md index a1306d50a30a26a470cf8bdf9f05b636484e00d5..c1536ee24c555c21ca85b3406ef7b71f8e1b2a7c 100644 --- a/linter-4.2/docs/rules/recipe34.md +++ b/linter-4.2/docs/rules/recipe34.md @@ -1,12 +1,13 @@ -# Generic functions must be called with explicit type specialization +# Type inference in case of generic function calls is limited Rule ``arkts-no-inferred-generic-params`` -**Severity: warning** +**Severity: error** -Currently, ArkTS does not support inference of type parameters in case of calls -to generic functions. If a function is declared generic, all calls must specify -type parameters explicitly. +ArkTS allows to omit generic type parameters if it is possible to infer +the concrete types from the parameters passed to the function. Otherwise a +compile-time error occurs. In particular, inference of generic type parameters +based only on function return types is prohibited. ## TypeScript @@ -18,9 +19,14 @@ type parameters explicitly. return Math.random() < 0.5 ? x : y } - let x = choose(10, 20) // Ok + let x = choose(10, 20) // OK, choose(...) is inferred let y = choose("10", 20) // Compile-time error + function greet(): T { + return "Hello" as T + } + let z = greet() // Type of x is inferred as "unknown" + ``` ## ArkTS @@ -32,8 +38,13 @@ type parameters explicitly. return Math.random() < 0.5 ? x : y } - let x = choose(10, 20) // Ok - let y = choose("10", 20) // Compile-time error + let x = choose(10, 20) // OK, choose(...) is inferred + let y = choose("10", 20) // Compile-time error + + function greet(): T { + return "Hello" as T + } + let z = greet() ``` diff --git a/linter-4.2/docs/rules/recipe38.md b/linter-4.2/docs/rules/recipe38.md index b508aad3119ee0b9a79e4b1d66cdefea6da6f3f4..62b06f7a93706c30e1481c1c77d94e2a7bf8bc96 100644 --- a/linter-4.2/docs/rules/recipe38.md +++ b/linter-4.2/docs/rules/recipe38.md @@ -1,14 +1,18 @@ -# Object literal must correspond to explicitly declared class or interface +# Object literal must correspond to some explicitly declared class or interface Rule ``arkts-no-untyped-obj-literals`` **Severity: error** -ArkTS supports the usage of object literals if the compiler can infer -to what classes or interfaces such literals correspond to. -Otherwise, a compile-time error occurs. +ArkTS supports usage of object literals if the compiler can infer to what +classes or interfaces such literals correspond to. Otherwise, a compile-time +error occurs. Specifically, using literals to initialize classes and interfaces +is not supported in following contexts: -The class or interface can be specified as a type annotation for a variable. +* Initialization of anything that has ``any``, ``Object``, or ``object`` type +* Initialization of classes or interfaces with methods +* Initialization of classes which declare a ``constructor`` with parameters +* Initialization of classes with ``readonly`` fields ## TypeScript @@ -16,7 +20,53 @@ The class or interface can be specified as a type annotation for a variable. ``` - let x = {f: 1} + let o1 = {n: 42, s: "foo"} + let o2: Object = {n: 42, s: "foo"} + let o3: object = {n: 42, s: "foo"} + + let oo: Object[] = [{n: 1, s: "1"}, {n: 2, s: "2"}] + + class C2 { + s: string + constructor(s: string) { + this.s = "s =" + s + } + } + let o4: C2 = {s: "foo"} + + class C3 { + readonly n: number = 0 + readonly s: string = "" + } + let o5: C3 = {n: 42, s: "foo"} + + abstract class A {} + let o6: A = {} + + class C4 { + n: number = 0 + s: string = "" + f() { + console.log("Hello") + } + } + let o7: C4 = {n: 42, s: "foo", f : () => {}} + + class Point { + x: number = 0 + y: number = 0 + } + + function id_x_y(o: Point): Point { + return o + } + + // Structural typing is used to deduce that p is Point: + let p = {x: 5, y: 10} + id_x_y(p) + + // A literal can be contextually (i.e., implicitly) typed as Point: + id_x_y({x: 5, y: 10}) ``` @@ -25,19 +75,72 @@ The class or interface can be specified as a type annotation for a variable. ``` - class O { - f: number + class C1 { + n: number = 0 + s: string = "" } - let x: O = {f: 1} // OK - let y = {f: 1} // Compile-time error, cannot infer object literal type - let z: Object = {f: 2} // Compile-time error, class 'Object' does not have field 'f' + let o1: C1 = {n: 42, s: "foo"} + let o2: C1 = {n: 42, s: "foo"} + let o3: C1 = {n: 42, s: "foo"} + + let oo: C1[] = [{n: 1, s: "1"}, {n: 2, s: "2"}] + + class C2 { + s: string + constructor(s: string) { + this.s = "s =" + s + } + } + let o4 = new C2("foo") + + class C3 { + n: number = 0 + s: string = "" + } + let o5: C3 = {n: 42, s: "foo"} + + abstract class A {} + class C extends A {} + let o6: C = {} // or let o6: C = new C() + + class C4 { + n: number = 0 + s: string = "" + f() { + console.log("Hello") + } + } + let o7 = new C4() + o7.n = 42 + o7.s = "foo" + + class Point { + x: number = 0 + y: number = 0 + + // constructor() is used before literal initialization + // to create a valid object. Since there is no other Point constructors, + // constructor() is automatically added by compiler + } + + function id_x_y(o: Point): Point { + return o + } + + // Explicit type is required for literal initialization + let p: Point = {x: 5, y: 10} + id_x_y(p) + + // id_x_y expects Point explicitly + // New instance of Point is initialized with the literal + id_x_y({x: 5, y: 10}) ``` ## See also - Recipe 040: Object literals cannot be used as type declarations (``arkts-no-obj-literals-as-types``) -- Recipe 043: Untyped array literals are not supported (``arkts-no-noninferrable-arr-literals``) +- Recipe 043: Array literals must contain elements of only inferrable types (``arkts-no-noninferrable-arr-literals``) diff --git a/linter-4.2/docs/rules/recipe40.md b/linter-4.2/docs/rules/recipe40.md index 0e70ca7c421b11e525f6f6bbb6cc6d7bef79eb18..9fd22580fbf472bf9bebc48b03bca25c45d5cced 100644 --- a/linter-4.2/docs/rules/recipe40.md +++ b/linter-4.2/docs/rules/recipe40.md @@ -40,7 +40,7 @@ types in place. Declare classes and interfaces explicitly instead. ## See also -- Recipe 038: Object literal must correspond to explicitly declared class or interface (``arkts-no-untyped-obj-literals``) -- Recipe 043: Untyped array literals are not supported (``arkts-no-noninferrable-arr-literals``) +- Recipe 038: Object literal must correspond to some explicitly declared class or interface (``arkts-no-untyped-obj-literals``) +- Recipe 043: Array literals must contain elements of only inferrable types (``arkts-no-noninferrable-arr-literals``) diff --git a/linter-4.2/docs/rules/recipe43.md b/linter-4.2/docs/rules/recipe43.md index bead8fbfd998729a8d5d82cce9cc583aac374f7b..e7257c77bf3037ae9ee155289e77b27aedb93be2 100644 --- a/linter-4.2/docs/rules/recipe43.md +++ b/linter-4.2/docs/rules/recipe43.md @@ -1,12 +1,12 @@ -# Untyped array literals are not supported +# Array literals must contain elements of only inferrable types Rule ``arkts-no-noninferrable-arr-literals`` **Severity: error** -ArkTS does not support the usage of untyped array literals. The type of an -array element must be inferred from the context. Use the type ``Object`` to -define mixed types array. +Basically, ArkTS infers the type of an array literal as a union type of its +contents. But if there is at least one element with a non-inferrable type +(e.g. untyped object literal), a compile-time error occurs. ## TypeScript @@ -14,8 +14,7 @@ define mixed types array. ``` - let x1 = [1, 2] - let x2 = [1, "aa"] + let a = [{n: 1, s: "1"}, {n: 2, s : "2"}] ``` @@ -24,19 +23,19 @@ define mixed types array. ``` - let x1: Object[] = [new Number(1), new Number(2)] + class C { + n: number = 0 + s: string = "" + } - // Implicit boxing of numbers to the object type Number - let x2: Object[] = [1, 2] - - // Implicit boxing of number and string to the object types Number and String - let x3: Object[] = [1, "aa"] + let a1 = [{n: 1, s: "1"} as C, {n: 2, s : "2"} as C] // a1 is of type "C[]" + let a2: C[] = [{n: 1, s: "1"}, {n: 2, s : "2"}] // ditto ``` ## See also -- Recipe 038: Object literal must correspond to explicitly declared class or interface (``arkts-no-untyped-obj-literals``) +- Recipe 038: Object literal must correspond to some explicitly declared class or interface (``arkts-no-untyped-obj-literals``) - Recipe 040: Object literals cannot be used as type declarations (``arkts-no-obj-literals-as-types``) diff --git a/linter-4.2/docs/rules/recipe46.md b/linter-4.2/docs/rules/recipe46.md index 172b344e07d7734b887dd08b255767ff1bdce65b..71fcbf8a1fd450b512787156f304591e859c1033 100644 --- a/linter-4.2/docs/rules/recipe46.md +++ b/linter-4.2/docs/rules/recipe46.md @@ -2,7 +2,7 @@ Rule ``arkts-no-func-expressions`` -**Severity: warning** +**Severity: error** ArkTS does not support function expressions, use arrow functions instead to be explicitly specified. diff --git a/linter-4.2/docs/rules/recipe52.md b/linter-4.2/docs/rules/recipe52.md index 59d298a8751b1f1e710046465331813935c0985e..91042ae7740cc4270ead455db209cd7b71fe9219 100644 --- a/linter-4.2/docs/rules/recipe52.md +++ b/linter-4.2/docs/rules/recipe52.md @@ -47,12 +47,13 @@ existence during compilation. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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/recipe55.md b/linter-4.2/docs/rules/recipe55.md index ee9cd5900b116bfbebc47811dfef939ba739fbbd..2b47bb52508ab4a126c165b41a62693b86879c9b 100644 --- a/linter-4.2/docs/rules/recipe55.md +++ b/linter-4.2/docs/rules/recipe55.md @@ -30,11 +30,11 @@ be done explicitly. ``` - let a = +5 // 5 as int + let a = +5 // 5 as number let b = +"5" // Compile-time error - let c = -5 // -5 as int + let c = -5 // -5 as number let d = -"5" // Compile-time error - let e = ~5 // -6 as int + let e = ~5 // -6 as number let f = ~"5" // Compile-time error let g = +"string" // Compile-time error @@ -42,7 +42,6 @@ be done explicitly. ## See also -- Recipe 055: Unary operators ``+``, ``-`` and ``~`` work only on numbers (``arkts-no-polymorphic-unops``) - Recipe 061: Binary operators ``*``, ``/``, ``%``, ``-``, ``<<``, ``>>``, ``>>>``, ``&``, ``^`` and ``|`` work only on numeric types (``arkts-no-polymorphic-binops``) - Recipe 063: Binary ``+`` operator supports implicit casts only for numbers and strings (``arkts-no-polymorphic-plus``) diff --git a/linter-4.2/docs/rules/recipe59.md b/linter-4.2/docs/rules/recipe59.md index a00c6cf88924cec5c1f84a0fd41af62eb695ee67..d64602e17550c8857100b5de5897a415472d816e 100644 --- a/linter-4.2/docs/rules/recipe59.md +++ b/linter-4.2/docs/rules/recipe59.md @@ -43,10 +43,10 @@ changed at runtime. Thus the operation of deleting a property makes no sense. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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 060: ``typeof`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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``) diff --git a/linter-4.2/docs/rules/recipe60.md b/linter-4.2/docs/rules/recipe60.md index 2898c87889989af124b0167ff9c2a9091171f411..38b6ca476730f4d5c1513353841f055db04ad590 100644 --- a/linter-4.2/docs/rules/recipe60.md +++ b/linter-4.2/docs/rules/recipe60.md @@ -1,11 +1,11 @@ -# ``typeof`` is allowed only in expression contexts +# ``typeof`` operator is allowed only in expression contexts Rule ``arkts-no-type-query`` **Severity: error** -ArkTS supports ``typeof`` operator only in the expression context. -Type notation with ``typeof`` is not supported. +ArkTS supports ``typeof`` operator only in the expression context. Specifying +type notations using ``typeof`` is not supported. ## TypeScript @@ -38,12 +38,13 @@ Type notation with ``typeof`` is not supported. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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 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/recipe61.md b/linter-4.2/docs/rules/recipe61.md index ff56af6b74428344cd9d7724c63f2ad88796ad14..e5bdfd14abd026bf364762ae3044274ce249ec5a 100644 --- a/linter-4.2/docs/rules/recipe61.md +++ b/linter-4.2/docs/rules/recipe61.md @@ -48,7 +48,7 @@ compile-time errors. let d = (5.5 | 5.5) // Compile-time error enum Direction { - Up, // TBD: explicit start value + Up, Down } diff --git a/linter-4.2/docs/rules/recipe66.md b/linter-4.2/docs/rules/recipe66.md index 0b689e1b22a6530a22a7a29caeecc93e4ad61c38..10476f234c5e3f9161ff50e15ffff354d473b17f 100644 --- a/linter-4.2/docs/rules/recipe66.md +++ b/linter-4.2/docs/rules/recipe66.md @@ -40,12 +40,13 @@ to check whether certain class members exist. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- Recipe 060: ``typeof`` operator is allowed only in expression contexts (``arkts-no-type-query``) - 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/recipe71.md b/linter-4.2/docs/rules/recipe71.md index dacc10297860b5057e60a2cef71315a50042002b..569b48bb2181272a7cbacccc150b3d4d362e82a9 100644 --- a/linter-4.2/docs/rules/recipe71.md +++ b/linter-4.2/docs/rules/recipe71.md @@ -14,7 +14,8 @@ it is useless as it makes the execution order harder to understand. ``` for (let i = 0, j = 0; i < 10; ++i, j += 2) { - console.log(i, j) + console.log(i) + console.log(j) } let x = 0 @@ -28,7 +29,8 @@ it is useless as it makes the execution order harder to understand. ``` for (let i = 0, j = 0; i < 10; ++i, j += 2) { - console.log(i, j) + console.log(i) + console.log(j) } // Use explicit execution order instead of the comma operator: diff --git a/linter-4.2/docs/rules/recipe8.md b/linter-4.2/docs/rules/recipe8.md index 4c4e1056c8d0ceb027606f125567e6c8d8ce8e7b..fd3e9e1004eb6050b4aff873026d39400e7bfc5b 100644 --- a/linter-4.2/docs/rules/recipe8.md +++ b/linter-4.2/docs/rules/recipe8.md @@ -1,11 +1,11 @@ -# Use explicit types instead of ``any``, ``undefined``, ``unknown`` +# Use explicit types instead of ``any``, ``unknown`` Rule ``arkts-no-any-undefined-unknown`` **Severity: error** -ArkTS does not support ``any``, ``undefined``, and ``unknown`` types. -Specify types explicitly. +ArkTS does not support ``any``, and ``unknown`` types. Please specify types +explicitly. ## TypeScript @@ -13,11 +13,13 @@ Specify types explicitly. ``` - var x - console.log(x) // undefined + let value1 : any + value1 = true + value1 = 42 - var y: any - console.log(y) // undefined + let value2 : unknown + value2 = true + value2 = 42 ``` @@ -26,14 +28,16 @@ Specify types explicitly. ``` - // All variables should have their types specified explicitly: - let x: Object = {} - console.log(x) // {} + let value_b: boolean = true // OR: let value_b = true + let value_n: number = 42 // OR: let value_n = 42 + let value_o1: Object = true + let value_o2: Object = 42 ``` ## See also - Recipe 013: Use ``Object[]`` instead of tuples (``arkts-no-tuples``) +- Recipe 145: Strict type checking is enforced (``arkts-strict-typing``) diff --git a/linter-4.2/docs/rules/recipe82.md b/linter-4.2/docs/rules/recipe82.md index 1bd77d93184adb46de660eb2550dbfeb02ebfe94..e6c28d9b6e920d1273549292c5de2f583899af51 100644 --- a/linter-4.2/docs/rules/recipe82.md +++ b/linter-4.2/docs/rules/recipe82.md @@ -26,7 +26,7 @@ but does not support the iteration of objects content. ``` let a: Set = new Set([1, 2, 3]) - let numbers = a.values() + let numbers = Array.from(a.values()) for (let n of numbers) { console.log(n) } diff --git a/linter-4.2/docs/rules/recipe83.md b/linter-4.2/docs/rules/recipe83.md index d642988b257715b89866137d0b4c62f888f0b915..3eedbaee4815cfa5dc9a6b6244954f1617018970 100644 --- a/linter-4.2/docs/rules/recipe83.md +++ b/linter-4.2/docs/rules/recipe83.md @@ -19,8 +19,25 @@ classes to achieve the same behaviour. ``` +## ArkTS + + +``` + + class C { + n: number = 0 + s: string = "" + } + + class CFlags { + n: boolean = false + s: boolean = false + } + +``` + ## See also -- Recipe 097: `keyof` operator is not supported (``arkts-no-keyof``) +- Recipe 097: ``keyof`` operator is not supported (``arkts-no-keyof``) diff --git a/linter-4.2/docs/rules/recipe86.md b/linter-4.2/docs/rules/recipe86.md index d57436d82172fe082702ce8fc4bb83fcd2cc7b21..9daf45688e5347bf711f605df2629598e392f884 100644 --- a/linter-4.2/docs/rules/recipe86.md +++ b/linter-4.2/docs/rules/recipe86.md @@ -4,9 +4,9 @@ Rule ``arkts-limited-switch`` **Severity: error** -ArkTS supports the values of the types ``char``, ``byte``, ``short``, ``int``, -``long``, ``Char``, ``Byte``, ``Short``, ``Int``, ``Long``, ``String`` or -``enum`` in ``switch`` statements. Use ``if`` statements in other cases. +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 diff --git a/linter-4.2/docs/rules/recipe90.md b/linter-4.2/docs/rules/recipe90.md index 5ee2428f2f1b791661da38f6bd1a6cdbd294ee67..0613f6913d23d1eef21feed846cb1e9e10136829 100644 --- a/linter-4.2/docs/rules/recipe90.md +++ b/linter-4.2/docs/rules/recipe90.md @@ -49,8 +49,8 @@ explicitly. return g(x) } - // Explicit return type is required: - function g(x: number) : number { + // Return type may be omitted, it is inferred from f's explicit type: + function g(x: number) { return f(x - 1) } diff --git a/linter-4.2/docs/rules/recipe94.md b/linter-4.2/docs/rules/recipe94.md index eeba93be5520fa34fe5bf5523fa5156b46b6546b..8f350dc7fe2cdebaf150ae48c2af4bc0e67cb4cd 100644 --- a/linter-4.2/docs/rules/recipe94.md +++ b/linter-4.2/docs/rules/recipe94.md @@ -30,10 +30,19 @@ Use the ``async`` / ``await`` mechanism for multitasking. ``` - for (let i = 1; i <= 5; ++i) { - console.log(i) + async function complexNumberProcessing(n : number) : Promise { + // Some complex logic for proccessing the number here + return n } + async function foo() { + for (let i = 1; i <= 5; i++) { + console.log(await complexNumberProcessing(i)) + } + } + + foo() + ``` diff --git a/linter-4.2/docs/rules/recipe97.md b/linter-4.2/docs/rules/recipe97.md index c82350448ea9e66b4c30ebd0572f0eef32867cd0..0ba7f3db02c7cd1a15c05e1a73716bc6901df415 100644 --- a/linter-4.2/docs/rules/recipe97.md +++ b/linter-4.2/docs/rules/recipe97.md @@ -1,4 +1,4 @@ -# `keyof` operator is not supported +# ``keyof`` operator is not supported Rule ``arkts-no-keyof`` @@ -49,7 +49,6 @@ accessed directly. return obj.y } throw new Error() // No such property - return 0 } function main(): void { diff --git a/linter-4.2/docs/rules/recipe99.md b/linter-4.2/docs/rules/recipe99.md index 094f6841e22c9c6f545e244ac3c79de8dc00009e..23349a239547a94390ff82ff5f94c484d00727a1 100644 --- a/linter-4.2/docs/rules/recipe99.md +++ b/linter-4.2/docs/rules/recipe99.md @@ -40,13 +40,12 @@ where necessary. res += n return res } + console.log(sum_numbers(1, 2, 3)) function log_numbers(x : number, y : number, z : number) { console.log(x, y, z) } - - let numbers : number[] = [0, 1, 2] - sum_numbers(...numbers) + let numbers: number[] = [1, 2, 3] log_numbers(numbers[0], numbers[1], numbers[2]) let list1 : number[] = [1, 2] diff --git a/linter-4.2/src/CookBookMsg.ts b/linter-4.2/src/CookBookMsg.ts index 54304c1e4f0c1ccf7acd2b93bab41a27cac16ee8..57e28c882afa5a3e0efa98ee3e4acb3ed57fbb53 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 < 144; i++) { +for( let i = 0; i < 147; i++) { cookBookMsg[ i ] = ''; } @@ -27,7 +27,7 @@ cookBookTag[ 4 ] = 'Use unique names for types, namespaces, etc. (arkts-unique-n cookBookTag[ 5 ] = 'Use "let" instead of "var" (arkts-no-var)'; cookBookTag[ 6 ] = ''; cookBookTag[ 7 ] = ''; -cookBookTag[ 8 ] = 'Use explicit types instead of "any", "undefined", "unknown" (arkts-no-any-undefined-unknown)'; +cookBookTag[ 8 ] = 'Use explicit types instead of "any", "unknown" (arkts-no-any-undefined-unknown)'; cookBookTag[ 9 ] = ''; cookBookTag[ 10 ] = '"bigint" is not a builtin type, suffix "n" for numeric literals is not supported (arkts-no-n-suffix)'; cookBookTag[ 11 ] = ''; @@ -40,10 +40,10 @@ cookBookTag[ 17 ] = 'Indexed signatures are not supported (arkts-no-indexed-sign cookBookTag[ 18 ] = ''; cookBookTag[ 19 ] = 'Use inheritance instead of intersection types (arkts-no-intersection-types)'; cookBookTag[ 20 ] = ''; -cookBookTag[ 21 ] = 'Returning "this" type is not supported (arkts-no-this-as-return-type)'; +cookBookTag[ 21 ] = 'Type notation using "this" is not supported (arkts-no-typing-with-this)'; cookBookTag[ 22 ] = 'Conditional types are not supported (arkts-no-conditional-types)'; cookBookTag[ 23 ] = ''; -cookBookTag[ 24 ] = 'Optional parameters are not supported for primitive types (arkts-no-opt-params)'; +cookBookTag[ 24 ] = ''; cookBookTag[ 25 ] = 'Declaring fields in "constructor" is not supported (arkts-no-ctor-prop-decls)'; cookBookTag[ 26 ] = ''; cookBookTag[ 27 ] = 'Construct signatures not supported in interfaces (arkts-no-ctor-signatures-iface)'; @@ -52,7 +52,7 @@ cookBookTag[ 29 ] = 'Indexed access is not supported for fields (arkts-no-props- cookBookTag[ 30 ] = 'Structural identity is not supported (arkts-no-structural-identity)'; cookBookTag[ 31 ] = 'Structural typing is not supported for subtyping / supertyping (arkts-no-structural-subtyping)'; cookBookTag[ 32 ] = 'Structural typing is not supported for assignability checks (arkts-no-structural-assignability)'; -cookBookTag[ 33 ] = 'Optional properties are not supported for primitive types (arkts-no-opt-props)'; +cookBookTag[ 33 ] = ''; cookBookTag[ 34 ] = 'Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)'; cookBookTag[ 35 ] = 'Structural typing is not supported for type inference (arkts-no-structural-inference)'; cookBookTag[ 36 ] = ''; @@ -140,13 +140,13 @@ 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[ 120 ] = '"import default as ..." is not supported (arkts-no-import-default-as)'; -cookBookTag[ 121 ] = '"require" is not supported (arkts-no-require)'; +cookBookTag[ 121 ] = '"require" and "import" assignment are not supported (arkts-no-require)'; cookBookTag[ 122 ] = ''; -cookBookTag[ 123 ] = 'Renaming in export declarations is not supported (arkts-no-export-renaming)'; +cookBookTag[ 123 ] = ''; cookBookTag[ 124 ] = 'Export list declaration is not supported (arkts-no-export-list-decl)'; -cookBookTag[ 125 ] = 'Re-exporting is not supported (arkts-no-reexport)'; +cookBookTag[ 125 ] = 'Re-exporting is supported with restrictions (arkts-limited-reexport)'; 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 ] = 'Special "export type" declarations are not supported (arkts-no-special-exports)'; 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)'; @@ -157,10 +157,13 @@ cookBookTag[ 134 ] = 'Definite assignment assertions are not supported (arkts-no cookBookTag[ 135 ] = 'IIFEs as namespace declarations are not supported (arkts-no-iife)'; cookBookTag[ 136 ] = 'Prototype assignment is not supported (arkts-no-prototype-assignment)'; cookBookTag[ 137 ] = '"globalThis" is not supported (arkts-no-globalthis)'; -cookBookTag[ 138 ] = 'Utility types are not supported (arkts-no-utility-types)'; +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[ 141 ] = '"readonly T[]" syntax is not supported (arkts-no-readonly-params)'; 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[ 147 ] = 'No dependencies on TypeScript code are currently allowed (arkts-no-ts-deps)'; diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index 8b66eaebe31faaa84792a5a14cd3672f261391d5..ace430886a2d0790c9c3ffd5240653377b865904 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -651,6 +651,9 @@ export class TypeScriptLinter { if (this.isIIFEasNamespace(propertyAccessNode)) this.incrementCounters(node, FaultID.IifeAsNamespace); if (this.isPrototypePropertyAccess(propertyAccessNode)) this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); + let symbol = TypeScriptLinter.tsTypeChecker.getSymbolAtLocation(propertyAccessNode); + if( !!symbol && Utils.isSymbolAPI(symbol)) + this.incrementCounters(node, FaultID.SymbolType); } private handlePropertyAssignmentOrDeclaration(node: ts.Node) { @@ -1375,6 +1378,9 @@ export class TypeScriptLinter { ) { this.incrementCounters(callExpr, FaultID.LimitedStdLibApi); } + if( Utils.isSymbolAPI(sym)) { + this.incrementCounters(callExpr, FaultID.SymbolType); + } } } diff --git a/linter-4.2/src/Utils.ts b/linter-4.2/src/Utils.ts index b40296037ce0b4d2e3943dd3561180bf52af2559..4206677b4e2463ed68e94a005052045634f1671f 100644 --- a/linter-4.2/src/Utils.ts +++ b/linter-4.2/src/Utils.ts @@ -720,6 +720,15 @@ export function isStdArrayBufferAPI(symbol: ts.Symbol): boolean { return !!parentName && (parentName === 'ArrayBuffer' || parentName === 'ArrayBufferConstructor'); } +export function isSymbolAPI(symbol: ts.Symbol): boolean { + let parentName = getParentSymbolName(symbol); + if( !!parentName ) + return (parentName === 'Symbol' || parentName === 'SymbolConstructor'); + else + return ( symbol.escapedName === 'Symbol' || symbol.escapedName === 'SymbolConstructor'); +} + + export function hasAccessModifier(decl: ts.Declaration): boolean { let modifiers = decl.modifiers; // TSC 4.2 doesn't have 'ts.getModifiers()' method return ( diff --git a/linter-4.2/test/symbol_api.ts b/linter-4.2/test/symbol_api.ts new file mode 100644 index 0000000000000000000000000000000000000000..53ab8433431d8fa1098cb3ebafa10cd4cd2c8923 --- /dev/null +++ b/linter-4.2/test/symbol_api.ts @@ -0,0 +1,30 @@ +/* + * 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. + */ + +let a = Symbol.asyncIterator; +let b = Symbol.hasInstance; +let c = Symbol.isConcatSpreadable; +let d = Symbol.iterator; +let e = Symbol.match; +let f = Symbol.replace; +let g = Symbol.search; +let h = Symbol.species; +let i = Symbol.split; +let j = Symbol.toPrimitive; +let k = Symbol.toStringTag; +let l = Symbol.unscopables; + +let m = Symbol(); + diff --git a/linter-4.2/test/symbol_api.ts.autofix.skip b/linter-4.2/test/symbol_api.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/linter-4.2/test/symbol_api.ts.relax.json b/linter-4.2/test/symbol_api.ts.relax.json new file mode 100644 index 0000000000000000000000000000000000000000..dcdf059f710be2b98ef7132bf5adf2ec1c6ce311 --- /dev/null +++ b/linter-4.2/test/symbol_api.ts.relax.json @@ -0,0 +1,83 @@ +{ + "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": 16, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 17, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 18, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 19, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 20, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 21, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 22, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 23, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 24, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 25, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 26, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 27, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 29, + "column": 9, + "problem": "SymbolType" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test/symbol_api.ts.strict.json b/linter-4.2/test/symbol_api.ts.strict.json new file mode 100644 index 0000000000000000000000000000000000000000..dcdf059f710be2b98ef7132bf5adf2ec1c6ce311 --- /dev/null +++ b/linter-4.2/test/symbol_api.ts.strict.json @@ -0,0 +1,83 @@ +{ + "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": 16, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 17, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 18, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 19, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 20, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 21, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 22, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 23, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 24, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 25, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 26, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 27, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 29, + "column": 9, + "problem": "SymbolType" + } + ] +} \ No newline at end of file diff --git a/linter/cookbook_convertor/md/recipe115.md b/linter/cookbook_convertor/md/recipe115.md index b7ed86e5f2733a979db425cc239c2fc5ea22e15e..813638578b2ba644f5b7cac1d24456bf754911f9 100644 --- a/linter/cookbook_convertor/md/recipe115.md +++ b/linter/cookbook_convertor/md/recipe115.md @@ -14,7 +14,6 @@ Differences are described in separate recipes. - 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`` is not supported (``arkts-no-require``) -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) - Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) - Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) - Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) diff --git a/linter/cookbook_convertor/md/recipe123.md b/linter/cookbook_convertor/md/recipe123.md deleted file mode 100644 index 93667373868f3ab91ac6ca468f8d5bd25ec90c65..0000000000000000000000000000000000000000 --- a/linter/cookbook_convertor/md/recipe123.md +++ /dev/null @@ -1,61 +0,0 @@ -# Renaming in export declarations is not supported - -Rule ``arkts-no-export-renaming`` - -**Severity: error** - -ArkTS does not support renaming in export declarations. Similar effect -can be achieved through setting an alias for the exported entity. - - -## TypeScript - - -``` - - // file1.ts - class MyClass { - // ... - } - - export { MyClass as RenamedClass } - - // file2.ts - import { RenamedClass } from "./file1" - - function main(): void { - const myObject = new RenamedClass() - // ... - } - -``` - -## ArkTS - - -``` - - // module1 - class MyClass { - // ... - } - - export type RenamedClass = MyClass - - // module2 - import { RenamedClass } from "./module1" - - function main(): void { - const myObject = new RenamedClass() - // ... - } - -``` - -## See also - -- Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) -- Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) -- Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) - - diff --git a/linter/cookbook_convertor/md/recipe124.md b/linter/cookbook_convertor/md/recipe124.md index d86e3f384c80fc59d1f1bc2f309421f18cffa9af..d073d262ce51cd4bd2eb833659e5792edff7a575 100644 --- a/linter/cookbook_convertor/md/recipe124.md +++ b/linter/cookbook_convertor/md/recipe124.md @@ -33,7 +33,6 @@ entities must be explicitly annotated with the ``export`` keyword. ## See also -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) - Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) - Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) diff --git a/linter/cookbook_convertor/md/recipe125.md b/linter/cookbook_convertor/md/recipe125.md index 47ee1ddd34953caa7df805a24ce9f52dc3c38497..624ff218fa166ef9d167974c1730b228b02ba28c 100644 --- a/linter/cookbook_convertor/md/recipe125.md +++ b/linter/cookbook_convertor/md/recipe125.md @@ -51,7 +51,6 @@ imported explicitly from the modules that export them. ## See also -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) - Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) - Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) diff --git a/linter/cookbook_convertor/md/recipe126.md b/linter/cookbook_convertor/md/recipe126.md index 94f88de58cd467215d24383ad9ad64012569398a..37d6fff4bd3ee40fad1b9683b24d6f9176c8ccf4 100644 --- a/linter/cookbook_convertor/md/recipe126.md +++ b/linter/cookbook_convertor/md/recipe126.md @@ -48,7 +48,6 @@ Use regular ``export`` / ``import`` instead. ## See also -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) - Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) - Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) diff --git a/linter/cookbook_convertor/md/recipe24.md b/linter/cookbook_convertor/md/recipe24.md deleted file mode 100644 index 174d840558bf5fa39a0a3acc06f8c5fb2455995c..0000000000000000000000000000000000000000 --- a/linter/cookbook_convertor/md/recipe24.md +++ /dev/null @@ -1,46 +0,0 @@ -# Optional parameters are not supported for primitive types - -Rule ``arkts-no-opt-params`` - -**Severity: error** - -ArkTS does not support optional parameters of primitive types. -You can use default parameter values or reference types. For reference types, -non-specified optional parameter is set to ``null``. - - -## TypeScript - - -``` - - // x is an optional parameter: - function f(x?: number) { - console.log(x) // log undefined or number - } - - // x is a required parameter with the default value: - function g(x: number = 1) { - console.log(x) - } - -``` - -## ArkTS - - -``` - - // You can use reference type (will be set to null if missing): - function f(x?: Number) { - console.log(x) // log null or some number - } - - // You can use a required parameter with the default value: - function g(x: number = 1) { - console.log(x) - } - -``` - - diff --git a/linter/cookbook_convertor/md/recipe33.md b/linter/cookbook_convertor/md/recipe33.md deleted file mode 100644 index 4b8adbb0738364eac0d715f7718df1f6d3858cb4..0000000000000000000000000000000000000000 --- a/linter/cookbook_convertor/md/recipe33.md +++ /dev/null @@ -1,58 +0,0 @@ -# Optional properties are not supported for primitive types - -Rule ``arkts-no-opt-props`` - -**Severity: error** - -ArkTS does not support optional properties of primitive types. You can use -properties with default values or reference types. For reference types, -non-specified optional property is set to ``null``. This rule applies both to -classes and interfaces. - - -## TypeScript - - -``` - - class CompilerOptions { - strict?: boolean - sourcePath?: string - targetPath?: string - } - - let options: CompilerOptions = { - strict: true, - sourcePath: "./src" - } - - if (options.targetPath == undefined) { - // Some logic - } - -``` - -## ArkTS - - -``` - - class CompilerOptions { - strict: boolean = false - sourcePath: string = "" - targetPath?: string - } - - let options: CompilerOptions = { - strict: true, - sourcePath: "./src" - // targetPath is implicitly set to null - } - - if (options.targetPath == null) { - // Some logic - } - -``` - - diff --git a/linter/cookbook_convertor/res/recipes.rst b/linter/cookbook_convertor/res/recipes.rst index ad0382359d2320388086e8f5eeda4c3951eef063..c8e2e289e1391db587194925f0806c4ac7cf61f1 100644 --- a/linter/cookbook_convertor/res/recipes.rst +++ b/linter/cookbook_convertor/res/recipes.rst @@ -710,49 +710,6 @@ All types must be specified explicitly. let a: A let b: A -.. _R024: - -|CB_R| #24: Optional arguments are not supported ------------------------------------------------- - -|CB_RULE| -~~~~~~~~~ - -Currently, |LANG| does not support optional parameters. Specify an -optional parameter as a parameter of a nullable type with the -default value ``null``. Default parameter values are supported for all types. - -|CB_BAD| -~~~~~~~~ - -.. code-block:: typescript - - // x is an optional parameter: - function f(x?: number) { - console.log(x) // log undefined or number - } - - // x is a required parameter with the default value: - function g(x: number = 1) { - console.log(x) - } - -|CB_OK| -~~~~~~~ - -.. code-block:: typescript - - // Optional parameters are not supported, - // but you can assign a default value ``null`` for the parameter: - function f(x: number | null = null) { - console.log(x); // log null or number - } - - // x is a required argument with the default value: - function g(x: number = 1) { - console.log(x); - } - .. _R025: |CB_R| #25: Declaring fields in ``constructor`` is not supported @@ -1120,56 +1077,6 @@ public APIs and decide whether such types are identical. Use other mechanisms * :ref:`R031` * :ref:`R035` -.. _R033: - -|CB_R| #33: Optional properties are not supported -------------------------------------------------- - -|CB_RULE| -~~~~~~~~~ - -|LANG| does not support optional properties. Use properties with default values. -Use properties of nullable types and the default ``null`` value to distinguish -whether a value is set or not. - -|CB_BAD| -~~~~~~~~ - -.. code-block:: typescript - - interface CompilerOptions { - strict?: boolean - sourcePath?: string - targetPath?: string - } - - var options: CompilerOptions = { - strict: true, - sourcepath: "./src", - } - if option.targetPath == undefined { - // set default - } - -|CB_OK| -~~~~~~~ - -.. code:: typescript - - interface CompilerOptions { - strict: boolean = false - sourcePath: string = "" - targetPath: string | null = null - } - - let options: CompilerOptions = { - strict: true, - sourcepath: "./src", - } - if option.targetPath == null { - // set default - } - .. _R034: |CB_R| #34: Generic functions must be called with explicit type specialization @@ -4264,7 +4171,6 @@ Differences are described in separate recipes. * :ref:`R120` * :ref:`R121` * :ref:`R122` -* :ref:`R123` * :ref:`R124` * :ref:`R125` * :ref:`R126` @@ -4517,64 +4423,6 @@ Use explicit ``import ... from ...`` instead. * :ref:`R120` -.. _R123: - -|CB_R| #123: Renaming in export declarations is not supported -------------------------------------------------------------- - -|CB_RULE| -~~~~~~~~~ - -|LANG| does not support renaming in export declarations. Similar effect -can be achieved through setting an alias for the exported entity. - -|CB_BAD| -~~~~~~~~ - -.. code-block:: typescript - - // file1.ts - class MyClass { - // ... - } - - export { MyClass as RenamedClass } - - // file2.ts - import { RenamedClass } from "./file1" - - function main(): void { - const myObject = new RenamedClass() - // ... - } - -|CB_OK| -~~~~~~~ - -.. code-block:: typescript - - // module1 - class MyClass { - // ... - } - - export RenamedClass = MyClass - - // module2 - import RenamedClass from "./module1" - - function main(): void { - const myObject = new RenamedClass() - // ... - } - -|CB_SEE| -~~~~~~~~ - -* :ref:`R124` -* :ref:`R125` -* :ref:`R126` - .. _R124: |CB_R| #124: Export list declaration is not supported @@ -4608,7 +4456,6 @@ entities must be explicitly annotated with the ``export`` keyword. |CB_SEE| ~~~~~~~~ -* :ref:`R123` * :ref:`R125` * :ref:`R126` @@ -4663,7 +4510,6 @@ imported explicitly from the modules that export them. |CB_SEE| ~~~~~~~~ -* :ref:`R123` * :ref:`R124` * :ref:`R126` @@ -4715,7 +4561,6 @@ Use regular ``export`` / ``import`` instead. |CB_SEE| ~~~~~~~~ -* :ref:`R123` * :ref:`R124` * :ref:`R125` diff --git a/linter/cookbook_convertor/src/cookbook_convertor.ts b/linter/cookbook_convertor/src/cookbook_convertor.ts index 201123993749eca70c982c7d3a1300d99e3ec08c..11d3c7766bb33bd81b73e86e0dd5a8cfc49f639a 100644 --- a/linter/cookbook_convertor/src/cookbook_convertor.ts +++ b/linter/cookbook_convertor/src/cookbook_convertor.ts @@ -36,7 +36,7 @@ const COPYRIGHT_HEADER = "/* \n\ const CODE_PROLOGUE = "export const cookBookMsg: string[] = [];\n\ export const cookBookTag: string[] = [];\n\ \n\ -for( let i = 0; i < 144; i++) {\n\ +for( let i = 0; i < 147; i++) {\n\ cookBookMsg[ i ] = '';\n\ }\n\ "; @@ -372,7 +372,7 @@ function makeOk(): string { needHeader(); console.error( ">>>makeOK HDR>>>: " + doc_lines[ _line ] ); - if( !doc_lines[_line].startsWith(CB_OK) ) { + if( _line >= doc_lines.length || !doc_lines[_line].startsWith(CB_OK) ) { return ""; } _line++; _line++; // skip underline diff --git a/linter/docs/rules/recipe1.md b/linter/docs/rules/recipe1.md index c67cc90d075811adc29ea05b1ad6e879c3c90851..317d04c6bd75c5d7c80e2e19a7553595833174ac 100644 --- a/linter/docs/rules/recipe1.md +++ b/linter/docs/rules/recipe1.md @@ -1,12 +1,12 @@ # Objects with property names that are not identifiers are not supported -Rule ``arkts-no-computed-props`` +Rule ``arkts-identifiers-as-prop-names`` **Severity: error** ArkTS does not support Objects with name properties that are numbers or -strings. Use classes to access data by property names. Use arrays to access data -by numeric indices. +strings. Use classes to access data by property names. Use arrays to access +data by numeric indices. ## TypeScript @@ -50,9 +50,10 @@ by numeric indices. - 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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/recipe105.md b/linter/docs/rules/recipe105.md index 599c1e61d052403b16e78dd4a0997171cd40a8ed..e7e9d47bd4ddee7855a9b3261376434ed844ee85 100644 --- a/linter/docs/rules/recipe105.md +++ b/linter/docs/rules/recipe105.md @@ -53,19 +53,21 @@ will result in a compile-time error. let obj: A = tmp as A obj.foo() // OK obj.bar() // OK - obj.some_foo() // Compile-time error: Method some_foo does not exist on this type + obj.some_foo() // Compile-time error: Method some_foo does not + // exist on this type } ``` ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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 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/recipe106.md b/linter/docs/rules/recipe106.md index 207e857bd9890cfff83413e00b6fbfd07ebc07ef..f98f5dcdfef698cd6c6612439f543f9d69364560 100644 --- a/linter/docs/rules/recipe106.md +++ b/linter/docs/rules/recipe106.md @@ -5,7 +5,7 @@ Rule ``arkts-no-ctor-signatures-funcs`` **Severity: error** ArkTS does not support the usage of the constructor function type. -Use lambdas instead, as they can be generalized to several types of objects. +Use lambdas instead. ## TypeScript @@ -19,10 +19,10 @@ Use lambdas instead, as they can be generalized to several types of objects. age: number ) {} } + type PersonCtor = new (name: string, age: number) => Person - type PersonConstructor = new (name: string, age: number) => Person - - function createPerson(Ctor: PersonConstructor, name: string, age: number): Person { + function createPerson(Ctor: PersonCtor, name: string, age: number): Person + { return new Ctor(name, age) } @@ -41,18 +41,17 @@ Use lambdas instead, as they can be generalized to several types of objects. age: number ) {} } + type PersonCtor = (n: string, a: number) => Person - let PersonConstructor: (name: string, age: number) => Person = (name: string, age: number): Person => { - return new Person(name, age) + function createPerson(Ctor: PersonCtor, n: string, a: number): Person { + return Ctor(n, a) } - function createPerson(Ctor: (name: string, age: number) => Person, name: string, age: number): Person { - return PersonConstructor(name, age) + let Impersonizer: PersonCtor = (n: string, a: number): Person => { + return new Person(n, a) } - function main(): void { - const person = createPerson(PersonConstructor, "John", 30) - } + const person = createPerson(Impersonizer, "John", 30) ``` diff --git a/linter/docs/rules/recipe109.md b/linter/docs/rules/recipe109.md index 591526e2be42d8a654767cb78da2b253be0179ee..05dd754c2161ecbca46bdb90943e9049fdad2cfb 100644 --- a/linter/docs/rules/recipe109.md +++ b/linter/docs/rules/recipe109.md @@ -57,12 +57,13 @@ declare fields, their names and types explicitly. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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/recipe111.md b/linter/docs/rules/recipe111.md index 2e7f4a7f1d3fabe0497bbb07fee69e0d817cc144..9100095fc4980f7ce6d782a2e97a8815f821666b 100644 --- a/linter/docs/rules/recipe111.md +++ b/linter/docs/rules/recipe111.md @@ -1,10 +1,12 @@ -# Explicit values for enumeration constants are not supported +# Enumeration members can be initialized only with compile time expressions of the same type -Rule ``arkts-no-explicit-enum-init`` +Rule ``arkts-no-enum-mixed-types`` **Severity: error** -Currently, ArkTS does not support assigning explicit values for ``enums``. +ArkTS does not support initializing members of enumerations with expressions +that are evaluated during program runtime. Besides, all explicitly set +initializers must be of the same type. ## TypeScript @@ -12,11 +14,19 @@ Currently, ArkTS does not support assigning explicit values for ``enums``. ``` - enum E { - A, - B, - C = 10, - D + enum E1 { + A = 0xa, + B = 0xb, + C = Math.random(), + D = 0xd, + E // 0xe inferred + } + + enum E2 { + A = 0xa, + B = "0xb", + C = 0xc, + D = "0xd" } ``` @@ -26,18 +36,19 @@ Currently, ArkTS does not support assigning explicit values for ``enums``. ``` - enum E { - A, - B, - C = 10, // Compile-time error: assigning out of order values for enums is not supported - D + enum E1 { + A = 0xa, + B = 0xb, + C = 0xc, + D = 0xd, + E // 0xe inferred } - enum E_fixed { - A, - B, - C, // OK - D + enum E2 { + A = "0xa", + B = "0xb", + C = "0xc", + D = "0xd" } ``` diff --git a/linter/docs/rules/recipe115.md b/linter/docs/rules/recipe115.md index b7ed86e5f2733a979db425cc239c2fc5ea22e15e..ee73f68fd25bfc22657de9f15ea50dd826f62462 100644 --- a/linter/docs/rules/recipe115.md +++ b/linter/docs/rules/recipe115.md @@ -13,10 +13,9 @@ Differences are described in separate recipes. - Recipe 118: Special import type declarations are not supported (``arkts-no-special-imports``) - 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`` is not supported (``arkts-no-require``) -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) +- Recipe 121: ``require`` and ``import`` assignment are not supported (``arkts-no-require``) - Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) -- Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) +- Recipe 125: Re-exporting is supported with restrictions (``arkts-limited-reexport``) - Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) diff --git a/linter/docs/rules/recipe118.md b/linter/docs/rules/recipe118.md index 5cd2e85ed0781ccf7b15d67a9c67109468464b0f..0041552fdb013d8acf3a5c3078f2ebc668725250 100644 --- a/linter/docs/rules/recipe118.md +++ b/linter/docs/rules/recipe118.md @@ -34,6 +34,6 @@ Use ordinary import instead. - 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`` is not supported (``arkts-no-require``) +- Recipe 121: ``require`` and ``import`` assignment are not supported (``arkts-no-require``) diff --git a/linter/docs/rules/recipe121.md b/linter/docs/rules/recipe121.md index 918ae2aed90d941443f0d25a701af1d3af56bfdd..ef4631c12d6b3523a67e1a709ac545268a8bcc8d 100644 --- a/linter/docs/rules/recipe121.md +++ b/linter/docs/rules/recipe121.md @@ -1,10 +1,11 @@ -# ``require`` is not supported +# ``require`` and ``import`` assignment are not supported Rule ``arkts-no-require`` **Severity: error** -ArkTS does not support importing via ``require``. Use ``import`` instead. +ArkTS does not support importing via ``require``. ``import`` assignment are +not supported either. Use regular ``import`` instead. ## TypeScript @@ -25,4 +26,8 @@ ArkTS does not support importing via ``require``. Use ``import`` instead. ``` +## See also + +- Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) + diff --git a/linter/docs/rules/recipe123.md b/linter/docs/rules/recipe123.md deleted file mode 100644 index 93667373868f3ab91ac6ca468f8d5bd25ec90c65..0000000000000000000000000000000000000000 --- a/linter/docs/rules/recipe123.md +++ /dev/null @@ -1,61 +0,0 @@ -# Renaming in export declarations is not supported - -Rule ``arkts-no-export-renaming`` - -**Severity: error** - -ArkTS does not support renaming in export declarations. Similar effect -can be achieved through setting an alias for the exported entity. - - -## TypeScript - - -``` - - // file1.ts - class MyClass { - // ... - } - - export { MyClass as RenamedClass } - - // file2.ts - import { RenamedClass } from "./file1" - - function main(): void { - const myObject = new RenamedClass() - // ... - } - -``` - -## ArkTS - - -``` - - // module1 - class MyClass { - // ... - } - - export type RenamedClass = MyClass - - // module2 - import { RenamedClass } from "./module1" - - function main(): void { - const myObject = new RenamedClass() - // ... - } - -``` - -## See also - -- Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) -- Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) -- Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) - - diff --git a/linter/docs/rules/recipe124.md b/linter/docs/rules/recipe124.md index d86e3f384c80fc59d1f1bc2f309421f18cffa9af..b1a80dc42b5afd5d926351050b452986d9c7161c 100644 --- a/linter/docs/rules/recipe124.md +++ b/linter/docs/rules/recipe124.md @@ -33,8 +33,7 @@ entities must be explicitly annotated with the ``export`` keyword. ## See also -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) -- Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) +- Recipe 125: Re-exporting is supported with restrictions (``arkts-limited-reexport``) - Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) diff --git a/linter/docs/rules/recipe125.md b/linter/docs/rules/recipe125.md index 47ee1ddd34953caa7df805a24ce9f52dc3c38497..4aa7cec5d9d73203e8d1f8c54f74d4353899e904 100644 --- a/linter/docs/rules/recipe125.md +++ b/linter/docs/rules/recipe125.md @@ -1,11 +1,12 @@ -# Re-exporting is not supported +# Re-exporting is supported with restrictions -Rule ``arkts-no-reexport`` +Rule ``arkts-limited-reexport`` **Severity: error** -ArkTS does not support re-exporting. All desired entities must be -imported explicitly from the modules that export them. +ArkTS supports re-exporting syntax which covers most common cases of re-export: +re-exporting imported entities and re-exporting which is combined with renaming. +Other syntax flavors like ``export * as ...`` are not supported. ## TypeScript @@ -14,17 +15,18 @@ imported explicitly from the modules that export them. ``` // module1 - export class MyClass { + export class Class1 { + // ... + } + export class Class2 { // ... } // module2 - export { MyClass } from "module1" + export * as utilities from "module1" // consumer module - import { MyClass } from "module2" - - const myInstance = new MyClass() + import { utilities } from "module2" ``` @@ -34,24 +36,24 @@ imported explicitly from the modules that export them. ``` // module1 - export class MyClass { - // ... + export class Class1 { + // ... + } + export class C2 { + // ... } // module2 - // some stuff + export { Class1 } from "module1" + export { C2 as Class2 } from "module1" // consumer module - import { MyClass } from "module1" - import * from "module2" - - const myInstance = new MyClass() + import { Class1, Class2 } from "module2" ``` ## See also -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) - Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) - Recipe 126: ``export = ...`` assignment is not supported (``arkts-no-export-assignment``) diff --git a/linter/docs/rules/recipe126.md b/linter/docs/rules/recipe126.md index 94f88de58cd467215d24383ad9ad64012569398a..59a9551cae1c65460da88d2b6b098b6c597a6f74 100644 --- a/linter/docs/rules/recipe126.md +++ b/linter/docs/rules/recipe126.md @@ -48,8 +48,8 @@ Use regular ``export`` / ``import`` instead. ## See also -- Recipe 123: Renaming in export declarations is not supported (``arkts-no-export-renaming``) +- Recipe 121: ``require`` and ``import`` assignment are not supported (``arkts-no-require``) - Recipe 124: Export list declaration is not supported (``arkts-no-export-list-decl``) -- Recipe 125: Re-exporting is not supported (``arkts-no-reexport``) +- Recipe 125: Re-exporting is supported with restrictions (``arkts-limited-reexport``) diff --git a/linter/docs/rules/recipe127.md b/linter/docs/rules/recipe127.md index 0a307add90b19cecdc701c9f42296c71ee8adc96..c89d24fbac4b50b1e68937ea99e7e979ae8c1452 100644 --- a/linter/docs/rules/recipe127.md +++ b/linter/docs/rules/recipe127.md @@ -1,11 +1,11 @@ -# Special export type declarations are not supported +# Special ``export type`` declarations are not supported Rule ``arkts-no-special-exports`` **Severity: error** -ArkTS does not have a special notation for exporting types. -Use ordinary export instead. +ArkTS does not have a special notation for exporting types through +``export type ...``. Use ordinary export instead. ## TypeScript @@ -13,8 +13,18 @@ Use ordinary export instead. ``` - class C {} - export type { C } + // Explicitly exported class: + export class Class1 { + // ... + } + + // Declared class later exported through export type ... + class Class2 { + // ... + } + + // This is not supported: + export type { Class2 } ``` @@ -23,7 +33,15 @@ Use ordinary export instead. ``` - export class C {} + // Explicitly exported class: + export class Class1 { + // ... + } + + // Explicitly exported class: + export class Class2 { + // ... + } ``` diff --git a/linter/docs/rules/recipe13.md b/linter/docs/rules/recipe13.md index 768c3f27ca3dfa94b5e6f3b79ab23a9b09c07a4f..1fcf6c6f558b41d7a10c0cd6e0727163cb3bb4e3 100644 --- a/linter/docs/rules/recipe13.md +++ b/linter/docs/rules/recipe13.md @@ -30,8 +30,4 @@ Currently, ArkTS does not support tuples. You can use arrays of ``Object`` ``` -## See also - -- Recipe 013: Use ``Object[]`` instead of tuples (``arkts-no-tuples``) - diff --git a/linter/docs/rules/recipe137.md b/linter/docs/rules/recipe137.md index 2ba40ccc7fc7f2621f31772463274d8925b709db..588cc70f46e523414ec8c99dc61aad374f963c14 100644 --- a/linter/docs/rules/recipe137.md +++ b/linter/docs/rules/recipe137.md @@ -39,5 +39,6 @@ objects with dynamically changed layout are not supported. ## See also - Recipe 139: Declaring properties on functions is not supported (``arkts-no-func-props``) +- Recipe 144: Usage of standard library is restricted (``arkts-limited-stdlib``) diff --git a/linter/docs/rules/recipe138.md b/linter/docs/rules/recipe138.md index d0f2210810806965fd1508d07e8f899ffe289f65..f97ec50ae8cf49b9c6d2ed321ed69e7603f3f779 100644 --- a/linter/docs/rules/recipe138.md +++ b/linter/docs/rules/recipe138.md @@ -1,12 +1,12 @@ -# Utility types are not supported +# Some of utility types are not supported Rule ``arkts-no-utility-types`` **Severity: error** Currently ArkTS does not support utility types from TypeScript extensions to the -standard library (``Omit``, ``Partial``, ``Readonly``, ``Record``, ``Pick``, -etc.). +standard library (``Omit``, ``Pick``, etc.). Exceptions are: ``Partial``, +``Record``. ## TypeScript diff --git a/linter/docs/rules/recipe139.md b/linter/docs/rules/recipe139.md index 3477c74442cfda4a6b751b12c0686235d2a394cc..5b27d1ebfa1009bd3986a339da8172aec5b19fef 100644 --- a/linter/docs/rules/recipe139.md +++ b/linter/docs/rules/recipe139.md @@ -18,7 +18,10 @@ this rule and their layout cannot be changed in runtime. // ... } - function readImage(path: string, callback: (err: any, image: MyImage) => void) { + function readImage( + path: string, callback: (err: any, image: MyImage) => void + ) + { // ... } @@ -46,7 +49,10 @@ this rule and their layout cannot be changed in runtime. // ... } - function readImage(path: string, callback: (err: Error, image: MyImage) => void) : Promise { + function readImage( + path: string, callback: (err: Error, image: MyImage) => void + ) : Promise + { // async implementation } diff --git a/linter/docs/rules/recipe142.md b/linter/docs/rules/recipe142.md index af28e8ef855fd735d00f18701fed5c30dda5c270..cca78dc76637bdb0eda7fa5750cb6a3bc51bc497 100644 --- a/linter/docs/rules/recipe142.md +++ b/linter/docs/rules/recipe142.md @@ -46,3 +46,5 @@ does not support literal types. } ``` + + diff --git a/linter/docs/rules/recipe144.md b/linter/docs/rules/recipe144.md new file mode 100644 index 0000000000000000000000000000000000000000..7a2ed2363221289e447529fe31ec777d25d39e44 --- /dev/null +++ b/linter/docs/rules/recipe144.md @@ -0,0 +1,54 @@ +# Usage of standard library is restricted + +Rule ``arkts-limited-stdlib`` + +**Severity: error** + +ArkTS does not allow usage of some APIs from the TypeScript/JavaScript standard library. +The most part of the restricted APIs relates to manipulating objects in +dynamic manner, which is not compatible with the static typing. Following APIs +are prohibited from usage: + +Properties and functions of the global object: ``eval``, +``Infinity``, ``NaN``, ``isFinite``, ``isNaN``, ``parseFloat``, ``parseInt``, +``encodeURI``, ``encodeURIComponent``, ``Encode``, +``decodeURI``, ``decodeURIComponent``, ``Decode``, +``escape``, ``unescape``, ``ParseHexOctet`` + +``Object``: ``__proto__``, ``__defineGetter__``, ``__defineSetter__``, +``__lookupGetter__``, ``__lookupSetter__``, ``assign``, ``create``, +``defineProperties``, ``defineProperty``, ``entries``, ``freeze``, +``fromEntries``, ``getOwnPropertyDescriptor``, ``getOwnPropertyDescriptors``, +``getOwnPropertyNames``, ``getOwnPropertySymbols``, ``getPrototypeOf``, +``hasOwn``, ``hasOwnProperty``, ``is``, ``isExtensible``, ``isFrozen``, +``isPrototypeOf``, ``isSealed``, ``keys``, ``preventExtensions``, +``propertyIsEnumerable``, ``seal``, ``setPrototypeOf``, ``values`` + +``Reflect``: ``apply``, ``construct``, ``defineProperty``, ``deleteProperty``, +``get``, ``getOwnPropertyDescriptor``, ``getPrototypeOf``, ``has``, +``isExtensible``, ``ownKeys``, ``preventExtensions``, ``set``, +``setPrototypeOf`` + +``Proxy``: ``handler.apply()``, ``handler.construct()``, +``handler.defineProperty()``, ``handler.deleteProperty()``, ``handler.get()``, +``handler.getOwnPropertyDescriptor()``, ``handler.getPrototypeOf()``, +``handler.has()``, ``handler.isExtensible()``, ``handler.ownKeys()``, +``handler.preventExtensions()``, ``handler.set()``, ``handler.setPrototypeOf()`` + +``Array``: ``isArray`` + +``ArrayBuffer``: ``isView`` + + +## 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 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 137: ``globalThis`` is not supported (``arkts-no-globalthis``) + + diff --git a/linter/docs/rules/recipe145.md b/linter/docs/rules/recipe145.md new file mode 100644 index 0000000000000000000000000000000000000000..37e7be51f165a952926ccaf4efa3e2876798a817 --- /dev/null +++ b/linter/docs/rules/recipe145.md @@ -0,0 +1,56 @@ +# Strict type checking is enforced + +Rule ``arkts-strict-typing`` + +**Severity: error** + +Type checker in ArkTS is not optional, the code must be explicitly and +correctly types to be compiled and run. When porting from the standard TypeScript, +following flags should be turned on: ``noImplicitReturns``, +``strictFunctionTypes``, ``strictNullChecks``, ``strictPropertyInitialization``. + + +## TypeScript + + +``` + + class C { + n: number + s: string + } + + function foo(s: string): string { + console.log(s) + } + + let n: number = null + +``` + +## ArkTS + + +``` + + class C { + n: number = 0 + s: string = "" + } + + function foo(s: string): string { + console.log(s) + return s + } + + let n1: number | null = null + let n2: number = 0 + +``` + +## See also + +- Recipe 008: Use explicit types instead of ``any``, ``unknown`` (``arkts-no-any-undefined-unknown``) +- Recipe 146: Switching off type checks with in-place comments is not allowed (``arkts-strict-typing-required``) + + diff --git a/linter/docs/rules/recipe146.md b/linter/docs/rules/recipe146.md new file mode 100644 index 0000000000000000000000000000000000000000..f00a66b1563b5c3d4fac8f031a578988df342655 --- /dev/null +++ b/linter/docs/rules/recipe146.md @@ -0,0 +1,44 @@ +# Switching off type checks with in-place comments is not allowed + +Rule ``arkts-strict-typing-required`` + +**Severity: error** + +Type checker in ArkTS is not optional, the code must be explicitly and +correctly types to be compiled and run. "Suppressing" type checker in-place +with special comments is not allowed. In particular, ``@ts-ignore`` and +``@ts-nocheck`` annotations are not supported. + + +## TypeScript + + +``` + + // @ts-nocheck + // ... + // Some code with switched off type checker + // ... + + // @ts-ignore + let s1: string = null // No error, type checker suppressed + let s2: string = null // Compile-time error + +``` + +## ArkTS + + +``` + + let s1: string | null = null // No error, properly types + let s2: string = null // Compile-time error + +``` + +## See also + +- Recipe 008: Use explicit types instead of ``any``, ``unknown`` (``arkts-no-any-undefined-unknown``) +- Recipe 145: Strict type checking is enforced (``arkts-strict-typing``) + + diff --git a/linter/docs/rules/recipe147.md b/linter/docs/rules/recipe147.md new file mode 100644 index 0000000000000000000000000000000000000000..6a81f41c8e315e4530e5fe285ca02d2cbbf24414 --- /dev/null +++ b/linter/docs/rules/recipe147.md @@ -0,0 +1,27 @@ +# No dependencies on |TS| code are currently allowed + +Rule ``arkts-no-ts-deps`` + +**Severity: error** + +Code base implemented in the standard TypeScript currently should not depend on ArkTS +through importing ArkTS code base. Imports in reverse direction are supported. + + +## TypeScript + + +``` + + // app.ets + export class C { + // ... + } + + // lib.ts + import { C } from "app" + +``` + + + diff --git a/linter/docs/rules/recipe2.md b/linter/docs/rules/recipe2.md index 2073d6c6379345939f5dcabf87a40751faa8c73e..623cbff522305e062b19fe33f58679239e9afd37 100644 --- a/linter/docs/rules/recipe2.md +++ b/linter/docs/rules/recipe2.md @@ -37,12 +37,13 @@ and cannot be changed at runtime. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-identifiers-as-prop-names``) - 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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/recipe21.md b/linter/docs/rules/recipe21.md index 75024ca7b7cb8e5a703fe15eb93a1cf1e746ea3a..942907dfd37e059fd9be40444f1c8465ae72c83d 100644 --- a/linter/docs/rules/recipe21.md +++ b/linter/docs/rules/recipe21.md @@ -1,6 +1,6 @@ -# Returning ``this`` type is not supported +# Type notation using ``this`` is not supported -Rule ``arkts-no-this-as-return-type`` +Rule ``arkts-no-typing-with-this`` **Severity: error** @@ -16,6 +16,14 @@ ArkTS does not support the returning ``this`` type. Use explicit type instead. getHead(): this } + class C { + n: number = 0 + + m(c: this) { + console.log(c) + } + } + ``` ## ArkTS @@ -27,6 +35,14 @@ ArkTS does not support the returning ``this`` type. Use explicit type instead. getHead(): ListItem } + class C { + n: number = 0 + + m(c: C) { + console.log(c) + } + } + ``` diff --git a/linter/docs/rules/recipe22.md b/linter/docs/rules/recipe22.md index 0b3bb748d5c820ab1dfd0ad2f553fc558ea78e4a..1ea9a18cba4a8c3a8266404deeb4813963df4313 100644 --- a/linter/docs/rules/recipe22.md +++ b/linter/docs/rules/recipe22.md @@ -31,7 +31,8 @@ keyword is not supported. // Rewrite with Object. Less type control, need more type checks for safety type X2 = Object - // Item has to be used as a generic parameter and need to be properly instantiated + // Item has to be used as a generic parameter and need to be properly + // instantiated type YI> = Item ``` diff --git a/linter/docs/rules/recipe24.md b/linter/docs/rules/recipe24.md deleted file mode 100644 index 174d840558bf5fa39a0a3acc06f8c5fb2455995c..0000000000000000000000000000000000000000 --- a/linter/docs/rules/recipe24.md +++ /dev/null @@ -1,46 +0,0 @@ -# Optional parameters are not supported for primitive types - -Rule ``arkts-no-opt-params`` - -**Severity: error** - -ArkTS does not support optional parameters of primitive types. -You can use default parameter values or reference types. For reference types, -non-specified optional parameter is set to ``null``. - - -## TypeScript - - -``` - - // x is an optional parameter: - function f(x?: number) { - console.log(x) // log undefined or number - } - - // x is a required parameter with the default value: - function g(x: number = 1) { - console.log(x) - } - -``` - -## ArkTS - - -``` - - // You can use reference type (will be set to null if missing): - function f(x?: Number) { - console.log(x) // log null or some number - } - - // You can use a required parameter with the default value: - function g(x: number = 1) { - console.log(x) - } - -``` - - diff --git a/linter/docs/rules/recipe3.md b/linter/docs/rules/recipe3.md index 94348f064adbc7dcd3bfd09f7fd1326e87573f6d..3611a35c26e4a565c3d896bae9d7ca0fa7ccec3c 100644 --- a/linter/docs/rules/recipe3.md +++ b/linter/docs/rules/recipe3.md @@ -13,9 +13,12 @@ keyword instead. ``` + /* + * Such notation for private fields is not supported: class C { - foo = 1 + #foo: number = 42 } + */ ``` @@ -25,10 +28,9 @@ keyword instead. ``` class C { - private foo = 1 + private foo: number = 42 } - ``` diff --git a/linter/docs/rules/recipe31.md b/linter/docs/rules/recipe31.md index cf4767dff52c99bc15141315ed1d00ca61c36dd1..bd8337a3c10d6777cb8de0336f455a571071136f 100644 --- a/linter/docs/rules/recipe31.md +++ b/linter/docs/rules/recipe31.md @@ -66,11 +66,11 @@ instead. let x = new X() let y = new Y() - console.log("Assign X to Y") - y = x // ok, X is the super class of X + console.log("Assign Y to X") + x = y // ok, X is the super class of Y - // Cannot assign Y to X - //x = y - compile-time error + // Cannot assign X to Y + //y = x - compile-time error ``` diff --git a/linter/docs/rules/recipe33.md b/linter/docs/rules/recipe33.md deleted file mode 100644 index 4b8adbb0738364eac0d715f7718df1f6d3858cb4..0000000000000000000000000000000000000000 --- a/linter/docs/rules/recipe33.md +++ /dev/null @@ -1,58 +0,0 @@ -# Optional properties are not supported for primitive types - -Rule ``arkts-no-opt-props`` - -**Severity: error** - -ArkTS does not support optional properties of primitive types. You can use -properties with default values or reference types. For reference types, -non-specified optional property is set to ``null``. This rule applies both to -classes and interfaces. - - -## TypeScript - - -``` - - class CompilerOptions { - strict?: boolean - sourcePath?: string - targetPath?: string - } - - let options: CompilerOptions = { - strict: true, - sourcePath: "./src" - } - - if (options.targetPath == undefined) { - // Some logic - } - -``` - -## ArkTS - - -``` - - class CompilerOptions { - strict: boolean = false - sourcePath: string = "" - targetPath?: string - } - - let options: CompilerOptions = { - strict: true, - sourcePath: "./src" - // targetPath is implicitly set to null - } - - if (options.targetPath == null) { - // Some logic - } - -``` - - diff --git a/linter/docs/rules/recipe34.md b/linter/docs/rules/recipe34.md index a1306d50a30a26a470cf8bdf9f05b636484e00d5..c1536ee24c555c21ca85b3406ef7b71f8e1b2a7c 100644 --- a/linter/docs/rules/recipe34.md +++ b/linter/docs/rules/recipe34.md @@ -1,12 +1,13 @@ -# Generic functions must be called with explicit type specialization +# Type inference in case of generic function calls is limited Rule ``arkts-no-inferred-generic-params`` -**Severity: warning** +**Severity: error** -Currently, ArkTS does not support inference of type parameters in case of calls -to generic functions. If a function is declared generic, all calls must specify -type parameters explicitly. +ArkTS allows to omit generic type parameters if it is possible to infer +the concrete types from the parameters passed to the function. Otherwise a +compile-time error occurs. In particular, inference of generic type parameters +based only on function return types is prohibited. ## TypeScript @@ -18,9 +19,14 @@ type parameters explicitly. return Math.random() < 0.5 ? x : y } - let x = choose(10, 20) // Ok + let x = choose(10, 20) // OK, choose(...) is inferred let y = choose("10", 20) // Compile-time error + function greet(): T { + return "Hello" as T + } + let z = greet() // Type of x is inferred as "unknown" + ``` ## ArkTS @@ -32,8 +38,13 @@ type parameters explicitly. return Math.random() < 0.5 ? x : y } - let x = choose(10, 20) // Ok - let y = choose("10", 20) // Compile-time error + let x = choose(10, 20) // OK, choose(...) is inferred + let y = choose("10", 20) // Compile-time error + + function greet(): T { + return "Hello" as T + } + let z = greet() ``` diff --git a/linter/docs/rules/recipe38.md b/linter/docs/rules/recipe38.md index b508aad3119ee0b9a79e4b1d66cdefea6da6f3f4..62b06f7a93706c30e1481c1c77d94e2a7bf8bc96 100644 --- a/linter/docs/rules/recipe38.md +++ b/linter/docs/rules/recipe38.md @@ -1,14 +1,18 @@ -# Object literal must correspond to explicitly declared class or interface +# Object literal must correspond to some explicitly declared class or interface Rule ``arkts-no-untyped-obj-literals`` **Severity: error** -ArkTS supports the usage of object literals if the compiler can infer -to what classes or interfaces such literals correspond to. -Otherwise, a compile-time error occurs. +ArkTS supports usage of object literals if the compiler can infer to what +classes or interfaces such literals correspond to. Otherwise, a compile-time +error occurs. Specifically, using literals to initialize classes and interfaces +is not supported in following contexts: -The class or interface can be specified as a type annotation for a variable. +* Initialization of anything that has ``any``, ``Object``, or ``object`` type +* Initialization of classes or interfaces with methods +* Initialization of classes which declare a ``constructor`` with parameters +* Initialization of classes with ``readonly`` fields ## TypeScript @@ -16,7 +20,53 @@ The class or interface can be specified as a type annotation for a variable. ``` - let x = {f: 1} + let o1 = {n: 42, s: "foo"} + let o2: Object = {n: 42, s: "foo"} + let o3: object = {n: 42, s: "foo"} + + let oo: Object[] = [{n: 1, s: "1"}, {n: 2, s: "2"}] + + class C2 { + s: string + constructor(s: string) { + this.s = "s =" + s + } + } + let o4: C2 = {s: "foo"} + + class C3 { + readonly n: number = 0 + readonly s: string = "" + } + let o5: C3 = {n: 42, s: "foo"} + + abstract class A {} + let o6: A = {} + + class C4 { + n: number = 0 + s: string = "" + f() { + console.log("Hello") + } + } + let o7: C4 = {n: 42, s: "foo", f : () => {}} + + class Point { + x: number = 0 + y: number = 0 + } + + function id_x_y(o: Point): Point { + return o + } + + // Structural typing is used to deduce that p is Point: + let p = {x: 5, y: 10} + id_x_y(p) + + // A literal can be contextually (i.e., implicitly) typed as Point: + id_x_y({x: 5, y: 10}) ``` @@ -25,19 +75,72 @@ The class or interface can be specified as a type annotation for a variable. ``` - class O { - f: number + class C1 { + n: number = 0 + s: string = "" } - let x: O = {f: 1} // OK - let y = {f: 1} // Compile-time error, cannot infer object literal type - let z: Object = {f: 2} // Compile-time error, class 'Object' does not have field 'f' + let o1: C1 = {n: 42, s: "foo"} + let o2: C1 = {n: 42, s: "foo"} + let o3: C1 = {n: 42, s: "foo"} + + let oo: C1[] = [{n: 1, s: "1"}, {n: 2, s: "2"}] + + class C2 { + s: string + constructor(s: string) { + this.s = "s =" + s + } + } + let o4 = new C2("foo") + + class C3 { + n: number = 0 + s: string = "" + } + let o5: C3 = {n: 42, s: "foo"} + + abstract class A {} + class C extends A {} + let o6: C = {} // or let o6: C = new C() + + class C4 { + n: number = 0 + s: string = "" + f() { + console.log("Hello") + } + } + let o7 = new C4() + o7.n = 42 + o7.s = "foo" + + class Point { + x: number = 0 + y: number = 0 + + // constructor() is used before literal initialization + // to create a valid object. Since there is no other Point constructors, + // constructor() is automatically added by compiler + } + + function id_x_y(o: Point): Point { + return o + } + + // Explicit type is required for literal initialization + let p: Point = {x: 5, y: 10} + id_x_y(p) + + // id_x_y expects Point explicitly + // New instance of Point is initialized with the literal + id_x_y({x: 5, y: 10}) ``` ## See also - Recipe 040: Object literals cannot be used as type declarations (``arkts-no-obj-literals-as-types``) -- Recipe 043: Untyped array literals are not supported (``arkts-no-noninferrable-arr-literals``) +- Recipe 043: Array literals must contain elements of only inferrable types (``arkts-no-noninferrable-arr-literals``) diff --git a/linter/docs/rules/recipe40.md b/linter/docs/rules/recipe40.md index 0e70ca7c421b11e525f6f6bbb6cc6d7bef79eb18..9fd22580fbf472bf9bebc48b03bca25c45d5cced 100644 --- a/linter/docs/rules/recipe40.md +++ b/linter/docs/rules/recipe40.md @@ -40,7 +40,7 @@ types in place. Declare classes and interfaces explicitly instead. ## See also -- Recipe 038: Object literal must correspond to explicitly declared class or interface (``arkts-no-untyped-obj-literals``) -- Recipe 043: Untyped array literals are not supported (``arkts-no-noninferrable-arr-literals``) +- Recipe 038: Object literal must correspond to some explicitly declared class or interface (``arkts-no-untyped-obj-literals``) +- Recipe 043: Array literals must contain elements of only inferrable types (``arkts-no-noninferrable-arr-literals``) diff --git a/linter/docs/rules/recipe43.md b/linter/docs/rules/recipe43.md index bead8fbfd998729a8d5d82cce9cc583aac374f7b..e7257c77bf3037ae9ee155289e77b27aedb93be2 100644 --- a/linter/docs/rules/recipe43.md +++ b/linter/docs/rules/recipe43.md @@ -1,12 +1,12 @@ -# Untyped array literals are not supported +# Array literals must contain elements of only inferrable types Rule ``arkts-no-noninferrable-arr-literals`` **Severity: error** -ArkTS does not support the usage of untyped array literals. The type of an -array element must be inferred from the context. Use the type ``Object`` to -define mixed types array. +Basically, ArkTS infers the type of an array literal as a union type of its +contents. But if there is at least one element with a non-inferrable type +(e.g. untyped object literal), a compile-time error occurs. ## TypeScript @@ -14,8 +14,7 @@ define mixed types array. ``` - let x1 = [1, 2] - let x2 = [1, "aa"] + let a = [{n: 1, s: "1"}, {n: 2, s : "2"}] ``` @@ -24,19 +23,19 @@ define mixed types array. ``` - let x1: Object[] = [new Number(1), new Number(2)] + class C { + n: number = 0 + s: string = "" + } - // Implicit boxing of numbers to the object type Number - let x2: Object[] = [1, 2] - - // Implicit boxing of number and string to the object types Number and String - let x3: Object[] = [1, "aa"] + let a1 = [{n: 1, s: "1"} as C, {n: 2, s : "2"} as C] // a1 is of type "C[]" + let a2: C[] = [{n: 1, s: "1"}, {n: 2, s : "2"}] // ditto ``` ## See also -- Recipe 038: Object literal must correspond to explicitly declared class or interface (``arkts-no-untyped-obj-literals``) +- Recipe 038: Object literal must correspond to some explicitly declared class or interface (``arkts-no-untyped-obj-literals``) - Recipe 040: Object literals cannot be used as type declarations (``arkts-no-obj-literals-as-types``) diff --git a/linter/docs/rules/recipe46.md b/linter/docs/rules/recipe46.md index 172b344e07d7734b887dd08b255767ff1bdce65b..71fcbf8a1fd450b512787156f304591e859c1033 100644 --- a/linter/docs/rules/recipe46.md +++ b/linter/docs/rules/recipe46.md @@ -2,7 +2,7 @@ Rule ``arkts-no-func-expressions`` -**Severity: warning** +**Severity: error** ArkTS does not support function expressions, use arrow functions instead to be explicitly specified. diff --git a/linter/docs/rules/recipe52.md b/linter/docs/rules/recipe52.md index 59d298a8751b1f1e710046465331813935c0985e..91042ae7740cc4270ead455db209cd7b71fe9219 100644 --- a/linter/docs/rules/recipe52.md +++ b/linter/docs/rules/recipe52.md @@ -47,12 +47,13 @@ existence during compilation. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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/recipe55.md b/linter/docs/rules/recipe55.md index ee9cd5900b116bfbebc47811dfef939ba739fbbd..2b47bb52508ab4a126c165b41a62693b86879c9b 100644 --- a/linter/docs/rules/recipe55.md +++ b/linter/docs/rules/recipe55.md @@ -30,11 +30,11 @@ be done explicitly. ``` - let a = +5 // 5 as int + let a = +5 // 5 as number let b = +"5" // Compile-time error - let c = -5 // -5 as int + let c = -5 // -5 as number let d = -"5" // Compile-time error - let e = ~5 // -6 as int + let e = ~5 // -6 as number let f = ~"5" // Compile-time error let g = +"string" // Compile-time error @@ -42,7 +42,6 @@ be done explicitly. ## See also -- Recipe 055: Unary operators ``+``, ``-`` and ``~`` work only on numbers (``arkts-no-polymorphic-unops``) - Recipe 061: Binary operators ``*``, ``/``, ``%``, ``-``, ``<<``, ``>>``, ``>>>``, ``&``, ``^`` and ``|`` work only on numeric types (``arkts-no-polymorphic-binops``) - Recipe 063: Binary ``+`` operator supports implicit casts only for numbers and strings (``arkts-no-polymorphic-plus``) diff --git a/linter/docs/rules/recipe59.md b/linter/docs/rules/recipe59.md index a00c6cf88924cec5c1f84a0fd41af62eb695ee67..d64602e17550c8857100b5de5897a415472d816e 100644 --- a/linter/docs/rules/recipe59.md +++ b/linter/docs/rules/recipe59.md @@ -43,10 +43,10 @@ changed at runtime. Thus the operation of deleting a property makes no sense. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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 060: ``typeof`` is allowed only in expression contexts (``arkts-no-type-query``) +- 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``) diff --git a/linter/docs/rules/recipe60.md b/linter/docs/rules/recipe60.md index 2898c87889989af124b0167ff9c2a9091171f411..38b6ca476730f4d5c1513353841f055db04ad590 100644 --- a/linter/docs/rules/recipe60.md +++ b/linter/docs/rules/recipe60.md @@ -1,11 +1,11 @@ -# ``typeof`` is allowed only in expression contexts +# ``typeof`` operator is allowed only in expression contexts Rule ``arkts-no-type-query`` **Severity: error** -ArkTS supports ``typeof`` operator only in the expression context. -Type notation with ``typeof`` is not supported. +ArkTS supports ``typeof`` operator only in the expression context. Specifying +type notations using ``typeof`` is not supported. ## TypeScript @@ -38,12 +38,13 @@ Type notation with ``typeof`` is not supported. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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 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/recipe61.md b/linter/docs/rules/recipe61.md index ff56af6b74428344cd9d7724c63f2ad88796ad14..e5bdfd14abd026bf364762ae3044274ce249ec5a 100644 --- a/linter/docs/rules/recipe61.md +++ b/linter/docs/rules/recipe61.md @@ -48,7 +48,7 @@ compile-time errors. let d = (5.5 | 5.5) // Compile-time error enum Direction { - Up, // TBD: explicit start value + Up, Down } diff --git a/linter/docs/rules/recipe66.md b/linter/docs/rules/recipe66.md index 0b689e1b22a6530a22a7a29caeecc93e4ad61c38..10476f234c5e3f9161ff50e15ffff354d473b17f 100644 --- a/linter/docs/rules/recipe66.md +++ b/linter/docs/rules/recipe66.md @@ -40,12 +40,13 @@ to check whether certain class members exist. ## See also -- Recipe 001: Objects with property names that are not identifiers are not supported (``arkts-no-computed-props``) +- 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`` is allowed only in expression contexts (``arkts-no-type-query``) +- Recipe 060: ``typeof`` operator is allowed only in expression contexts (``arkts-no-type-query``) - 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/recipe71.md b/linter/docs/rules/recipe71.md index dacc10297860b5057e60a2cef71315a50042002b..569b48bb2181272a7cbacccc150b3d4d362e82a9 100644 --- a/linter/docs/rules/recipe71.md +++ b/linter/docs/rules/recipe71.md @@ -14,7 +14,8 @@ it is useless as it makes the execution order harder to understand. ``` for (let i = 0, j = 0; i < 10; ++i, j += 2) { - console.log(i, j) + console.log(i) + console.log(j) } let x = 0 @@ -28,7 +29,8 @@ it is useless as it makes the execution order harder to understand. ``` for (let i = 0, j = 0; i < 10; ++i, j += 2) { - console.log(i, j) + console.log(i) + console.log(j) } // Use explicit execution order instead of the comma operator: diff --git a/linter/docs/rules/recipe8.md b/linter/docs/rules/recipe8.md index 4c4e1056c8d0ceb027606f125567e6c8d8ce8e7b..fd3e9e1004eb6050b4aff873026d39400e7bfc5b 100644 --- a/linter/docs/rules/recipe8.md +++ b/linter/docs/rules/recipe8.md @@ -1,11 +1,11 @@ -# Use explicit types instead of ``any``, ``undefined``, ``unknown`` +# Use explicit types instead of ``any``, ``unknown`` Rule ``arkts-no-any-undefined-unknown`` **Severity: error** -ArkTS does not support ``any``, ``undefined``, and ``unknown`` types. -Specify types explicitly. +ArkTS does not support ``any``, and ``unknown`` types. Please specify types +explicitly. ## TypeScript @@ -13,11 +13,13 @@ Specify types explicitly. ``` - var x - console.log(x) // undefined + let value1 : any + value1 = true + value1 = 42 - var y: any - console.log(y) // undefined + let value2 : unknown + value2 = true + value2 = 42 ``` @@ -26,14 +28,16 @@ Specify types explicitly. ``` - // All variables should have their types specified explicitly: - let x: Object = {} - console.log(x) // {} + let value_b: boolean = true // OR: let value_b = true + let value_n: number = 42 // OR: let value_n = 42 + let value_o1: Object = true + let value_o2: Object = 42 ``` ## See also - Recipe 013: Use ``Object[]`` instead of tuples (``arkts-no-tuples``) +- Recipe 145: Strict type checking is enforced (``arkts-strict-typing``) diff --git a/linter/docs/rules/recipe82.md b/linter/docs/rules/recipe82.md index 1bd77d93184adb46de660eb2550dbfeb02ebfe94..e6c28d9b6e920d1273549292c5de2f583899af51 100644 --- a/linter/docs/rules/recipe82.md +++ b/linter/docs/rules/recipe82.md @@ -26,7 +26,7 @@ but does not support the iteration of objects content. ``` let a: Set = new Set([1, 2, 3]) - let numbers = a.values() + let numbers = Array.from(a.values()) for (let n of numbers) { console.log(n) } diff --git a/linter/docs/rules/recipe83.md b/linter/docs/rules/recipe83.md index d642988b257715b89866137d0b4c62f888f0b915..3eedbaee4815cfa5dc9a6b6244954f1617018970 100644 --- a/linter/docs/rules/recipe83.md +++ b/linter/docs/rules/recipe83.md @@ -19,8 +19,25 @@ classes to achieve the same behaviour. ``` +## ArkTS + + +``` + + class C { + n: number = 0 + s: string = "" + } + + class CFlags { + n: boolean = false + s: boolean = false + } + +``` + ## See also -- Recipe 097: `keyof` operator is not supported (``arkts-no-keyof``) +- Recipe 097: ``keyof`` operator is not supported (``arkts-no-keyof``) diff --git a/linter/docs/rules/recipe86.md b/linter/docs/rules/recipe86.md index d57436d82172fe082702ce8fc4bb83fcd2cc7b21..9daf45688e5347bf711f605df2629598e392f884 100644 --- a/linter/docs/rules/recipe86.md +++ b/linter/docs/rules/recipe86.md @@ -4,9 +4,9 @@ Rule ``arkts-limited-switch`` **Severity: error** -ArkTS supports the values of the types ``char``, ``byte``, ``short``, ``int``, -``long``, ``Char``, ``Byte``, ``Short``, ``Int``, ``Long``, ``String`` or -``enum`` in ``switch`` statements. Use ``if`` statements in other cases. +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 diff --git a/linter/docs/rules/recipe90.md b/linter/docs/rules/recipe90.md index 5ee2428f2f1b791661da38f6bd1a6cdbd294ee67..0613f6913d23d1eef21feed846cb1e9e10136829 100644 --- a/linter/docs/rules/recipe90.md +++ b/linter/docs/rules/recipe90.md @@ -49,8 +49,8 @@ explicitly. return g(x) } - // Explicit return type is required: - function g(x: number) : number { + // Return type may be omitted, it is inferred from f's explicit type: + function g(x: number) { return f(x - 1) } diff --git a/linter/docs/rules/recipe94.md b/linter/docs/rules/recipe94.md index eeba93be5520fa34fe5bf5523fa5156b46b6546b..8f350dc7fe2cdebaf150ae48c2af4bc0e67cb4cd 100644 --- a/linter/docs/rules/recipe94.md +++ b/linter/docs/rules/recipe94.md @@ -30,10 +30,19 @@ Use the ``async`` / ``await`` mechanism for multitasking. ``` - for (let i = 1; i <= 5; ++i) { - console.log(i) + async function complexNumberProcessing(n : number) : Promise { + // Some complex logic for proccessing the number here + return n } + async function foo() { + for (let i = 1; i <= 5; i++) { + console.log(await complexNumberProcessing(i)) + } + } + + foo() + ``` diff --git a/linter/docs/rules/recipe97.md b/linter/docs/rules/recipe97.md index c82350448ea9e66b4c30ebd0572f0eef32867cd0..0ba7f3db02c7cd1a15c05e1a73716bc6901df415 100644 --- a/linter/docs/rules/recipe97.md +++ b/linter/docs/rules/recipe97.md @@ -1,4 +1,4 @@ -# `keyof` operator is not supported +# ``keyof`` operator is not supported Rule ``arkts-no-keyof`` @@ -49,7 +49,6 @@ accessed directly. return obj.y } throw new Error() // No such property - return 0 } function main(): void { diff --git a/linter/docs/rules/recipe99.md b/linter/docs/rules/recipe99.md index 094f6841e22c9c6f545e244ac3c79de8dc00009e..23349a239547a94390ff82ff5f94c484d00727a1 100644 --- a/linter/docs/rules/recipe99.md +++ b/linter/docs/rules/recipe99.md @@ -40,13 +40,12 @@ where necessary. res += n return res } + console.log(sum_numbers(1, 2, 3)) function log_numbers(x : number, y : number, z : number) { console.log(x, y, z) } - - let numbers : number[] = [0, 1, 2] - sum_numbers(...numbers) + let numbers: number[] = [1, 2, 3] log_numbers(numbers[0], numbers[1], numbers[2]) let list1 : number[] = [1, 2] diff --git a/linter/src/AutofixInfo.ts b/linter/src/AutofixInfo.ts new file mode 100644 index 0000000000000000000000000000000000000000..a0d25dbd25e6e8c99c812ba2d08bcb6f80ed6a06 --- /dev/null +++ b/linter/src/AutofixInfo.ts @@ -0,0 +1,20 @@ +/* + * 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 interface AutofixInfo { + problemID: string; + start: number; + end: number; +} \ No newline at end of file diff --git a/linter/src/Autofixer.ts b/linter/src/Autofixer.ts index 4f7019187ffee254b67898131eb3b1af3b915670..3b9ff1295490d9cccee8df18f45cd89aad0f6206 100644 --- a/linter/src/Autofixer.ts +++ b/linter/src/Autofixer.ts @@ -14,7 +14,7 @@ */ import * as ts from 'typescript'; -import { AutofixInfo } from './Common'; +import { AutofixInfo } from './AutofixInfo'; import { FaultID } from './Problems'; export const AUTOFIX_ALL: AutofixInfo = { diff --git a/linter/src/Common.ts b/linter/src/CommandLineOptions.ts similarity index 76% rename from linter/src/Common.ts rename to linter/src/CommandLineOptions.ts index 399a7d11621abb7e706086e7708d96d11994c07a..0dc423300d6d8c1e741eadcd2cf5d502dc8cb50a 100644 --- a/linter/src/Common.ts +++ b/linter/src/CommandLineOptions.ts @@ -14,12 +14,7 @@ */ import * as ts from 'typescript'; - -export interface AutofixInfo { - problemID: string; - start: number; - end: number; -} +import { AutofixInfo } from './AutofixInfo'; export interface CommandLineOptions { strictMode?: boolean; @@ -29,11 +24,4 @@ export interface CommandLineOptions { parsedConfigFile?: ts.ParsedCommandLine; inputFiles: string[]; autofixInfo?: AutofixInfo[]; -} - -// common options interface, additional fields may be used by plugins -export interface LintOptions { - cmdOptions: CommandLineOptions; - tsProgram?: ts.Program; - [key: string]: any; -} +} \ No newline at end of file diff --git a/linter/src/CommandLineParser.ts b/linter/src/CommandLineParser.ts index b9d3d3f9822344a9016b6595e76d4953b2653636..2638181a727bd31112045aef02a7db4e5c9439fc 100644 --- a/linter/src/CommandLineParser.ts +++ b/linter/src/CommandLineParser.ts @@ -15,7 +15,7 @@ import Logger from '../utils/logger'; import { logTscDiagnostic, decodeAutofixInfo } from './Utils'; -import { AutofixInfo } from './Common'; +import { CommandLineOptions } from './CommandLineOptions'; import { AUTOFIX_ALL } from './Autofixer'; import { Command, Option } from 'commander'; import * as ts from 'typescript'; @@ -29,16 +29,6 @@ const JSON_EXT = '.json'; const logger = Logger.getLogger(); -export interface CommandLineOptions { - strictMode?: boolean; - ideMode?: boolean; - logTscErrors?: boolean; - warningsAsErrors: boolean; - parsedConfigFile?: ts.ParsedCommandLine; - inputFiles: string[]; - autofixInfo?: AutofixInfo[]; -} - let inputFiles: string[]; let responseFile = ''; function addSrcFile(value: string, dummy: string) { diff --git a/linter/src/CompilerWrapper.ts b/linter/src/CompilerWrapper.ts index db82d9b9015de5ee7a5c69834385e41511818dc6..a92a316b2e7dc900dcf2161ce5bbea3509c03ddc 100644 --- a/linter/src/CompilerWrapper.ts +++ b/linter/src/CompilerWrapper.ts @@ -16,7 +16,8 @@ import * as ts from 'typescript'; import { logTscDiagnostic } from './Utils'; import { consoleLog } from './TypeScriptLinter'; -import { CommandLineOptions, LintOptions } from './Common'; +import { CommandLineOptions } from './CommandLineOptions'; +import { LintOptions } from './LintOptions'; export function compile(options: LintOptions, logTscErrors: boolean | undefined): ts.Program { const createProgramOptions = formTscOptions(options.cmdOptions); diff --git a/linter/src/CookBookMsg.ts b/linter/src/CookBookMsg.ts index 54304c1e4f0c1ccf7acd2b93bab41a27cac16ee8..57e28c882afa5a3e0efa98ee3e4acb3ed57fbb53 100644 --- a/linter/src/CookBookMsg.ts +++ b/linter/src/CookBookMsg.ts @@ -16,7 +16,7 @@ export const cookBookMsg: string[] = []; export const cookBookTag: string[] = []; -for( let i = 0; i < 144; i++) { +for( let i = 0; i < 147; i++) { cookBookMsg[ i ] = ''; } @@ -27,7 +27,7 @@ cookBookTag[ 4 ] = 'Use unique names for types, namespaces, etc. (arkts-unique-n cookBookTag[ 5 ] = 'Use "let" instead of "var" (arkts-no-var)'; cookBookTag[ 6 ] = ''; cookBookTag[ 7 ] = ''; -cookBookTag[ 8 ] = 'Use explicit types instead of "any", "undefined", "unknown" (arkts-no-any-undefined-unknown)'; +cookBookTag[ 8 ] = 'Use explicit types instead of "any", "unknown" (arkts-no-any-undefined-unknown)'; cookBookTag[ 9 ] = ''; cookBookTag[ 10 ] = '"bigint" is not a builtin type, suffix "n" for numeric literals is not supported (arkts-no-n-suffix)'; cookBookTag[ 11 ] = ''; @@ -40,10 +40,10 @@ cookBookTag[ 17 ] = 'Indexed signatures are not supported (arkts-no-indexed-sign cookBookTag[ 18 ] = ''; cookBookTag[ 19 ] = 'Use inheritance instead of intersection types (arkts-no-intersection-types)'; cookBookTag[ 20 ] = ''; -cookBookTag[ 21 ] = 'Returning "this" type is not supported (arkts-no-this-as-return-type)'; +cookBookTag[ 21 ] = 'Type notation using "this" is not supported (arkts-no-typing-with-this)'; cookBookTag[ 22 ] = 'Conditional types are not supported (arkts-no-conditional-types)'; cookBookTag[ 23 ] = ''; -cookBookTag[ 24 ] = 'Optional parameters are not supported for primitive types (arkts-no-opt-params)'; +cookBookTag[ 24 ] = ''; cookBookTag[ 25 ] = 'Declaring fields in "constructor" is not supported (arkts-no-ctor-prop-decls)'; cookBookTag[ 26 ] = ''; cookBookTag[ 27 ] = 'Construct signatures not supported in interfaces (arkts-no-ctor-signatures-iface)'; @@ -52,7 +52,7 @@ cookBookTag[ 29 ] = 'Indexed access is not supported for fields (arkts-no-props- cookBookTag[ 30 ] = 'Structural identity is not supported (arkts-no-structural-identity)'; cookBookTag[ 31 ] = 'Structural typing is not supported for subtyping / supertyping (arkts-no-structural-subtyping)'; cookBookTag[ 32 ] = 'Structural typing is not supported for assignability checks (arkts-no-structural-assignability)'; -cookBookTag[ 33 ] = 'Optional properties are not supported for primitive types (arkts-no-opt-props)'; +cookBookTag[ 33 ] = ''; cookBookTag[ 34 ] = 'Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)'; cookBookTag[ 35 ] = 'Structural typing is not supported for type inference (arkts-no-structural-inference)'; cookBookTag[ 36 ] = ''; @@ -140,13 +140,13 @@ 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[ 120 ] = '"import default as ..." is not supported (arkts-no-import-default-as)'; -cookBookTag[ 121 ] = '"require" is not supported (arkts-no-require)'; +cookBookTag[ 121 ] = '"require" and "import" assignment are not supported (arkts-no-require)'; cookBookTag[ 122 ] = ''; -cookBookTag[ 123 ] = 'Renaming in export declarations is not supported (arkts-no-export-renaming)'; +cookBookTag[ 123 ] = ''; cookBookTag[ 124 ] = 'Export list declaration is not supported (arkts-no-export-list-decl)'; -cookBookTag[ 125 ] = 'Re-exporting is not supported (arkts-no-reexport)'; +cookBookTag[ 125 ] = 'Re-exporting is supported with restrictions (arkts-limited-reexport)'; 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 ] = 'Special "export type" declarations are not supported (arkts-no-special-exports)'; 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)'; @@ -157,10 +157,13 @@ cookBookTag[ 134 ] = 'Definite assignment assertions are not supported (arkts-no cookBookTag[ 135 ] = 'IIFEs as namespace declarations are not supported (arkts-no-iife)'; cookBookTag[ 136 ] = 'Prototype assignment is not supported (arkts-no-prototype-assignment)'; cookBookTag[ 137 ] = '"globalThis" is not supported (arkts-no-globalthis)'; -cookBookTag[ 138 ] = 'Utility types are not supported (arkts-no-utility-types)'; +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[ 141 ] = '"readonly T[]" syntax is not supported (arkts-no-readonly-params)'; 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[ 147 ] = 'No dependencies on TypeScript code are currently allowed (arkts-no-ts-deps)'; diff --git a/linter/src/LintOptions.ts b/linter/src/LintOptions.ts new file mode 100644 index 0000000000000000000000000000000000000000..a2d1184f59fbf5189cc5e18a23cafab7b9c7fd37 --- /dev/null +++ b/linter/src/LintOptions.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + +import * as ts from 'typescript'; +import { CommandLineOptions } from './CommandLineOptions'; + +// common options interface, additional fields may be used by plugins +export interface LintOptions { + cmdOptions: CommandLineOptions; + tsProgram?: ts.Program; + [key: string]: any; +} diff --git a/linter/src/LintRunResult.ts b/linter/src/LintRunResult.ts new file mode 100644 index 0000000000000000000000000000000000000000..565b7bf6dfb2d7a980f25519eecb08ede6d686f7 --- /dev/null +++ b/linter/src/LintRunResult.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { ProblemInfo } from './ProblemInfo'; + +export interface LintRunResult { + errorNodes: number; + problemsInfos: Map; +} \ No newline at end of file diff --git a/linter/src/LinterRunner.ts b/linter/src/LinterRunner.ts index bd26d271d2d2d05b64996304760ace2a39081c41..b6f0111338a9141b432de8afb37401165336e1a7 100644 --- a/linter/src/LinterRunner.ts +++ b/linter/src/LinterRunner.ts @@ -19,21 +19,19 @@ import { TypeScriptLinter, consoleLog } from './TypeScriptLinter'; import { FaultID, faultsAttrs } from './Problems'; import { parseCommandLine } from './CommandLineParser'; import { LinterConfig } from './TypeScriptLinterConfig'; +import { LintRunResult } from './LintRunResult'; import Logger from '../utils/logger'; import * as fs from 'node:fs'; import * as os from 'node:os'; import * as readline from 'node:readline'; import * as path from 'node:path'; import { compile } from './CompilerWrapper'; -import { CommandLineOptions, LintOptions } from './Common'; +import { CommandLineOptions } from './CommandLineOptions'; +import { LintOptions } from './LintOptions'; import { AutofixInfoSet } from './Autofixer'; const logger = Logger.getLogger(); -export interface LintRunResult { - errorNodes: number; - problemsInfos: Map; -} export function lint(options: LintOptions): LintRunResult { const cmdOptions = options.cmdOptions; diff --git a/linter/src/ProblemInfo.ts b/linter/src/ProblemInfo.ts index f531ac4243952979ae8ef315c4414b0d6728f71a..0339677419324bf539b2ee156f874fc44e3264b3 100644 --- a/linter/src/ProblemInfo.ts +++ b/linter/src/ProblemInfo.ts @@ -15,7 +15,6 @@ import { Autofix } from './Autofixer'; -export enum ProblemSeverity { WARNING = 1, ERROR = 2 } export interface ProblemInfo { line: number; column: number; diff --git a/linter/src/ProblemSeverity.ts b/linter/src/ProblemSeverity.ts new file mode 100644 index 0000000000000000000000000000000000000000..3736c692ef46726f5ecced3be6290c18c371f039 --- /dev/null +++ b/linter/src/ProblemSeverity.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 enum ProblemSeverity { WARNING = 1, ERROR = 2 } diff --git a/linter/src/Problems.ts b/linter/src/Problems.ts index c001b4178e3a43152d0ade022a95353c691893d3..f4c3f3bd86099c344d0f80680ad35cf1a76f4afd 100644 --- a/linter/src/Problems.ts +++ b/linter/src/Problems.ts @@ -14,7 +14,7 @@ */ export enum FaultID { - AnyType, UndefinedValue, SymbolType, TupleType, ObjectLiteralNoContextType, ArrayLiteralNoContextType, + AnyType, SymbolType, TupleType, ObjectLiteralNoContextType, ArrayLiteralNoContextType, ComputedPropertyName, LiteralAsPropertyName, TypeQuery, TupleLiteral, RegexLiteral, IsOperator, DestructuringParameter, YieldExpression, InterfaceOrEnumMerging, InterfaceExtendsClass, IndexMember, WithStatement, ThrowStatement, IndexedAccessType, UnknownType, ForInStatement, InOperator, @@ -22,18 +22,18 @@ export enum FaultID { ObjectTypeLiteral, AddWithWrongType, BitOpWithWrongType, CommaOperator, LimitedReturnTypeInference, ArrowFunctionWithOmittedTypes, LambdaWithTypeParameters, ClassExpression, DestructuringAssignment, DestructuringDeclaration, ForOfNonArray, VarDeclaration, CatchWithUnsupportedType, DeleteOperator, - DeclWithDuplicateName, FuncOptionalParams, UnaryArithmNotNumber, ConstructorType, CallSignature, + DeclWithDuplicateName, UnaryArithmNotNumber, ConstructorType, CallSignature, TypeAssertion, PrivateIdentifier, LocalFunction, SwitchSelectorInvalidType, CaseExpressionNonConst, ConditionalType, MappedType, NamespaceAsObject, NonDeclarationInNamespace, GeneratorFunction, FunctionContainsThis, PropertyAccessByIndex, JsxElement, EnumMemberNonConstInit, ImplementsClass, MultipleStaticBlocks, ThisType, InferType, IntefaceExtendDifProps, StructuralIdentity, TypeOnlyImport, TypeOnlyExport, DefaultImport, - ExportRenaming, ExportListDeclaration, ReExporting, ExportAssignment, ImportAssignment, PropertyRuntimeCheck, - GenericCallNoTypeArgs, InterfaceOptionalProp, ParameterProperties, + ExportListDeclaration, ReExporting, ExportAssignment, ImportAssignment, PropertyRuntimeCheck, + GenericCallNoTypeArgs, ParameterProperties, InstanceofUnsupported, ShorthandAmbientModuleDecl, WildcardsInModuleName, UMDModuleDefinition, JSExtensionInModuleIdent, NewTarget, DynamicImport, DefiniteAssignment, IifeAsNamespace, Prototype, GlobalThis, UtilityType, PropertyDeclOnFunction, FunctionApplyBindCall, ReadonlyArr, ConstAssertion, ImportAssertion, - BigIntLiteral, SpreadOperator, LimitedStdLibApi, + BigIntLiteral, SpreadOperator, LimitedStdLibApi, ErrorSuppression, LAST_ID, // this should always be last enum` } @@ -52,7 +52,6 @@ faultsAttrs[FaultID.PrivateIdentifier] = {migratable: true, cookBookRef: '3',}; faultsAttrs[FaultID.DeclWithDuplicateName] = {migratable: true, cookBookRef: '4',}; faultsAttrs[FaultID.VarDeclaration] = {migratable: true, cookBookRef: '5',}; faultsAttrs[FaultID.AnyType] = {cookBookRef: '8'}; -faultsAttrs[FaultID.UndefinedValue] = {cookBookRef: '8'}; faultsAttrs[FaultID.UnknownType] = {cookBookRef: '8',}; faultsAttrs[FaultID.BigIntLiteral] = {migratable: true, cookBookRef: '10',}; faultsAttrs[FaultID.TupleType] = {cookBookRef: '13',}; @@ -64,12 +63,10 @@ faultsAttrs[FaultID.IndexMember] = {cookBookRef: '17',}; faultsAttrs[FaultID.IntersectionType] = {cookBookRef: '19',}; faultsAttrs[FaultID.ThisType] = {cookBookRef: '21',}; faultsAttrs[FaultID.ConditionalType] = {cookBookRef: '22',}; -faultsAttrs[FaultID.FuncOptionalParams] = {migratable: true, cookBookRef: '24',}; faultsAttrs[FaultID.ParameterProperties] = {migratable: true, cookBookRef: '25',}; faultsAttrs[FaultID.IndexedAccessType] = {cookBookRef: '28',}; faultsAttrs[FaultID.PropertyAccessByIndex] = {migratable: true, cookBookRef: '29',}; faultsAttrs[FaultID.StructuralIdentity] = {cookBookRef: '30',}; -faultsAttrs[FaultID.InterfaceOptionalProp] = {cookBookRef: '33',}; faultsAttrs[FaultID.GenericCallNoTypeArgs] = {cookBookRef: '34',}; faultsAttrs[FaultID.RegexLiteral] = {cookBookRef: '37',}; faultsAttrs[FaultID.ObjectLiteralNoContextType] = {cookBookRef: '38',}; @@ -121,7 +118,6 @@ 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.ExportRenaming] = {migratable: true, cookBookRef: '123',}; faultsAttrs[FaultID.ExportListDeclaration] = {migratable: true, cookBookRef: '124',}; faultsAttrs[FaultID.ReExporting] = {cookBookRef: '125',}; faultsAttrs[FaultID.ExportAssignment] = {cookBookRef: '126',}; @@ -143,3 +139,4 @@ faultsAttrs[FaultID.ReadonlyArr] = {migratable: true, cookBookRef: '141',}; faultsAttrs[FaultID.ConstAssertion] = {cookBookRef: '142',}; faultsAttrs[FaultID.ImportAssertion] = {cookBookRef: '143',}; faultsAttrs[FaultID.LimitedStdLibApi] = {cookBookRef: '144',}; +faultsAttrs[FaultID.ErrorSuppression] = {cookBookRef: '146',}; diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index b9db9026c2eeea0c204f07a54a31884545458ef0..5dcc8e50124ee504266a7dd4a05a1fdd5aaf36be 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -20,7 +20,8 @@ import { cookBookMsg, cookBookTag } from './CookBookMsg'; import { LinterConfig } from './TypeScriptLinterConfig'; import { Autofix, AutofixInfoSet } from './Autofixer'; import * as Autofixer from './Autofixer'; -import { ProblemInfo, ProblemSeverity } from './ProblemInfo'; +import { ProblemInfo } from './ProblemInfo'; +import { ProblemSeverity } from './ProblemSeverity'; import Logger from '../utils/logger'; const logger = Logger.getLogger(); @@ -117,13 +118,16 @@ export class TypeScriptLinter { [ts.SyntaxKind.NonNullExpression, this.handleNonNullExpression], ]); - public incrementCounters(node: ts.Node, faultId: number, autofixable: boolean = false, autofix?: Autofix[],) { + 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 return; + const startPos = this.tsUtils.getStartPos(node); + const endPos = this.tsUtils.getEndPos(node); + this.nodeCounters[faultId]++; // TSC counts lines and columns from zero - let { line, character } = this.sourceFile!.getLineAndCharacterOfPosition(node.getStart()); + let { line, character } = this.sourceFile!.getLineAndCharacterOfPosition(startPos); ++line; ++character; @@ -141,8 +145,8 @@ export class TypeScriptLinter { line: line, column: character, endColumn: this.getNodeOrLineEnd(node, line), - start: node.getStart(), - end: node.getEnd(), + start: startPos, + end: endPos, type: faultType, severity: severity, problem: FaultID[faultId], @@ -187,7 +191,9 @@ export class TypeScriptLinter { if (LinterConfig.tsSyntaxKindNames[node.kind] === 'StructDeclaration') { self.handleStructDeclaration(node); return; - } + } + + self.handleComments(node); if (LinterConfig.terminalTokens.has(node.kind)) return; @@ -439,11 +445,11 @@ export class TypeScriptLinter { * @param startLine node's start line * @returns column index of the node's end if node is located on one line, line's end otherwise */ - private getNodeOrLineEnd(node: ts.Node, startLine: number): number { - const pos = this.sourceFile!.getLineAndCharacterOfPosition(node.getEnd()); + private getNodeOrLineEnd(node: ts.Node | ts.CommentRange, startLine: number): number { + const pos = this.sourceFile!.getLineAndCharacterOfPosition(this.tsUtils.getEndPos(node)); return pos.line === startLine ? pos.character - : this.sourceFile!.getLineEndOfPosition(node.getStart()); + : this.sourceFile!.getLineEndOfPosition(this.tsUtils.getStartPos(node)); } private handleObjectLiteralExpression(node: ts.Node) { @@ -545,15 +551,6 @@ export class TypeScriptLinter { if (interfaceNode.heritageClauses) this.interfaceInharitanceLint(node, interfaceNode.heritageClauses); - for (const typeElem of interfaceNode.members) { - // ArkTs does not support otional properties of primitive types. - if (typeElem.questionToken && ts.isPropertySignature(typeElem)) { - let type = this.tsTypeChecker.getTypeAtLocation(typeElem.name); - if (type && this.tsUtils.isPrimitiveType(type)) - this.incrementCounters(typeElem, FaultID.InterfaceOptionalProp); - } - } - this.countDeclarationsWithDuplicateName( this.tsTypeChecker.getSymbolAtLocation(interfaceNode.name), interfaceNode ); @@ -630,6 +627,9 @@ export class TypeScriptLinter { if (this.isIIFEasNamespace(propertyAccessNode)) this.incrementCounters(node, FaultID.IifeAsNamespace); if (this.isPrototypePropertyAccess(propertyAccessNode)) this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); + let symbol = this.tsTypeChecker.getSymbolAtLocation(propertyAccessNode); + if( !!symbol && this.tsUtils.isSymbolAPI(symbol)) + this.incrementCounters(node, FaultID.SymbolType); } private handlePropertyAssignmentOrDeclaration(node: ts.Node) { @@ -729,10 +729,6 @@ export class TypeScriptLinter { this.tsTypeChecker.getSymbolAtLocation(tsFunctionDeclaration.name), tsFunctionDeclaration ); - let tsParams = tsFunctionDeclaration.parameters; - for (const tsParam of tsParams) - if (tsParam.questionToken) this.handleOptionalParam(tsParam); - if (tsFunctionDeclaration.body && this.functionContainsThis(tsFunctionDeclaration.body)) this.incrementCounters(node, FaultID.FunctionContainsThis); @@ -816,13 +812,6 @@ export class TypeScriptLinter { return hasLimitedTypeInference; } - private handleOptionalParam(tsParam: ts.ParameterDeclaration) { - const paramType = this.tsTypeChecker.getTypeAtLocation(tsParam); - if (this.tsUtils.isNumberLikeType(paramType) || this.tsUtils.isBooleanType(paramType)) { - this.incrementCounters(tsParam, FaultID.FuncOptionalParams); - } - } - private handlePrefixUnaryExpression(node: ts.Node) { let tsUnaryArithm = node as ts.PrefixUnaryExpression; let tsUnaryOp = tsUnaryArithm.operator; @@ -911,11 +900,6 @@ export class TypeScriptLinter { !this.tsUtils.relatedByInheritanceOrIdentical(rightOperandType, leftOperandType) ) this.incrementCounters(tsBinaryExpr, FaultID.StructuralIdentity); - if ( - ts.isIdentifier(tsRhsExpr) && tsRhsExpr.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword && - (!leftOperandType.isUnion() || this.tsUtils.isUnsupportedUnionType(leftOperandType)) - ) - this.incrementCounters(tsRhsExpr, FaultID.UndefinedValue); } } @@ -962,11 +946,6 @@ export class TypeScriptLinter { !this.tsUtils.relatedByInheritanceOrIdentical(tsInitType, tsVarType) ) this.incrementCounters(tsVarDecl, FaultID.StructuralIdentity); - if ( - ts.isIdentifier(tsVarInit) && tsVarInit.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword && - (!tsVarType.isUnion() || this.tsUtils.isUnsupportedUnionType(tsVarType)) - ) - this.incrementCounters(tsVarDecl.initializer, FaultID.UndefinedValue); } } @@ -1271,9 +1250,6 @@ export class TypeScriptLinter { this.incrementCounters(exportClause, FaultID.ExportListDeclaration); for (const exportSpec of exportClause.elements) { - if (exportSpec.propertyName) - this.incrementCounters(exportSpec, FaultID.ExportRenaming); - if (exportSpec.isTypeOnly) { let autofix: Autofix[] | undefined; if (this.autofixesInfo.shouldAutofix(exportSpec, FaultID.TypeOnlyExport)) @@ -1390,11 +1366,6 @@ export class TypeScriptLinter { !this.tsUtils.relatedByInheritanceOrIdentical(tsArgType, tsParamType) ) this.incrementCounters(tsArg, FaultID.StructuralIdentity); - if ( - ts.isIdentifier(tsArg) && tsArg.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword && - (!tsParamType.isUnion() || this.tsUtils.isUnsupportedUnionType(tsParamType)) - ) - this.incrementCounters(tsArg, FaultID.UndefinedValue); } } } @@ -1416,6 +1387,9 @@ export class TypeScriptLinter { ) { this.incrementCounters(callExpr, FaultID.LimitedStdLibApi); } + if( this.tsUtils.isSymbolAPI(sym)) { + this.incrementCounters(callExpr, FaultID.SymbolType); + } } } @@ -1504,6 +1478,41 @@ export class TypeScriptLinter { } } + private handleComments(node: ts.Node) { + // Note: Same comment may be owned by several nodes if their + // start/end position matches. Thus, look for the most parental + // owner of the specific comment (by the node's position). + const srcText = node.getSourceFile().getFullText(); + + const parent = node.parent; + if (!parent || parent.getFullStart() !== node.getFullStart()) { + let leadingComments = ts.getLeadingCommentRanges(srcText, node.getFullStart()); + if (leadingComments) { + for (const comment of leadingComments) { + this.checkErrorSuppressingAnnotation(comment, srcText); + } + } + } + + if (!parent || parent.getEnd() !== node.getEnd()) { + let trailingComments = ts.getTrailingCommentRanges(srcText, node.getEnd()); + if (trailingComments) { + for (const comment of trailingComments) { + this.checkErrorSuppressingAnnotation(comment, srcText); + } + } + } + } + + 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); + + if (commentContent.includes('@ts-ignore') || commentContent.includes('@ts-nocheck')) + this.incrementCounters(comment, FaultID.ErrorSuppression); + } + public lint(sourceFile: ts.SourceFile) { this.sourceFile = sourceFile; this.visitTSNode(this.sourceFile); diff --git a/linter/src/TypeScriptLinterConfig.ts b/linter/src/TypeScriptLinterConfig.ts index 806e5e30a24090a7bbc5d16a3af363164f5e2987..c4cdb85389963e414b17a81ef6fae7ceaf9696f8 100644 --- a/linter/src/TypeScriptLinterConfig.ts +++ b/linter/src/TypeScriptLinterConfig.ts @@ -32,7 +32,6 @@ export class LinterConfig { static { // Set the feature descriptions (for the output). LinterConfig.nodeDesc[FaultID.AnyType] = '"any" type'; - LinterConfig.nodeDesc[FaultID.UndefinedValue] = '"undefined" value in wrong context'; LinterConfig.nodeDesc[FaultID.SymbolType] = '"symbol" type'; LinterConfig.nodeDesc[FaultID.TupleType] = 'Tuple type'; LinterConfig.nodeDesc[FaultID.ObjectLiteralNoContextType] = 'Object literals with no context Class or Interface type'; @@ -73,7 +72,6 @@ export class LinterConfig { LinterConfig.nodeDesc[FaultID.CatchWithUnsupportedType] = '"catch" clause with unsupported exception type'; LinterConfig.nodeDesc[FaultID.DeleteOperator] = '"delete" operations'; LinterConfig.nodeDesc[FaultID.DeclWithDuplicateName] = 'Declarations with duplicate name'; - LinterConfig.nodeDesc[FaultID.FuncOptionalParams] = 'Optional parameters in function'; LinterConfig.nodeDesc[FaultID.UnaryArithmNotNumber] = 'Unary arithmetics with not-numeric values'; LinterConfig.nodeDesc[FaultID.ConstructorType] = 'Constructor type'; LinterConfig.nodeDesc[FaultID.CallSignature] = 'Call signatures'; @@ -100,14 +98,12 @@ export class LinterConfig { LinterConfig.nodeDesc[FaultID.TypeOnlyImport] = 'Type-only imports'; LinterConfig.nodeDesc[FaultID.TypeOnlyExport] = 'Type-only exports'; LinterConfig.nodeDesc[FaultID.DefaultImport] = 'Default import declarations'; - LinterConfig.nodeDesc[FaultID.ExportRenaming] = 'Renaming in export declarations'; LinterConfig.nodeDesc[FaultID.ExportListDeclaration] = 'Export list declarations'; LinterConfig.nodeDesc[FaultID.ReExporting] = 'Re-exporting declarations'; LinterConfig.nodeDesc[FaultID.ExportAssignment] = 'Export assignments (export = ..)'; LinterConfig.nodeDesc[FaultID.ImportAssignment] = 'Import assignments (import = ..)'; LinterConfig.nodeDesc[FaultID.PropertyRuntimeCheck] = 'Property-based runtime checks'; LinterConfig.nodeDesc[FaultID.GenericCallNoTypeArgs] = 'Generic calls without type arguments'; - LinterConfig.nodeDesc[FaultID.InterfaceOptionalProp] = 'Interface optional property'; LinterConfig.nodeDesc[FaultID.ParameterProperties] = 'Parameter properties in constructor'; LinterConfig.nodeDesc[FaultID.InstanceofUnsupported] = 'Left-hand side of "instanceof" is wrong'; LinterConfig.nodeDesc[FaultID.ShorthandAmbientModuleDecl] = 'Shorthand ambient module declaration'; @@ -129,6 +125,7 @@ export class LinterConfig { LinterConfig.nodeDesc[FaultID.BigIntLiteral] = 'BigInt literal'; LinterConfig.nodeDesc[FaultID.SpreadOperator] = 'Spread operation'; LinterConfig.nodeDesc[FaultID.LimitedStdLibApi] = 'Limited standard library API'; + LinterConfig.nodeDesc[FaultID.ErrorSuppression] = 'Error suppression annotation'; LinterConfig.initTsSyntaxKindNames(); } diff --git a/linter/src/Utils.ts b/linter/src/Utils.ts index edbb8760e6df964429d8e54d52b2f2f3be59abf4..67421d305f2ffdf418251dd474b6ef534bd913be 100644 --- a/linter/src/Utils.ts +++ b/linter/src/Utils.ts @@ -15,7 +15,7 @@ import * as ts from 'typescript'; import { ProblemInfo } from './ProblemInfo'; -import { AutofixInfo } from './Common'; +import { AutofixInfo } from './AutofixInfo'; export function logTscDiagnostic(diagnostics: readonly ts.Diagnostic[], log: (message: any, ...args: any[]) => void) { diagnostics.forEach((diagnostic) => { @@ -723,7 +723,27 @@ export class TsUtils { return !!parentName && (parentName === 'ArrayBuffer' || parentName === 'ArrayBufferConstructor'); } + public isSymbolAPI(symbol: ts.Symbol): boolean { + let parentName = this.getParentSymbolName(symbol); + if (parentName) + return (parentName === 'Symbol' || parentName === 'SymbolConstructor'); + else + return ( symbol.escapedName === 'Symbol' || symbol.escapedName === 'SymbolConstructor'); + } + public isDefaultImport(importSpec: ts.ImportSpecifier): boolean { return importSpec?.propertyName?.text === 'default'; } + + public getStartPos(nodeOrComment: ts.Node | ts.CommentRange): number { + 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) + ? (nodeOrComment as ts.CommentRange).end + : (nodeOrComment as ts.Node).getEnd(); + } } diff --git a/linter/test/func_def_params.ts.strict.json b/linter/test/func_def_params.ts.strict.json index 528bb75d6484cb46feff2138266e0d75aa1241d8..9ef9898408bf9c5ea3e83bb864a24990bad74aa7 100644 --- a/linter/test/func_def_params.ts.strict.json +++ b/linter/test/func_def_params.ts.strict.json @@ -14,20 +14,5 @@ "limitations under the License." ], "nodes": [ - { - "line": 16, - "column": 14, - "problem": "FuncOptionalParams" - }, - { - "line": 20, - "column": 26, - "problem": "FuncOptionalParams" - }, - { - "line": 20, - "column": 38, - "problem": "FuncOptionalParams" - } ] } \ No newline at end of file diff --git a/linter/test/function_overload.ts.strict.json b/linter/test/function_overload.ts.strict.json index 6753bf2e36442679b255ef4642bbe403ddf7a29d..13aacbf8bddbb173935d625cc6d39095c506a328 100644 --- a/linter/test/function_overload.ts.strict.json +++ b/linter/test/function_overload.ts.strict.json @@ -14,16 +14,6 @@ "limitations under the License." ], "nodes": [ - { - "line": 18, - "column": 41, - "problem": "FuncOptionalParams" - }, - { - "line": 18, - "column": 53, - "problem": "FuncOptionalParams" - }, { "line": 37, "column": 19, diff --git a/linter/test/interfaces_optional_props.ts.relax.json b/linter/test/interfaces_optional_props.ts.relax.json index 550d662051c490e8424719f43f47996664061682..18ac144f5d3d23452ecc2c434dc236ece2a7b633 100644 --- a/linter/test/interfaces_optional_props.ts.relax.json +++ b/linter/test/interfaces_optional_props.ts.relax.json @@ -14,10 +14,5 @@ "limitations under the License." ], "nodes": [ - { - "line": 17, - "column": 3, - "problem": "InterfaceOptionalProp" - } ] } \ No newline at end of file diff --git a/linter/test/interfaces_optional_props.ts.strict.json b/linter/test/interfaces_optional_props.ts.strict.json index 550d662051c490e8424719f43f47996664061682..18ac144f5d3d23452ecc2c434dc236ece2a7b633 100644 --- a/linter/test/interfaces_optional_props.ts.strict.json +++ b/linter/test/interfaces_optional_props.ts.strict.json @@ -14,10 +14,5 @@ "limitations under the License." ], "nodes": [ - { - "line": 17, - "column": 3, - "problem": "InterfaceOptionalProp" - } ] } \ No newline at end of file diff --git a/linter/test/modules.ts.autofix.json b/linter/test/modules.ts.autofix.json index 826b31c754f50bf56b585c20dc084b7356afd0e3..fbb25f5c24f414399c1d237bba3b86862335a93b 100755 --- a/linter/test/modules.ts.autofix.json +++ b/linter/test/modules.ts.autofix.json @@ -176,24 +176,12 @@ "problem": "ExportListDeclaration", "autofixable": false }, - { - "line": 97, - "column": 15, - "problem": "ExportRenaming", - "autofixable": false - }, { "line": 98, "column": 8, "problem": "ExportListDeclaration", "autofixable": false }, - { - "line": 98, - "column": 10, - "problem": "ExportRenaming", - "autofixable": false - }, { "line": 98, "column": 10, @@ -213,30 +201,12 @@ "problem": "ExportListDeclaration", "autofixable": false }, - { - "line": 101, - "column": 10, - "problem": "ExportRenaming", - "autofixable": false - }, { "line": 103, "column": 8, "problem": "ExportListDeclaration", "autofixable": false }, - { - "line": 103, - "column": 15, - "problem": "ExportRenaming", - "autofixable": false - }, - { - "line": 103, - "column": 27, - "problem": "ExportRenaming", - "autofixable": false - }, { "line": 105, "column": 1, diff --git a/linter/test/modules.ts.strict.json b/linter/test/modules.ts.strict.json index 5390ddba5623150b1d35bbd04099b917330b4bf4..899f9cd50ed3fc008052efed1356a04de7e21627 100644 --- a/linter/test/modules.ts.strict.json +++ b/linter/test/modules.ts.strict.json @@ -114,21 +114,11 @@ "column": 13, "problem": "ExportListDeclaration" }, - { - "line": 97, - "column": 15, - "problem": "ExportRenaming" - }, { "line": 98, "column": 8, "problem": "ExportListDeclaration" }, - { - "line": 98, - "column": 10, - "problem": "ExportRenaming" - }, { "line": 98, "column": 10, @@ -139,26 +129,11 @@ "column": 8, "problem": "ExportListDeclaration" }, - { - "line": 101, - "column": 10, - "problem": "ExportRenaming" - }, { "line": 103, "column": 8, "problem": "ExportListDeclaration" }, - { - "line": 103, - "column": 15, - "problem": "ExportRenaming" - }, - { - "line": 103, - "column": 27, - "problem": "ExportRenaming" - }, { "line": 105, "column": 1, diff --git a/linter/test/symbol_api.ts b/linter/test/symbol_api.ts new file mode 100644 index 0000000000000000000000000000000000000000..53ab8433431d8fa1098cb3ebafa10cd4cd2c8923 --- /dev/null +++ b/linter/test/symbol_api.ts @@ -0,0 +1,30 @@ +/* + * 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. + */ + +let a = Symbol.asyncIterator; +let b = Symbol.hasInstance; +let c = Symbol.isConcatSpreadable; +let d = Symbol.iterator; +let e = Symbol.match; +let f = Symbol.replace; +let g = Symbol.search; +let h = Symbol.species; +let i = Symbol.split; +let j = Symbol.toPrimitive; +let k = Symbol.toStringTag; +let l = Symbol.unscopables; + +let m = Symbol(); + diff --git a/linter/test/symbol_api.ts.autofix.skip b/linter/test/symbol_api.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/linter/test/symbol_api.ts.relax.json b/linter/test/symbol_api.ts.relax.json new file mode 100644 index 0000000000000000000000000000000000000000..dcdf059f710be2b98ef7132bf5adf2ec1c6ce311 --- /dev/null +++ b/linter/test/symbol_api.ts.relax.json @@ -0,0 +1,83 @@ +{ + "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": 16, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 17, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 18, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 19, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 20, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 21, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 22, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 23, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 24, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 25, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 26, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 27, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 29, + "column": 9, + "problem": "SymbolType" + } + ] +} \ No newline at end of file diff --git a/linter/test/symbol_api.ts.strict.json b/linter/test/symbol_api.ts.strict.json new file mode 100644 index 0000000000000000000000000000000000000000..dcdf059f710be2b98ef7132bf5adf2ec1c6ce311 --- /dev/null +++ b/linter/test/symbol_api.ts.strict.json @@ -0,0 +1,83 @@ +{ + "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": 16, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 17, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 18, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 19, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 20, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 21, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 22, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 23, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 24, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 25, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 26, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 27, + "column": 9, + "problem": "SymbolType" + }, + { + "line": 29, + "column": 9, + "problem": "SymbolType" + } + ] +} \ No newline at end of file diff --git a/linter/test/this_type.ts b/linter/test/this_type.ts index cba3c78c9bb0f33e761256046d854143f07f93a8..ce8847152b0a3f3bf691fffa5ee6dd4dc9c7810a 100644 --- a/linter/test/this_type.ts +++ b/linter/test/this_type.ts @@ -48,3 +48,9 @@ const stringAdder: StringAdder = new StringAdder(); const str = stringAdder.addFoo().addBar().addGreeting('Jane').getValue(); console.log(str); + +class C { + m(c: this): void { + console.log(c); + } +} \ No newline at end of file diff --git a/linter/test/this_type.ts.relax.json b/linter/test/this_type.ts.relax.json index ec1dbd495c0ee5c23234a416f71611e41a871452..3b9cf7c60737c2ce216f0471a9891b55f3695bdb 100644 --- a/linter/test/this_type.ts.relax.json +++ b/linter/test/this_type.ts.relax.json @@ -43,6 +43,11 @@ "line": 41, "column": 30, "problem": "ThisType" + }, + { + "line": 53, + "column": 8, + "problem": "ThisType" } ] } \ No newline at end of file diff --git a/linter/test/this_type.ts.strict.json b/linter/test/this_type.ts.strict.json index ec1dbd495c0ee5c23234a416f71611e41a871452..3b9cf7c60737c2ce216f0471a9891b55f3695bdb 100644 --- a/linter/test/this_type.ts.strict.json +++ b/linter/test/this_type.ts.strict.json @@ -43,6 +43,11 @@ "line": 41, "column": 30, "problem": "ThisType" + }, + { + "line": 53, + "column": 8, + "problem": "ThisType" } ] } \ No newline at end of file diff --git a/linter/test/ts_ignore.ts b/linter/test/ts_ignore.ts new file mode 100644 index 0000000000000000000000000000000000000000..de908760e5122319b0940ade9d5e27cf5418e7a5 --- /dev/null +++ b/linter/test/ts_ignore.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. + */ + +// @ts-ignore +let x: number = null; // No error, type checking is suppressed +let y: number = null; // Compile-time error + +if (false) { + /* @ts-ignore: Unreachable code error */ + console.log("hello"); +} + +let a: number = 0 // @ts-ignore: suppresses CTE for the next line +let b: number = null; \ No newline at end of file diff --git a/linter/test/ts_ignore.ts.autofix.skip b/linter/test/ts_ignore.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/linter/test/ts_ignore.ts.relax.json b/linter/test/ts_ignore.ts.relax.json new file mode 100644 index 0000000000000000000000000000000000000000..76b4c6138f79897e52166c1074f9184e02b5c347 --- /dev/null +++ b/linter/test/ts_ignore.ts.relax.json @@ -0,0 +1,33 @@ +{ + "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": 16, + "column": 1, + "problem": "ErrorSuppression" + }, + { + "line": 21, + "column": 3, + "problem": "ErrorSuppression" + }, + { + "line": 25, + "column": 19, + "problem": "ErrorSuppression" + } + ] +} \ No newline at end of file diff --git a/linter/test/ts_ignore.ts.strict.json b/linter/test/ts_ignore.ts.strict.json new file mode 100644 index 0000000000000000000000000000000000000000..76b4c6138f79897e52166c1074f9184e02b5c347 --- /dev/null +++ b/linter/test/ts_ignore.ts.strict.json @@ -0,0 +1,33 @@ +{ + "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": 16, + "column": 1, + "problem": "ErrorSuppression" + }, + { + "line": 21, + "column": 3, + "problem": "ErrorSuppression" + }, + { + "line": 25, + "column": 19, + "problem": "ErrorSuppression" + } + ] +} \ No newline at end of file diff --git a/linter/test/ts_nocheck.ts b/linter/test/ts_nocheck.ts new file mode 100644 index 0000000000000000000000000000000000000000..52faa8e8aad4061901fc96edb304c8f08c7d409b --- /dev/null +++ b/linter/test/ts_nocheck.ts @@ -0,0 +1,22 @@ +/* + * 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. + */ + +// @ts-nocheck +let x: number = null; // No error, type checking is suppressed +let y: number = null; // No error, type checking is suppressed + +if (false) { + console.log("hello"); // No error, type checking is suppressed +} \ No newline at end of file diff --git a/linter/test/ts_nocheck.ts.autofix.skip b/linter/test/ts_nocheck.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/linter/test/ts_nocheck.ts.relax.json b/linter/test/ts_nocheck.ts.relax.json new file mode 100644 index 0000000000000000000000000000000000000000..63ef021ed385a9af9847cc67ab410d66aa52e0f8 --- /dev/null +++ b/linter/test/ts_nocheck.ts.relax.json @@ -0,0 +1,23 @@ +{ + "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": 16, + "column": 1, + "problem": "ErrorSuppression" + } + ] +} \ No newline at end of file diff --git a/linter/test/ts_nocheck.ts.strict.json b/linter/test/ts_nocheck.ts.strict.json new file mode 100644 index 0000000000000000000000000000000000000000..63ef021ed385a9af9847cc67ab410d66aa52e0f8 --- /dev/null +++ b/linter/test/ts_nocheck.ts.strict.json @@ -0,0 +1,23 @@ +{ + "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": 16, + "column": 1, + "problem": "ErrorSuppression" + } + ] +} \ No newline at end of file diff --git a/linter/test/types.ts.autofix.json b/linter/test/types.ts.autofix.json index 328cbb300c5d30704ee475780c5d147b28700155..54f54a35a9db47948a262a2d229df283ac6994ba 100644 --- a/linter/test/types.ts.autofix.json +++ b/linter/test/types.ts.autofix.json @@ -14,12 +14,6 @@ "limitations under the License." ], "nodes": [ - { - "line": 17, - "column": 21, - "problem": "UndefinedValue", - "autofixable": false - }, { "line": 17, "column": 15, @@ -346,24 +340,6 @@ "replacementText": "x: T" } ] - }, - { - "line": 148, - "column": 7, - "problem": "UndefinedValue", - "autofixable": false - }, - { - "line": 149, - "column": 18, - "problem": "UndefinedValue", - "autofixable": false - }, - { - "line": 150, - "column": 17, - "problem": "UndefinedValue", - "autofixable": false } ] } \ No newline at end of file diff --git a/linter/test/types.ts.relax.json b/linter/test/types.ts.relax.json index 898e8df5a051af14e25baf8f87f90016e1475da5..2a6cbf9a643d0330d6cf70cb9066ccaf9d10e220 100644 --- a/linter/test/types.ts.relax.json +++ b/linter/test/types.ts.relax.json @@ -14,11 +14,6 @@ "limitations under the License." ], "nodes": [ - { - "line": 17, - "column": 21, - "problem": "UndefinedValue" - }, { "line": 17, "column": 15, @@ -183,21 +178,6 @@ "line": 128, "column": 18, "problem": "ObjectLiteralNoContextType" - }, - { - "line": 148, - "column": 7, - "problem": "UndefinedValue" - }, - { - "line": 149, - "column": 18, - "problem": "UndefinedValue" - }, - { - "line": 150, - "column": 17, - "problem": "UndefinedValue" } ] } \ No newline at end of file diff --git a/linter/test/types.ts.strict.json b/linter/test/types.ts.strict.json index 4f894ca455f2e3a7ace29a853b7dc7beb7d0e3f2..47a59aca914387d738f18ff2ad913bc20f732720 100644 --- a/linter/test/types.ts.strict.json +++ b/linter/test/types.ts.strict.json @@ -14,11 +14,6 @@ "limitations under the License." ], "nodes": [ - { - "line": 17, - "column": 21, - "problem": "UndefinedValue" - }, { "line": 17, "column": 15, @@ -238,21 +233,6 @@ "line": 139, "column": 22, "problem": "ArrowFunctionWithOmittedTypes" - }, - { - "line": 148, - "column": 7, - "problem": "UndefinedValue" - }, - { - "line": 149, - "column": 18, - "problem": "UndefinedValue" - }, - { - "line": 150, - "column": 17, - "problem": "UndefinedValue" } ] } \ No newline at end of file diff --git a/linter/test/unique_names.ts.strict.json b/linter/test/unique_names.ts.strict.json index f9108f99bc8e2f38b383af8f63839212bd04fe8b..e868237f3e5f358a4edff2817bc151f61a549431 100644 --- a/linter/test/unique_names.ts.strict.json +++ b/linter/test/unique_names.ts.strict.json @@ -129,11 +129,6 @@ "column": 1, "problem": "DeclWithDuplicateName" }, - { - "line": 68, - "column": 12, - "problem": "FuncOptionalParams" - }, { "line": 75, "column": 9, diff --git a/linter/test/utility_types.ts.relax.json b/linter/test/utility_types.ts.relax.json index 6f87877211bccab0af5c255d5226bf79b85475dd..ab7e78c41521bbf11509a21c189d282e843addb4 100644 --- a/linter/test/utility_types.ts.relax.json +++ b/linter/test/utility_types.ts.relax.json @@ -59,11 +59,6 @@ "column": 35, "problem": "ObjectLiteralNoContextType" }, - { - "line": 46, - "column": 5, - "problem": "InterfaceOptionalProp" - }, { "line": 51, "column": 15, diff --git a/linter/test/utility_types.ts.strict.json b/linter/test/utility_types.ts.strict.json index 3d80d3b123d99dc71ac295e0b5e58909b2427ae5..1e90114550a9c46d24dc3948f012bdd386496d7e 100644 --- a/linter/test/utility_types.ts.strict.json +++ b/linter/test/utility_types.ts.strict.json @@ -64,11 +64,6 @@ "column": 35, "problem": "ObjectLiteralNoContextType" }, - { - "line": 46, - "column": 5, - "problem": "InterfaceOptionalProp" - }, { "line": 51, "column": 15,