diff --git a/linter-4.2/docs/rules/recipe135.md b/linter-4.2/docs/rules/recipe135.md deleted file mode 100644 index df981900ae4987a0ded2fb70884e61c5b54f4a7b..0000000000000000000000000000000000000000 --- 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 68440297976e0446aebc4e3d548a6d0f0a896b9c..a8e57eb0b3ca1b2bfc8a73fa6d7c6ebd724f2311 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 dea592e845a58dd9c7f128619a330e0ef5f2f236..a912a3134d3da06026f3cab5dc5c82fa142e2c88 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 9203844e85e37e9d78cf78e94ebd9831dbea040a..f8ea75df68ea6bc19ba2662327bbc96b1b0f0bff 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 0f4ec7aeebc7491beddfdfa5c22bfd963a3b7e77..53397f8b3d91832b3788b91fa49120da3e6709ab 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 a930c25c6a619a44b09439edd2a3ba99fed204ac..73124e0bbc7c0856c0b4151695b94e302fae1d50 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 4ff5827b0d783913b4358ab1a98057fdfcac48e6..b06227021f092f20110cdafb2a6d660605c2ff96 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 0728d70a322500a22e46c3673ad8a8c12bab07c4..b06227021f092f20110cdafb2a6d660605c2ff96 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 a21943b09621695b0ff2bcea651f741431d23346..0000000000000000000000000000000000000000 --- 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 1912fcad2b334cd6e68b6dda529cef5a04c46462..0000000000000000000000000000000000000000 --- 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 f6875492b5e55dfa2250c42c73eea095d82f6097..0000000000000000000000000000000000000000 --- 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 772a1f628e47461607ed2422e22212586394fbc1..0000000000000000000000000000000000000000 --- 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 7159087471035566f8d733bcf352d7e6ddc34b98..0000000000000000000000000000000000000000 --- 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 df981900ae4987a0ded2fb70884e61c5b54f4a7b..0000000000000000000000000000000000000000 --- 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 68440297976e0446aebc4e3d548a6d0f0a896b9c..a8e57eb0b3ca1b2bfc8a73fa6d7c6ebd724f2311 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 76426a0767ea1154f7d6aac2f81a2fddad36600f..d46a8e4d1f5fa1b96e2e90ff039bcf59deb60b73 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 3c6c1d03d43d48cfecefb885a96e0e60ab853743..51a6f8d363026aa07f01959a6bd90aa52631b399 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 afd78b501968f653f5fb1a3728292cf7a5596faa..c53260e05a58ed179ca88505076d307533a4b37b 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 4bb4a2328b13891e862a54c12afd0f9c0eefea69..a7892724ff38e11bd5c83c72ef0179de7063de0a 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 041ba38cea7d0b2f87da5b37a444f5173d7e591a..73124e0bbc7c0856c0b4151695b94e302fae1d50 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 0000000000000000000000000000000000000000..b06227021f092f20110cdafb2a6d660605c2ff96 --- /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 0000000000000000000000000000000000000000..b06227021f092f20110cdafb2a6d660605c2ff96 --- /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 0041d2709ccba0e417c62bc8277f12bb33f573dc..0000000000000000000000000000000000000000 --- 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 1912fcad2b334cd6e68b6dda529cef5a04c46462..0000000000000000000000000000000000000000 --- 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 f6875492b5e55dfa2250c42c73eea095d82f6097..0000000000000000000000000000000000000000 --- 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 772a1f628e47461607ed2422e22212586394fbc1..0000000000000000000000000000000000000000 --- 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 7159087471035566f8d733bcf352d7e6ddc34b98..0000000000000000000000000000000000000000 --- 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