From efb8df6af246db76753e6ab8b82f7acd77008784 Mon Sep 17 00:00:00 2001 From: Ilya Trubachev Date: Tue, 19 Sep 2023 13:05:29 +0300 Subject: [PATCH] relax recipe 141 Signed-off-by: Ilya Trubachev --- linter-4.2/docs/rules/recipe141.md | 34 ------------------- linter-4.2/src/Autofixer.ts | 8 ----- linter-4.2/src/CookBookMsg.ts | 2 +- linter-4.2/src/Problems.ts | 3 +- linter-4.2/src/TypeScriptLinter.ts | 4 --- linter-4.2/src/TypeScriptLinterConfig.ts | 1 - linter-4.2/test/readonly_arr.ts.autofix.json | 13 ------- linter-4.2/test/readonly_arr.ts.strict.json | 5 --- linter-4.2/test_rules/rule141.ts | 4 --- linter-4.2/test_rules/rule141.ts.autofix.json | 19 ----------- linter-4.2/test_rules/rule141.ts.relax.json | 3 -- linter-4.2/test_rules/rule141.ts.strict.json | 11 ------ linter/docs/rules/recipe141.md | 34 ------------------- linter/src/AutofixTitles.ts | 1 - linter/src/Autofixer.ts | 8 ----- linter/src/CookBookMsg.ts | 2 +- linter/src/FaultAttrs.ts | 1 - linter/src/FaultDesc.ts | 1 - linter/src/Problems.ts | 2 +- linter/src/TypeScriptLinter.ts | 2 -- linter/test/readonly_arr.ts.autofix.json | 13 ------- linter/test/readonly_arr.ts.strict.json | 5 --- linter/test_rules/rule141.ts | 4 --- linter/test_rules/rule141.ts.autofix.json | 19 ----------- linter/test_rules/rule141.ts.relax.json | 3 -- linter/test_rules/rule141.ts.strict.json | 11 ------ 26 files changed, 4 insertions(+), 209 deletions(-) delete mode 100644 linter-4.2/docs/rules/recipe141.md delete mode 100644 linter-4.2/test_rules/rule141.ts delete mode 100644 linter-4.2/test_rules/rule141.ts.autofix.json delete mode 100644 linter-4.2/test_rules/rule141.ts.relax.json delete mode 100644 linter-4.2/test_rules/rule141.ts.strict.json delete mode 100644 linter/docs/rules/recipe141.md delete mode 100644 linter/test_rules/rule141.ts delete mode 100644 linter/test_rules/rule141.ts.autofix.json delete mode 100644 linter/test_rules/rule141.ts.relax.json delete mode 100644 linter/test_rules/rule141.ts.strict.json diff --git a/linter-4.2/docs/rules/recipe141.md b/linter-4.2/docs/rules/recipe141.md deleted file mode 100644 index a772b5388..000000000 --- a/linter-4.2/docs/rules/recipe141.md +++ /dev/null @@ -1,34 +0,0 @@ -# ``readonly T[]`` syntax is not supported - -Rule ``arkts-no-readonly-params`` - -**Severity: error** - -Currently, ArkTS supports ``readonly`` for properties, but not for parameters. - - -## TypeScript - - -``` - - function foo(arr: readonly string[]) { - arr.slice() // OK - arr.push("hello!") // Compile-time error - } - -``` - -## ArkTS - - -``` - - function foo(arr: string[]) { - arr.slice() // OK - arr.push("hello!") // OK - } - -``` - - diff --git a/linter-4.2/src/Autofixer.ts b/linter-4.2/src/Autofixer.ts index 697a71f54..0ff724931 100644 --- a/linter-4.2/src/Autofixer.ts +++ b/linter-4.2/src/Autofixer.ts @@ -134,14 +134,6 @@ export function fixTypeAssertion(typeAssertion: ts.TypeAssertion): Autofix { return { start: typeAssertion.getStart(), end: typeAssertion.getEnd(), replacementText: text }; } -export function fixReadonlyArr(node: ts.Node): Autofix { - return { - start: node.getStart(), - end: node.getEnd(), - replacementText: node.getText().substring('readonly '.length), - }; -} - const printer: ts.Printer = ts.createPrinter(); function numericLiteral2IdentifierName(numeric: ts.NumericLiteral) { diff --git a/linter-4.2/src/CookBookMsg.ts b/linter-4.2/src/CookBookMsg.ts index 87c5dc8ff..ae282eee2 100644 --- a/linter-4.2/src/CookBookMsg.ts +++ b/linter-4.2/src/CookBookMsg.ts @@ -160,7 +160,7 @@ cookBookTag[137] = '"globalThis" is not supported (arkts-no-globalthis)'; cookBookTag[138] = 'Some of utility types are not supported (arkts-no-utility-types)'; cookBookTag[139] = 'Declaring properties on functions is not supported (arkts-no-func-props)'; cookBookTag[140] = '"Function.apply", "Function.bind", "Function.call" are not supported (arkts-no-func-apply-bind-call)'; -cookBookTag[141] = '"readonly T[]" syntax is not supported (arkts-no-readonly-params)'; +cookBookTag[141] = ''; cookBookTag[142] = '"as const" assertions are not supported (arkts-no-as-const)'; cookBookTag[143] = 'Import assertions are not supported (arkts-no-import-assertions)'; cookBookTag[144] = 'Usage of standard library is restricted (arkts-limited-stdlib)'; diff --git a/linter-4.2/src/Problems.ts b/linter-4.2/src/Problems.ts index 373f77688..eaa149828 100644 --- a/linter-4.2/src/Problems.ts +++ b/linter-4.2/src/Problems.ts @@ -32,7 +32,7 @@ export enum FaultID { GenericCallNoTypeArgs, ParameterProperties, InstanceofUnsupported, ShorthandAmbientModuleDecl, WildcardsInModuleName, UMDModuleDefinition, NewTarget, DefiniteAssignment, IifeAsNamespace, Prototype, GlobalThis, - UtilityType, PropertyDeclOnFunction, FunctionApplyBindCall, ReadonlyArr, ConstAssertion, ImportAssertion, + UtilityType, PropertyDeclOnFunction, FunctionApplyBindCall, ConstAssertion, ImportAssertion, SpreadOperator, LimitedStdLibApi, ErrorSuppression, StrictDiagnostic, UnsupportedDecorators, ImportAfterStatement, EsObjectType, EsObjectAssignment, EsObjectAccess, LAST_ID, // this should always be last enum` @@ -129,7 +129,6 @@ faultsAttrs[FaultID.GlobalThis] = {cookBookRef: '137',}; faultsAttrs[FaultID.UtilityType] = {cookBookRef: '138',}; faultsAttrs[FaultID.PropertyDeclOnFunction] = {cookBookRef: '139',}; faultsAttrs[FaultID.FunctionApplyBindCall] = {cookBookRef: '140',}; -faultsAttrs[FaultID.ReadonlyArr] = {migratable: true, cookBookRef: '141',}; faultsAttrs[FaultID.ConstAssertion] = {cookBookRef: '142',}; faultsAttrs[FaultID.ImportAssertion] = {cookBookRef: '143',}; faultsAttrs[FaultID.LimitedStdLibApi] = {cookBookRef: '144',}; diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index c2a79bc87..ad75b54d9 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -738,10 +738,6 @@ export class TypeScriptLinter { const fullText = node.getFullText().trim(); if (fullText.startsWith("keyof")) this.incrementCounters(node, FaultID.KeyOfOperator); - else if (fullText.startsWith("readonly")) - this.incrementCounters(node, FaultID.ReadonlyArr, true, [ - Autofixer.fixReadonlyArr(node), - ]); } private handleImportDeclaration(node: ts.Node) { diff --git a/linter-4.2/src/TypeScriptLinterConfig.ts b/linter-4.2/src/TypeScriptLinterConfig.ts index 1834923b6..02fe63f5a 100644 --- a/linter-4.2/src/TypeScriptLinterConfig.ts +++ b/linter-4.2/src/TypeScriptLinterConfig.ts @@ -116,7 +116,6 @@ export class LinterConfig { LinterConfig.nodeDesc[FaultID.UtilityType] = 'Standard Utility types'; LinterConfig.nodeDesc[FaultID.PropertyDeclOnFunction] = 'Property declaration on function'; LinterConfig.nodeDesc[FaultID.FunctionApplyBindCall] = 'Invoking methods of function objects'; - LinterConfig.nodeDesc[FaultID.ReadonlyArr] = '"readonly" array or tuple'; LinterConfig.nodeDesc[FaultID.ConstAssertion] = '"as const" assertion'; LinterConfig.nodeDesc[FaultID.ImportAssertion] = 'Import assertion'; LinterConfig.nodeDesc[FaultID.SpreadOperator] = 'Spread operation'; diff --git a/linter-4.2/test/readonly_arr.ts.autofix.json b/linter-4.2/test/readonly_arr.ts.autofix.json index bd3479561..982cc7b69 100644 --- a/linter-4.2/test/readonly_arr.ts.autofix.json +++ b/linter-4.2/test/readonly_arr.ts.autofix.json @@ -14,19 +14,6 @@ "limitations under the License." ], "nodes": [ - { - "line": 21, - "column": 19, - "problem": "ReadonlyArr", - "autofixable": true, - "autofix": [ - { - "start": 712, - "end": 729, - "replacementText": "string[]" - } - ] - }, { "line": 17, "column": 12, diff --git a/linter-4.2/test/readonly_arr.ts.strict.json b/linter-4.2/test/readonly_arr.ts.strict.json index 5f11751c5..ac1284435 100644 --- a/linter-4.2/test/readonly_arr.ts.strict.json +++ b/linter-4.2/test/readonly_arr.ts.strict.json @@ -14,11 +14,6 @@ "limitations under the License." ], "nodes": [ - { - "line": 21, - "column": 19, - "problem": "ReadonlyArr" - }, { "line": 17, "column": 12, diff --git a/linter-4.2/test_rules/rule141.ts b/linter-4.2/test_rules/rule141.ts deleted file mode 100644 index a0ebc2f84..000000000 --- a/linter-4.2/test_rules/rule141.ts +++ /dev/null @@ -1,4 +0,0 @@ -function foo(arr: readonly string[]) { - arr.slice() // OK - arr.push("hello!") // Compile-time error -} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule141.ts.autofix.json b/linter-4.2/test_rules/rule141.ts.autofix.json deleted file mode 100644 index 4843ef02e..000000000 --- a/linter-4.2/test_rules/rule141.ts.autofix.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "nodes": [ - { - "line": 1, - "column": 19, - "problem": "ReadonlyArr", - "autofixable": true, - "autofix": [ - { - "start": 18, - "end": 35, - "replacementText": "string[]" - } - ], - "suggest": "", - "rule": "\"readonly T[]\" syntax is not supported (arkts-no-readonly-params)" - } - ] -} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule141.ts.relax.json b/linter-4.2/test_rules/rule141.ts.relax.json deleted file mode 100644 index 13f13363f..000000000 --- a/linter-4.2/test_rules/rule141.ts.relax.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "nodes": [] -} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule141.ts.strict.json b/linter-4.2/test_rules/rule141.ts.strict.json deleted file mode 100644 index 3d0ea4953..000000000 --- a/linter-4.2/test_rules/rule141.ts.strict.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "nodes": [ - { - "line": 1, - "column": 19, - "problem": "ReadonlyArr", - "suggest": "", - "rule": "\"readonly T[]\" syntax is not supported (arkts-no-readonly-params)" - } - ] -} \ No newline at end of file diff --git a/linter/docs/rules/recipe141.md b/linter/docs/rules/recipe141.md deleted file mode 100644 index a772b5388..000000000 --- a/linter/docs/rules/recipe141.md +++ /dev/null @@ -1,34 +0,0 @@ -# ``readonly T[]`` syntax is not supported - -Rule ``arkts-no-readonly-params`` - -**Severity: error** - -Currently, ArkTS supports ``readonly`` for properties, but not for parameters. - - -## TypeScript - - -``` - - function foo(arr: readonly string[]) { - arr.slice() // OK - arr.push("hello!") // Compile-time error - } - -``` - -## ArkTS - - -``` - - function foo(arr: string[]) { - arr.slice() // OK - arr.push("hello!") // OK - } - -``` - - diff --git a/linter/src/AutofixTitles.ts b/linter/src/AutofixTitles.ts index 4059f5b4b..89bad0381 100644 --- a/linter/src/AutofixTitles.ts +++ b/linter/src/AutofixTitles.ts @@ -25,5 +25,4 @@ export const cookBookRefToFixTitle: Map = new Map([ [118, 'Replace with ordinary import'], [120, 'Replace with explicit import'], [127, 'Replace with ordinary export'], - [141, 'Remove \'readonly\' keyword'], ]); diff --git a/linter/src/Autofixer.ts b/linter/src/Autofixer.ts index 8d44c607a..e10d1ce44 100644 --- a/linter/src/Autofixer.ts +++ b/linter/src/Autofixer.ts @@ -142,14 +142,6 @@ export function fixTypeAssertion(typeAssertion: ts.TypeAssertion): Autofix { return { start: typeAssertion.getStart(), end: typeAssertion.getEnd(), replacementText: text }; } -export function fixReadonlyArr(node: ts.Node): Autofix { - return { - start: node.getStart(), - end: node.getEnd(), - replacementText: node.getText().substring('readonly '.length), - }; -} - const printer: ts.Printer = ts.createPrinter(); function numericLiteral2IdentifierName(numeric: ts.NumericLiteral) { diff --git a/linter/src/CookBookMsg.ts b/linter/src/CookBookMsg.ts index 87c5dc8ff..ae282eee2 100644 --- a/linter/src/CookBookMsg.ts +++ b/linter/src/CookBookMsg.ts @@ -160,7 +160,7 @@ cookBookTag[137] = '"globalThis" is not supported (arkts-no-globalthis)'; cookBookTag[138] = 'Some of utility types are not supported (arkts-no-utility-types)'; cookBookTag[139] = 'Declaring properties on functions is not supported (arkts-no-func-props)'; cookBookTag[140] = '"Function.apply", "Function.bind", "Function.call" are not supported (arkts-no-func-apply-bind-call)'; -cookBookTag[141] = '"readonly T[]" syntax is not supported (arkts-no-readonly-params)'; +cookBookTag[141] = ''; cookBookTag[142] = '"as const" assertions are not supported (arkts-no-as-const)'; cookBookTag[143] = 'Import assertions are not supported (arkts-no-import-assertions)'; cookBookTag[144] = 'Usage of standard library is restricted (arkts-limited-stdlib)'; diff --git a/linter/src/FaultAttrs.ts b/linter/src/FaultAttrs.ts index bdaf14ea5..67fabac25 100644 --- a/linter/src/FaultAttrs.ts +++ b/linter/src/FaultAttrs.ts @@ -106,7 +106,6 @@ faultsAttrs[FaultID.GlobalThis] = {cookBookRef: '137',}; faultsAttrs[FaultID.UtilityType] = {cookBookRef: '138',}; faultsAttrs[FaultID.PropertyDeclOnFunction] = {cookBookRef: '139',}; faultsAttrs[FaultID.FunctionApplyBindCall] = {cookBookRef: '140',}; -faultsAttrs[FaultID.ReadonlyArr] = {migratable: true, cookBookRef: '141',}; faultsAttrs[FaultID.ConstAssertion] = {cookBookRef: '142',}; faultsAttrs[FaultID.ImportAssertion] = {cookBookRef: '143',}; faultsAttrs[FaultID.LimitedStdLibApi] = {cookBookRef: '144',}; diff --git a/linter/src/FaultDesc.ts b/linter/src/FaultDesc.ts index ae0717c04..491414356 100644 --- a/linter/src/FaultDesc.ts +++ b/linter/src/FaultDesc.ts @@ -100,7 +100,6 @@ faultDesc[FaultID.GlobalThis] = 'Use of globalThis'; faultDesc[FaultID.UtilityType] = 'Standard Utility types'; faultDesc[FaultID.PropertyDeclOnFunction] = 'Property declaration on function'; faultDesc[FaultID.FunctionApplyBindCall] = 'Invoking methods of function objects'; -faultDesc[FaultID.ReadonlyArr] = '"readonly" array or tuple'; faultDesc[FaultID.ConstAssertion] = '"as const" assertion'; faultDesc[FaultID.ImportAssertion] = 'Import assertion'; faultDesc[FaultID.SpreadOperator] = 'Spread operation'; diff --git a/linter/src/Problems.ts b/linter/src/Problems.ts index f4ac406f2..3db60b3e7 100644 --- a/linter/src/Problems.ts +++ b/linter/src/Problems.ts @@ -32,7 +32,7 @@ export enum FaultID { GenericCallNoTypeArgs, ParameterProperties, InstanceofUnsupported, ShorthandAmbientModuleDecl, WildcardsInModuleName, UMDModuleDefinition, NewTarget, DefiniteAssignment, IifeAsNamespace, Prototype, GlobalThis, - UtilityType, PropertyDeclOnFunction, FunctionApplyBindCall, ReadonlyArr, ConstAssertion, ImportAssertion, + UtilityType, PropertyDeclOnFunction, FunctionApplyBindCall, ConstAssertion, ImportAssertion, SpreadOperator, LimitedStdLibApi, ErrorSuppression, StrictDiagnostic, UnsupportedDecorators, ImportAfterStatement, EsObjectType, EsObjectAssignment, EsObjectAccess, LAST_ID, // this should always be last enum` diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index ea461af04..6251b4a7f 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -615,8 +615,6 @@ export class TypeScriptLinter { const fullText = node.getFullText().trim(); if (fullText.startsWith('keyof')) { this.incrementCounters(node, FaultID.KeyOfOperator); - } else if (fullText.startsWith('readonly')) { - this.incrementCounters(node, FaultID.ReadonlyArr, true, [ Autofixer.fixReadonlyArr(node) ]); } } diff --git a/linter/test/readonly_arr.ts.autofix.json b/linter/test/readonly_arr.ts.autofix.json index bd3479561..982cc7b69 100644 --- a/linter/test/readonly_arr.ts.autofix.json +++ b/linter/test/readonly_arr.ts.autofix.json @@ -14,19 +14,6 @@ "limitations under the License." ], "nodes": [ - { - "line": 21, - "column": 19, - "problem": "ReadonlyArr", - "autofixable": true, - "autofix": [ - { - "start": 712, - "end": 729, - "replacementText": "string[]" - } - ] - }, { "line": 17, "column": 12, diff --git a/linter/test/readonly_arr.ts.strict.json b/linter/test/readonly_arr.ts.strict.json index 5f11751c5..ac1284435 100644 --- a/linter/test/readonly_arr.ts.strict.json +++ b/linter/test/readonly_arr.ts.strict.json @@ -14,11 +14,6 @@ "limitations under the License." ], "nodes": [ - { - "line": 21, - "column": 19, - "problem": "ReadonlyArr" - }, { "line": 17, "column": 12, diff --git a/linter/test_rules/rule141.ts b/linter/test_rules/rule141.ts deleted file mode 100644 index a0ebc2f84..000000000 --- a/linter/test_rules/rule141.ts +++ /dev/null @@ -1,4 +0,0 @@ -function foo(arr: readonly string[]) { - arr.slice() // OK - arr.push("hello!") // Compile-time error -} \ No newline at end of file diff --git a/linter/test_rules/rule141.ts.autofix.json b/linter/test_rules/rule141.ts.autofix.json deleted file mode 100644 index 4843ef02e..000000000 --- a/linter/test_rules/rule141.ts.autofix.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "nodes": [ - { - "line": 1, - "column": 19, - "problem": "ReadonlyArr", - "autofixable": true, - "autofix": [ - { - "start": 18, - "end": 35, - "replacementText": "string[]" - } - ], - "suggest": "", - "rule": "\"readonly T[]\" syntax is not supported (arkts-no-readonly-params)" - } - ] -} \ No newline at end of file diff --git a/linter/test_rules/rule141.ts.relax.json b/linter/test_rules/rule141.ts.relax.json deleted file mode 100644 index 13f13363f..000000000 --- a/linter/test_rules/rule141.ts.relax.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "nodes": [] -} \ No newline at end of file diff --git a/linter/test_rules/rule141.ts.strict.json b/linter/test_rules/rule141.ts.strict.json deleted file mode 100644 index 3d0ea4953..000000000 --- a/linter/test_rules/rule141.ts.strict.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "nodes": [ - { - "line": 1, - "column": 19, - "problem": "ReadonlyArr", - "suggest": "", - "rule": "\"readonly T[]\" syntax is not supported (arkts-no-readonly-params)" - } - ] -} \ No newline at end of file -- Gitee