From 1261aadeef76c0a185863da067ca790d9af31b89 Mon Sep 17 00:00:00 2001 From: Ilya Trubachev Date: Fri, 22 Sep 2023 17:08:25 +0300 Subject: [PATCH] relax recipe 135 Signed-off-by: Ilya Trubachev --- linter-4.2/docs/rules/recipe135.md | 39 -------- linter-4.2/src/CookBookMsg.ts | 2 +- linter-4.2/src/Problems.ts | 3 +- linter-4.2/src/TypeScriptLinter.ts | 29 +----- linter-4.2/src/TypeScriptLinterConfig.ts | 1 - .../test/{iife_as_namespace.ts => iife.ts} | 36 +------ ...e.ts.autofix.skip => iife.ts.autofix.skip} | 0 .../test/iife.ts.relax.json | 63 +----------- ...pace.ts.relax.json => iife.ts.strict.json} | 65 +----------- .../test/iife_as_namespace.ts.strict.json | 98 ------------------- linter-4.2/test_rules/rule135.ts | 8 -- linter-4.2/test_rules/rule135.ts.autofix.json | 43 -------- linter-4.2/test_rules/rule135.ts.relax.json | 11 --- linter-4.2/test_rules/rule135.ts.strict.json | 32 ------ linter/docs/rules/recipe135.md | 39 -------- linter/src/CookBookMsg.ts | 2 +- linter/src/FaultAttrs.ts | 1 - linter/src/FaultDesc.ts | 1 - linter/src/Problems.ts | 2 +- linter/src/TypeScriptLinter.ts | 29 ------ linter/test/{iife_as_namespace.ts => iife.ts} | 36 +------ ...e.ts.autofix.skip => iife.ts.autofix.skip} | 0 linter/test/iife.ts.relax.json | 17 ++++ linter/test/iife.ts.strict.json | 17 ++++ linter/test/iife_as_namespace.ts.strict.json | 98 ------------------- linter/test_rules/rule135.ts | 8 -- linter/test_rules/rule135.ts.autofix.json | 43 -------- linter/test_rules/rule135.ts.relax.json | 11 --- linter/test_rules/rule135.ts.strict.json | 32 ------ 29 files changed, 50 insertions(+), 716 deletions(-) delete mode 100644 linter-4.2/docs/rules/recipe135.md rename linter-4.2/test/{iife_as_namespace.ts => iife.ts} (47%) rename linter-4.2/test/{iife_as_namespace.ts.autofix.skip => iife.ts.autofix.skip} (100%) rename linter/test/iife_as_namespace.ts.relax.json => linter-4.2/test/iife.ts.relax.json (34%) rename linter-4.2/test/{iife_as_namespace.ts.relax.json => iife.ts.strict.json} (34%) delete mode 100644 linter-4.2/test/iife_as_namespace.ts.strict.json delete mode 100644 linter-4.2/test_rules/rule135.ts delete mode 100644 linter-4.2/test_rules/rule135.ts.autofix.json delete mode 100644 linter-4.2/test_rules/rule135.ts.relax.json delete mode 100644 linter-4.2/test_rules/rule135.ts.strict.json delete mode 100644 linter/docs/rules/recipe135.md rename linter/test/{iife_as_namespace.ts => iife.ts} (47%) rename linter/test/{iife_as_namespace.ts.autofix.skip => iife.ts.autofix.skip} (100%) create mode 100644 linter/test/iife.ts.relax.json create mode 100644 linter/test/iife.ts.strict.json delete mode 100644 linter/test/iife_as_namespace.ts.strict.json delete mode 100644 linter/test_rules/rule135.ts delete mode 100644 linter/test_rules/rule135.ts.autofix.json delete mode 100644 linter/test_rules/rule135.ts.relax.json delete mode 100644 linter/test_rules/rule135.ts.strict.json diff --git a/linter-4.2/docs/rules/recipe135.md b/linter-4.2/docs/rules/recipe135.md deleted file mode 100644 index df981900a..000000000 --- a/linter-4.2/docs/rules/recipe135.md +++ /dev/null @@ -1,39 +0,0 @@ -# IIFEs as namespace declarations are not supported - -Rule ``arkts-no-iife`` - -**Severity: error** - -ArkTS does not support IIFEs as namespace declarations because anonymous -functions in the language cannot serve as namespaces. -Use regular syntax for namespaces instead. - - -## TypeScript - - -``` - - var C = (function() { - function C(n: number) { - this.p = n // Compile-time error only with noImplicitThis - } - C.staticProperty = 0 - return C - })() - C.staticProperty = 1 - -``` - -## ArkTS - - -``` - - namespace C { - // ... - } - -``` - - diff --git a/linter-4.2/src/CookBookMsg.ts b/linter-4.2/src/CookBookMsg.ts index 684402979..a8e57eb0b 100644 --- a/linter-4.2/src/CookBookMsg.ts +++ b/linter-4.2/src/CookBookMsg.ts @@ -154,7 +154,7 @@ cookBookTag[131] = ''; cookBookTag[132] = '"new.target" is not supported (arkts-no-new-target)'; cookBookTag[133] = ''; cookBookTag[134] = 'Definite assignment assertions are not supported (arkts-no-definite-assignment)'; -cookBookTag[135] = 'IIFEs as namespace declarations are not supported (arkts-no-iife)'; +cookBookTag[135] = ''; cookBookTag[136] = 'Prototype assignment is not supported (arkts-no-prototype-assignment)'; cookBookTag[137] = '"globalThis" is not supported (arkts-no-globalthis)'; cookBookTag[138] = 'Some of utility types are not supported (arkts-no-utility-types)'; diff --git a/linter-4.2/src/Problems.ts b/linter-4.2/src/Problems.ts index dea592e84..a912a3134 100644 --- a/linter-4.2/src/Problems.ts +++ b/linter-4.2/src/Problems.ts @@ -31,7 +31,7 @@ export enum FaultID { ExportAssignment, ImportAssignment, PropertyRuntimeCheck, GenericCallNoTypeArgs, ParameterProperties, InstanceofUnsupported, ShorthandAmbientModuleDecl, WildcardsInModuleName, UMDModuleDefinition, - NewTarget, DefiniteAssignment, IifeAsNamespace, Prototype, GlobalThis, + NewTarget, DefiniteAssignment, Prototype, GlobalThis, UtilityType, PropertyDeclOnFunction, FunctionApplyBindCall, ConstAssertion, ImportAssertion, SpreadOperator, LimitedStdLibApi, ErrorSuppression, StrictDiagnostic, UnsupportedDecorators, ImportAfterStatement, EsObjectType, EsObjectAssignment, EsObjectAccess, @@ -121,7 +121,6 @@ faultsAttrs[FaultID.WildcardsInModuleName] = {cookBookRef: '129',}; faultsAttrs[FaultID.UMDModuleDefinition] = {cookBookRef: '130',}; faultsAttrs[FaultID.NewTarget] = {cookBookRef: '132',}; faultsAttrs[FaultID.DefiniteAssignment] = {cookBookRef: '134',}; -faultsAttrs[FaultID.IifeAsNamespace] = {cookBookRef: '135',}; faultsAttrs[FaultID.Prototype] = {cookBookRef: '136',}; faultsAttrs[FaultID.GlobalThis] = {cookBookRef: '137',}; faultsAttrs[FaultID.UtilityType] = {cookBookRef: '138',}; diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index 9203844e8..f8ea75df6 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -404,29 +404,6 @@ export class TypeScriptLinter { ); } - private isIIFEasNamespace(tsExpr: ts.PropertyAccessExpression): boolean { - const nameSymbol = this.tsUtils.trueSymbolAtLocation(tsExpr.name); - if (!nameSymbol) { - const leftHandSymbol = this.tsUtils.trueSymbolAtLocation(tsExpr.expression); - if (leftHandSymbol) { - const decls = leftHandSymbol.getDeclarations(); - if (!decls || decls.length !== 1) return false; - - const leftHandDecl = decls[0]; - if (!ts.isVariableDeclaration(leftHandDecl)) return false; - - const varDecl = leftHandDecl as ts.VariableDeclaration; - if (varDecl.initializer && ts.isCallExpression(varDecl.initializer)) { - const callExpr = varDecl.initializer as ts.CallExpression; - const expr = this.tsUtils.unwrapParenthesized(callExpr.expression); - if (ts.isFunctionExpression(expr)) return true; - } - } - } - - return false; - } - private isPrototypePropertyAccess( tsPropertyAccess: ts.PropertyAccessExpression ): boolean { @@ -766,11 +743,7 @@ export class TypeScriptLinter { if (this.isPropertyRuntimeCheck(propertyAccessNode)) { this.incrementCounters(node, FaultID.PropertyRuntimeCheck); } - - if (this.isIIFEasNamespace(propertyAccessNode)) { - this.incrementCounters(node, FaultID.IifeAsNamespace); - } - + if (this.isPrototypePropertyAccess(propertyAccessNode)) { this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); } diff --git a/linter-4.2/src/TypeScriptLinterConfig.ts b/linter-4.2/src/TypeScriptLinterConfig.ts index 0f4ec7aee..53397f8b3 100644 --- a/linter-4.2/src/TypeScriptLinterConfig.ts +++ b/linter-4.2/src/TypeScriptLinterConfig.ts @@ -108,7 +108,6 @@ export class LinterConfig { LinterConfig.nodeDesc[FaultID.UMDModuleDefinition] = 'UMD module definition'; LinterConfig.nodeDesc[FaultID.NewTarget] = '"new.target" meta-property'; LinterConfig.nodeDesc[FaultID.DefiniteAssignment] = 'Definite assignment assertion'; - LinterConfig.nodeDesc[FaultID.IifeAsNamespace] = 'IIFEs as namespace declarations'; LinterConfig.nodeDesc[FaultID.Prototype] = 'Prototype assignment'; LinterConfig.nodeDesc[FaultID.GlobalThis] = 'Use of globalThis'; LinterConfig.nodeDesc[FaultID.UtilityType] = 'Standard Utility types'; diff --git a/linter-4.2/test/iife_as_namespace.ts b/linter-4.2/test/iife.ts similarity index 47% rename from linter-4.2/test/iife_as_namespace.ts rename to linter-4.2/test/iife.ts index a930c25c6..73124e0bb 100644 --- a/linter-4.2/test/iife_as_namespace.ts +++ b/linter-4.2/test/iife.ts @@ -13,37 +13,9 @@ * limitations under the License. */ -const F = (function () { - function B(n) { - this.p = n; - } - - return B; -})(); - -F.staticProperty = 1; // #135 - -console.log('F.staticProperty = ' + F.staticProperty); // #135 - -const C = (function () { - class Cl { - static static_value = 'static_value'; - static any_value: any = 'any_value'; - string_field = 'string_field'; - } - - return Cl; -})(); - -C.prop = 2; // #135 -console.log('C.prop = ' + C.prop); // #135 -console.log('C.static_value = ' + C.static_value); -console.log('C.any_value = ' + C.any_value); -console.log('C.string_field = ' + C.string_field); // Not #135 - -const O = (function () { - return {}; +(() => { + let a = 5; + let b = 10; + let c = a + b; })(); -O.objProp = 3; // #135 -console.log('O.objProp = ' + O.objProp); // #135 diff --git a/linter-4.2/test/iife_as_namespace.ts.autofix.skip b/linter-4.2/test/iife.ts.autofix.skip similarity index 100% rename from linter-4.2/test/iife_as_namespace.ts.autofix.skip rename to linter-4.2/test/iife.ts.autofix.skip diff --git a/linter/test/iife_as_namespace.ts.relax.json b/linter-4.2/test/iife.ts.relax.json similarity index 34% rename from linter/test/iife_as_namespace.ts.relax.json rename to linter-4.2/test/iife.ts.relax.json index 4ff5827b0..b06227021 100644 --- a/linter/test/iife_as_namespace.ts.relax.json +++ b/linter-4.2/test/iife.ts.relax.json @@ -13,66 +13,5 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "nodes": [ - { - "line": 17, - "column": 3, - "problem": "FunctionContainsThis" - }, - { - "line": 17, - "column": 14, - "problem": "AnyType" - }, - { - "line": 24, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 26, - "column": 37, - "problem": "IifeAsNamespace" - }, - { - "line": 31, - "column": 23, - "problem": "AnyType" - }, - { - "line": 35, - "column": 10, - "problem": "ClassAsObject" - }, - { - "line": 38, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 39, - "column": 27, - "problem": "IifeAsNamespace" - }, - { - "line": 42, - "column": 35, - "problem": "IifeAsNamespace" - }, - { - "line": 45, - "column": 10, - "problem": "ObjectLiteralNoContextType" - }, - { - "line": 48, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 49, - "column": 30, - "problem": "IifeAsNamespace" - } - ] + "nodes": [] } \ No newline at end of file diff --git a/linter-4.2/test/iife_as_namespace.ts.relax.json b/linter-4.2/test/iife.ts.strict.json similarity index 34% rename from linter-4.2/test/iife_as_namespace.ts.relax.json rename to linter-4.2/test/iife.ts.strict.json index 0728d70a3..b06227021 100644 --- a/linter-4.2/test/iife_as_namespace.ts.relax.json +++ b/linter-4.2/test/iife.ts.strict.json @@ -13,66 +13,5 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "nodes": [ - { - "line": 17, - "column": 3, - "problem": "FunctionContainsThis" - }, - { - "line": 17, - "column": 14, - "problem": "AnyType" - }, - { - "line": 24, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 26, - "column": 37, - "problem": "IifeAsNamespace" - }, - { - "line": 31, - "column": 23, - "problem": "AnyType" - }, - { - "line": 35, - "column": 10, - "problem": "ClassAsObject" - }, - { - "line": 38, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 39, - "column": 27, - "problem": "IifeAsNamespace" - }, - { - "line": 42, - "column": 35, - "problem": "IifeAsNamespace" - }, - { - "line": 45, - "column": 10, - "problem": "ObjectLiteralNoContextType" - }, - { - "line": 48, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 49, - "column": 30, - "problem": "IifeAsNamespace" - } - ] -} + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test/iife_as_namespace.ts.strict.json b/linter-4.2/test/iife_as_namespace.ts.strict.json deleted file mode 100644 index a21943b09..000000000 --- a/linter-4.2/test/iife_as_namespace.ts.strict.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "copyright": [ - "Copyright (c) 2022-2023 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], - "nodes": [ - { - "line": 16, - "column": 12, - "problem": "FunctionExpression" - }, - { - "line": 17, - "column": 3, - "problem": "FunctionContainsThis" - }, - { - "line": 17, - "column": 3, - "problem": "LocalFunction" - }, - { - "line": 17, - "column": 14, - "problem": "AnyType" - }, - { - "line": 24, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 26, - "column": 37, - "problem": "IifeAsNamespace" - }, - { - "line": 28, - "column": 12, - "problem": "FunctionExpression" - }, - { - "line": 31, - "column": 23, - "problem": "AnyType" - }, - { - "line": 35, - "column": 10, - "problem": "ClassAsObject" - }, - { - "line": 38, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 39, - "column": 27, - "problem": "IifeAsNamespace" - }, - { - "line": 42, - "column": 35, - "problem": "IifeAsNamespace" - }, - { - "line": 44, - "column": 12, - "problem": "FunctionExpression" - }, - { - "line": 45, - "column": 10, - "problem": "ObjectLiteralNoContextType" - }, - { - "line": 48, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 49, - "column": 30, - "problem": "IifeAsNamespace" - } - ] -} diff --git a/linter-4.2/test_rules/rule135.ts b/linter-4.2/test_rules/rule135.ts deleted file mode 100644 index 1912fcad2..000000000 --- a/linter-4.2/test_rules/rule135.ts +++ /dev/null @@ -1,8 +0,0 @@ -var C = (function() { - function C(n: number) { - this.p = n // Compile-time error only with noImplicitThis - } - C.staticProperty = 0 - return C -})() -C.staticProperty = 1 \ No newline at end of file diff --git a/linter-4.2/test_rules/rule135.ts.autofix.json b/linter-4.2/test_rules/rule135.ts.autofix.json deleted file mode 100644 index f6875492b..000000000 --- a/linter-4.2/test_rules/rule135.ts.autofix.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "nodes": [ - { - "line": 1, - "column": 1, - "problem": "VarDeclaration", - "autofixable": false, - "suggest": "", - "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" - }, - { - "line": 1, - "column": 10, - "problem": "FunctionExpression", - "autofixable": true, - "autofix": [ - { - "start": 9, - "end": 161, - "replacementText": "() => {\n function C(n: number) {\n this.p = n; // Compile-time error only with noImplicitThis\n }\n C.staticProperty = 0;\n return C;\n}" - } - ], - "suggest": "", - "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" - }, - { - "line": 2, - "column": 5, - "problem": "FunctionContainsThis", - "autofixable": false, - "suggest": "", - "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" - }, - { - "line": 2, - "column": 5, - "problem": "LocalFunction", - "autofixable": false, - "suggest": "", - "rule": "Nested functions are not supported (arkts-no-nested-funcs)" - } - ] -} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule135.ts.relax.json b/linter-4.2/test_rules/rule135.ts.relax.json deleted file mode 100644 index 772a1f628..000000000 --- a/linter-4.2/test_rules/rule135.ts.relax.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "nodes": [ - { - "line": 2, - "column": 5, - "problem": "FunctionContainsThis", - "suggest": "", - "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" - } - ] -} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule135.ts.strict.json b/linter-4.2/test_rules/rule135.ts.strict.json deleted file mode 100644 index 715908747..000000000 --- a/linter-4.2/test_rules/rule135.ts.strict.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "nodes": [ - { - "line": 1, - "column": 1, - "problem": "VarDeclaration", - "suggest": "", - "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" - }, - { - "line": 1, - "column": 10, - "problem": "FunctionExpression", - "suggest": "", - "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" - }, - { - "line": 2, - "column": 5, - "problem": "FunctionContainsThis", - "suggest": "", - "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" - }, - { - "line": 2, - "column": 5, - "problem": "LocalFunction", - "suggest": "", - "rule": "Nested functions are not supported (arkts-no-nested-funcs)" - } - ] -} \ No newline at end of file diff --git a/linter/docs/rules/recipe135.md b/linter/docs/rules/recipe135.md deleted file mode 100644 index df981900a..000000000 --- a/linter/docs/rules/recipe135.md +++ /dev/null @@ -1,39 +0,0 @@ -# IIFEs as namespace declarations are not supported - -Rule ``arkts-no-iife`` - -**Severity: error** - -ArkTS does not support IIFEs as namespace declarations because anonymous -functions in the language cannot serve as namespaces. -Use regular syntax for namespaces instead. - - -## TypeScript - - -``` - - var C = (function() { - function C(n: number) { - this.p = n // Compile-time error only with noImplicitThis - } - C.staticProperty = 0 - return C - })() - C.staticProperty = 1 - -``` - -## ArkTS - - -``` - - namespace C { - // ... - } - -``` - - diff --git a/linter/src/CookBookMsg.ts b/linter/src/CookBookMsg.ts index 684402979..a8e57eb0b 100644 --- a/linter/src/CookBookMsg.ts +++ b/linter/src/CookBookMsg.ts @@ -154,7 +154,7 @@ cookBookTag[131] = ''; cookBookTag[132] = '"new.target" is not supported (arkts-no-new-target)'; cookBookTag[133] = ''; cookBookTag[134] = 'Definite assignment assertions are not supported (arkts-no-definite-assignment)'; -cookBookTag[135] = 'IIFEs as namespace declarations are not supported (arkts-no-iife)'; +cookBookTag[135] = ''; cookBookTag[136] = 'Prototype assignment is not supported (arkts-no-prototype-assignment)'; cookBookTag[137] = '"globalThis" is not supported (arkts-no-globalthis)'; cookBookTag[138] = 'Some of utility types are not supported (arkts-no-utility-types)'; diff --git a/linter/src/FaultAttrs.ts b/linter/src/FaultAttrs.ts index 76426a076..d46a8e4d1 100644 --- a/linter/src/FaultAttrs.ts +++ b/linter/src/FaultAttrs.ts @@ -98,7 +98,6 @@ faultsAttrs[FaultID.WildcardsInModuleName] = {cookBookRef: '129',}; faultsAttrs[FaultID.UMDModuleDefinition] = {cookBookRef: '130',}; faultsAttrs[FaultID.NewTarget] = {cookBookRef: '132',}; faultsAttrs[FaultID.DefiniteAssignment] = {cookBookRef: '134',}; -faultsAttrs[FaultID.IifeAsNamespace] = {cookBookRef: '135',}; faultsAttrs[FaultID.Prototype] = {cookBookRef: '136',}; faultsAttrs[FaultID.GlobalThis] = {cookBookRef: '137',}; faultsAttrs[FaultID.UtilityType] = {cookBookRef: '138',}; diff --git a/linter/src/FaultDesc.ts b/linter/src/FaultDesc.ts index 3c6c1d03d..51a6f8d36 100644 --- a/linter/src/FaultDesc.ts +++ b/linter/src/FaultDesc.ts @@ -92,7 +92,6 @@ faultDesc[FaultID.WildcardsInModuleName] = 'Wildcards in module name'; faultDesc[FaultID.UMDModuleDefinition] = 'UMD module definition'; faultDesc[FaultID.NewTarget] = '"new.target" meta-property'; faultDesc[FaultID.DefiniteAssignment] = 'Definite assignment assertion'; -faultDesc[FaultID.IifeAsNamespace] = 'IIFEs as namespace declarations'; faultDesc[FaultID.Prototype] = 'Prototype assignment'; faultDesc[FaultID.GlobalThis] = 'Use of globalThis'; faultDesc[FaultID.UtilityType] = 'Standard Utility types'; diff --git a/linter/src/Problems.ts b/linter/src/Problems.ts index afd78b501..c53260e05 100644 --- a/linter/src/Problems.ts +++ b/linter/src/Problems.ts @@ -31,7 +31,7 @@ export enum FaultID { ExportAssignment, ImportAssignment, PropertyRuntimeCheck, GenericCallNoTypeArgs, ParameterProperties, InstanceofUnsupported, ShorthandAmbientModuleDecl, WildcardsInModuleName, UMDModuleDefinition, - NewTarget, DefiniteAssignment, IifeAsNamespace, Prototype, GlobalThis, + NewTarget, DefiniteAssignment, Prototype, GlobalThis, UtilityType, PropertyDeclOnFunction, FunctionApplyBindCall, ConstAssertion, ImportAssertion, SpreadOperator, LimitedStdLibApi, ErrorSuppression, StrictDiagnostic, UnsupportedDecorators, ImportAfterStatement, EsObjectType, EsObjectAssignment, EsObjectAccess, diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index 4bb4a2328..a7892724f 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -341,32 +341,6 @@ export class TypeScriptLinter { ); } - private isIIFEasNamespace(tsExpr: ts.PropertyAccessExpression): boolean { - const nameSymbol = this.tsUtils.trueSymbolAtLocation(tsExpr.name); - if (!nameSymbol) { - const leftHandSymbol = this.tsUtils.trueSymbolAtLocation(tsExpr.expression); - if (leftHandSymbol) { - const decls = leftHandSymbol.getDeclarations(); - if (!decls || decls.length !== 1) { - return false; - } - const leftHandDecl = decls[0]; - if (!ts.isVariableDeclaration(leftHandDecl)) { - return false; - } - const varDecl = leftHandDecl as ts.VariableDeclaration; - if (varDecl.initializer && ts.isCallExpression(varDecl.initializer)) { - const callExpr = varDecl.initializer as ts.CallExpression; - const expr = this.tsUtils.unwrapParenthesized(callExpr.expression); - if (ts.isFunctionExpression(expr)) { - return true; - } - } - } - } - return false; - } - private isPrototypePropertyAccess(tsPropertyAccess: ts.PropertyAccessExpression): boolean { if (!(ts.isIdentifier(tsPropertyAccess.name) && tsPropertyAccess.name.text === 'prototype')) { return false; @@ -650,9 +624,6 @@ export class TypeScriptLinter { if (this.isPropertyRuntimeCheck(propertyAccessNode)) { this.incrementCounters(node, FaultID.PropertyRuntimeCheck); } - if (this.isIIFEasNamespace(propertyAccessNode)) { - this.incrementCounters(node, FaultID.IifeAsNamespace); - } if (this.isPrototypePropertyAccess(propertyAccessNode)) { this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); } diff --git a/linter/test/iife_as_namespace.ts b/linter/test/iife.ts similarity index 47% rename from linter/test/iife_as_namespace.ts rename to linter/test/iife.ts index 041ba38ce..73124e0bb 100644 --- a/linter/test/iife_as_namespace.ts +++ b/linter/test/iife.ts @@ -13,37 +13,9 @@ * limitations under the License. */ -const F = (function () { - function B(n) { - this.p = n; - } - - return B; -})(); - -F.staticProperty = 1; // #135 - -console.log("F.staticProperty = " + F.staticProperty); // #135 - -const C = (function () { - class Cl { - static static_value = "static_value"; - static any_value: any = "any_value"; - string_field = "string_field"; - } - - return Cl; -})(); - -C.prop = 2; // #135 -console.log("C.prop = " + C.prop); // #135 -console.log("C.static_value = " + C.static_value); -console.log("C.any_value = " + C.any_value); -console.log("C.string_field = " + C.string_field); // Not #135 - -const O = (function () { - return {}; +(() => { + let a = 5; + let b = 10; + let c = a + b; })(); -O.objProp = 3; // #135 -console.log("O.objProp = " + O.objProp); // #135 diff --git a/linter/test/iife_as_namespace.ts.autofix.skip b/linter/test/iife.ts.autofix.skip similarity index 100% rename from linter/test/iife_as_namespace.ts.autofix.skip rename to linter/test/iife.ts.autofix.skip diff --git a/linter/test/iife.ts.relax.json b/linter/test/iife.ts.relax.json new file mode 100644 index 000000000..b06227021 --- /dev/null +++ b/linter/test/iife.ts.relax.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2022-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [] +} \ No newline at end of file diff --git a/linter/test/iife.ts.strict.json b/linter/test/iife.ts.strict.json new file mode 100644 index 000000000..b06227021 --- /dev/null +++ b/linter/test/iife.ts.strict.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2022-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [] +} \ No newline at end of file diff --git a/linter/test/iife_as_namespace.ts.strict.json b/linter/test/iife_as_namespace.ts.strict.json deleted file mode 100644 index 0041d2709..000000000 --- a/linter/test/iife_as_namespace.ts.strict.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "copyright": [ - "Copyright (c) 2022-2023 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], - "nodes": [ - { - "line": 16, - "column": 12, - "problem": "FunctionExpression" - }, - { - "line": 17, - "column": 3, - "problem": "FunctionContainsThis" - }, - { - "line": 17, - "column": 3, - "problem": "LocalFunction" - }, - { - "line": 17, - "column": 14, - "problem": "AnyType" - }, - { - "line": 24, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 26, - "column": 37, - "problem": "IifeAsNamespace" - }, - { - "line": 28, - "column": 12, - "problem": "FunctionExpression" - }, - { - "line": 31, - "column": 23, - "problem": "AnyType" - }, - { - "line": 35, - "column": 10, - "problem": "ClassAsObject" - }, - { - "line": 38, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 39, - "column": 27, - "problem": "IifeAsNamespace" - }, - { - "line": 42, - "column": 35, - "problem": "IifeAsNamespace" - }, - { - "line": 44, - "column": 12, - "problem": "FunctionExpression" - }, - { - "line": 45, - "column": 10, - "problem": "ObjectLiteralNoContextType" - }, - { - "line": 48, - "column": 1, - "problem": "IifeAsNamespace" - }, - { - "line": 49, - "column": 30, - "problem": "IifeAsNamespace" - } - ] -} \ No newline at end of file diff --git a/linter/test_rules/rule135.ts b/linter/test_rules/rule135.ts deleted file mode 100644 index 1912fcad2..000000000 --- a/linter/test_rules/rule135.ts +++ /dev/null @@ -1,8 +0,0 @@ -var C = (function() { - function C(n: number) { - this.p = n // Compile-time error only with noImplicitThis - } - C.staticProperty = 0 - return C -})() -C.staticProperty = 1 \ No newline at end of file diff --git a/linter/test_rules/rule135.ts.autofix.json b/linter/test_rules/rule135.ts.autofix.json deleted file mode 100644 index f6875492b..000000000 --- a/linter/test_rules/rule135.ts.autofix.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "nodes": [ - { - "line": 1, - "column": 1, - "problem": "VarDeclaration", - "autofixable": false, - "suggest": "", - "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" - }, - { - "line": 1, - "column": 10, - "problem": "FunctionExpression", - "autofixable": true, - "autofix": [ - { - "start": 9, - "end": 161, - "replacementText": "() => {\n function C(n: number) {\n this.p = n; // Compile-time error only with noImplicitThis\n }\n C.staticProperty = 0;\n return C;\n}" - } - ], - "suggest": "", - "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" - }, - { - "line": 2, - "column": 5, - "problem": "FunctionContainsThis", - "autofixable": false, - "suggest": "", - "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" - }, - { - "line": 2, - "column": 5, - "problem": "LocalFunction", - "autofixable": false, - "suggest": "", - "rule": "Nested functions are not supported (arkts-no-nested-funcs)" - } - ] -} \ No newline at end of file diff --git a/linter/test_rules/rule135.ts.relax.json b/linter/test_rules/rule135.ts.relax.json deleted file mode 100644 index 772a1f628..000000000 --- a/linter/test_rules/rule135.ts.relax.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "nodes": [ - { - "line": 2, - "column": 5, - "problem": "FunctionContainsThis", - "suggest": "", - "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" - } - ] -} \ No newline at end of file diff --git a/linter/test_rules/rule135.ts.strict.json b/linter/test_rules/rule135.ts.strict.json deleted file mode 100644 index 715908747..000000000 --- a/linter/test_rules/rule135.ts.strict.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "nodes": [ - { - "line": 1, - "column": 1, - "problem": "VarDeclaration", - "suggest": "", - "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" - }, - { - "line": 1, - "column": 10, - "problem": "FunctionExpression", - "suggest": "", - "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" - }, - { - "line": 2, - "column": 5, - "problem": "FunctionContainsThis", - "suggest": "", - "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" - }, - { - "line": 2, - "column": 5, - "problem": "LocalFunction", - "suggest": "", - "rule": "Nested functions are not supported (arkts-no-nested-funcs)" - } - ] -} \ No newline at end of file -- Gitee