From f9da262c4d16ed7354c681c9e72624bc1486bbb8 Mon Sep 17 00:00:00 2001 From: Ilya Trubachev Date: Tue, 19 Sep 2023 17:11:44 +0300 Subject: [PATCH] Relax recipe 99 Signed-off-by: Ilya Trubachev --- linter-4.2/docs/rules/recipe99.md | 18 +++++++++++---- linter-4.2/src/CookBookMsg.ts | 2 +- linter-4.2/src/TypeScriptLinter.ts | 6 +++-- linter-4.2/test/array_literal_spread.ts | 23 +++++++++++++++++++ .../test/array_literal_spread.ts.autofix.skip | 0 .../test/array_literal_spread.ts.relax.json | 17 ++++++++++++++ .../test/array_literal_spread.ts.strict.json | 17 ++++++++++++++ linter-4.2/test/destructuring.ts.relax.json | 5 ---- linter-4.2/test/destructuring.ts.strict.json | 5 ---- linter-4.2/test_rules/rule69.ts.autofix.json | 2 +- linter-4.2/test_rules/rule69.ts.relax.json | 2 +- linter-4.2/test_rules/rule69.ts.strict.json | 2 +- linter-4.2/test_rules/rule99.ts | 11 ++++++++- linter-4.2/test_rules/rule99.ts.autofix.json | 12 ++-------- linter-4.2/test_rules/rule99.ts.relax.json | 11 ++------- linter-4.2/test_rules/rule99.ts.strict.json | 11 ++------- linter/docs/rules/recipe99.md | 18 +++++++++++---- linter/src/CookBookMsg.ts | 2 +- linter/src/TypeScriptLinter.ts | 5 ++-- linter/test/array_literal_spread.ts | 23 +++++++++++++++++++ .../test/array_literal_spread.ts.autofix.skip | 0 .../test/array_literal_spread.ts.relax.json | 17 ++++++++++++++ .../test/array_literal_spread.ts.strict.json | 17 ++++++++++++++ linter/test/destructuring.ts.relax.json | 5 ---- linter/test/destructuring.ts.strict.json | 5 ---- linter/test_rules/rule69.ts.autofix.json | 2 +- linter/test_rules/rule69.ts.relax.json | 2 +- linter/test_rules/rule69.ts.strict.json | 2 +- linter/test_rules/rule99.ts | 11 ++++++++- linter/test_rules/rule99.ts.autofix.json | 12 ++-------- linter/test_rules/rule99.ts.relax.json | 11 ++------- linter/test_rules/rule99.ts.strict.json | 11 ++------- 32 files changed, 187 insertions(+), 100 deletions(-) create mode 100644 linter-4.2/test/array_literal_spread.ts create mode 100644 linter-4.2/test/array_literal_spread.ts.autofix.skip create mode 100644 linter-4.2/test/array_literal_spread.ts.relax.json create mode 100644 linter-4.2/test/array_literal_spread.ts.strict.json create mode 100644 linter/test/array_literal_spread.ts create mode 100644 linter/test/array_literal_spread.ts.autofix.skip create mode 100644 linter/test/array_literal_spread.ts.relax.json create mode 100644 linter/test/array_literal_spread.ts.strict.json diff --git a/linter-4.2/docs/rules/recipe99.md b/linter-4.2/docs/rules/recipe99.md index 3b8fb7974..b5c78af07 100644 --- a/linter-4.2/docs/rules/recipe99.md +++ b/linter-4.2/docs/rules/recipe99.md @@ -1,13 +1,14 @@ -# It is possible to spread only arrays into the rest parameter +# It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals Rule ``arkts-no-spread`` **Severity: error** -The only supported scenario for the spread operator is to spread an array into -the rest parameter. Otherwise, manually "unpack" data from arrays and objects, -where necessary. All typed arrays from the standard library (for example, -``Int32Array``) are also supported. +The only supported scenario for the spread operator is to spread an array or +class derived from array into the rest parameter or array literal. +Otherwise, manually "unpack" data from arrays and objects, where necessary. +All typed arrays from the standard library (for example, ``Int32Array``) +are also supported. ## TypeScript @@ -68,6 +69,13 @@ where necessary. All typed arrays from the standard library (for example, let p3d = new Point3D({x: 1, y: 2} as Point2D, 3) console.log(p3d.x, p3d.y, p3d.z) + class DerivedFromArray extends Uint16Array {}; + + let arr1 = [1, 2, 3]; + let arr2 = new Uint16Array([4, 5, 6]); + let arr3 = new DerivedFromArray([7, 8, 9]) + let arr4 = [...arr1, 10, ...arr2, 11, ...arr3] + ``` diff --git a/linter-4.2/src/CookBookMsg.ts b/linter-4.2/src/CookBookMsg.ts index 87c5dc8ff..621eeb670 100644 --- a/linter-4.2/src/CookBookMsg.ts +++ b/linter-4.2/src/CookBookMsg.ts @@ -118,7 +118,7 @@ cookBookTag[95] = ''; cookBookTag[96] = 'Type guarding is supported with "instanceof" and "as" (arkts-no-is)'; cookBookTag[97] = '"keyof" operator is not supported (arkts-no-keyof)'; cookBookTag[98] = ''; -cookBookTag[99] = 'It is possible to spread only arrays into the rest parameter (arkts-no-spread)'; +cookBookTag[99] = 'It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)'; cookBookTag[100] = ''; cookBookTag[101] = ''; cookBookTag[102] = 'Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)'; diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index c2a79bc87..13dfababa 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -2047,11 +2047,13 @@ export class TypeScriptLinter { ); if ( spreadExprTypeNode !== undefined && - ts.isCallLikeExpression(node.parent) + (ts.isCallLikeExpression(node.parent) || + ts.isArrayLiteralExpression(node.parent)) ) { if ( ts.isArrayTypeNode(spreadExprTypeNode) || - this.tsUtils.isTypedArray(spreadExprTypeNode) + this.tsUtils.isTypedArray(spreadExprTypeNode) || + this.tsUtils.isDerivedFromArray(spreadExprType) ) { return; } diff --git a/linter-4.2/test/array_literal_spread.ts b/linter-4.2/test/array_literal_spread.ts new file mode 100644 index 000000000..233c2c5d7 --- /dev/null +++ b/linter-4.2/test/array_literal_spread.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +class DerivedFromArray extends Uint16Array { +}; + +let arr1 = [1, 2, 3]; +let arr2 = new Uint16Array([4, 5, 6]); +let arr3 = new DerivedFromArray([7, 8, 9]) + +let arr4 = [...arr1, 10, ...arr2, 11, ...arr3] diff --git a/linter-4.2/test/array_literal_spread.ts.autofix.skip b/linter-4.2/test/array_literal_spread.ts.autofix.skip new file mode 100644 index 000000000..e69de29bb diff --git a/linter-4.2/test/array_literal_spread.ts.relax.json b/linter-4.2/test/array_literal_spread.ts.relax.json new file mode 100644 index 000000000..b06227021 --- /dev/null +++ b/linter-4.2/test/array_literal_spread.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-4.2/test/array_literal_spread.ts.strict.json b/linter-4.2/test/array_literal_spread.ts.strict.json new file mode 100644 index 000000000..b06227021 --- /dev/null +++ b/linter-4.2/test/array_literal_spread.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-4.2/test/destructuring.ts.relax.json b/linter-4.2/test/destructuring.ts.relax.json index 7053e79b9..14ae01cc1 100644 --- a/linter-4.2/test/destructuring.ts.relax.json +++ b/linter-4.2/test/destructuring.ts.relax.json @@ -59,11 +59,6 @@ "column": 10, "problem": "SpreadOperator" }, - { - "line": 51, - "column": 11, - "problem": "SpreadOperator" - }, { "line": 55, "column": 12, diff --git a/linter-4.2/test/destructuring.ts.strict.json b/linter-4.2/test/destructuring.ts.strict.json index 2bf3ea978..0c913b11c 100644 --- a/linter-4.2/test/destructuring.ts.strict.json +++ b/linter-4.2/test/destructuring.ts.strict.json @@ -84,11 +84,6 @@ "column": 10, "problem": "SpreadOperator" }, - { - "line": 51, - "column": 11, - "problem": "SpreadOperator" - }, { "line": 55, "column": 12, diff --git a/linter-4.2/test_rules/rule69.ts.autofix.json b/linter-4.2/test_rules/rule69.ts.autofix.json index 0c8f1f91d..647cff3bb 100644 --- a/linter-4.2/test_rules/rule69.ts.autofix.json +++ b/linter-4.2/test_rules/rule69.ts.autofix.json @@ -46,7 +46,7 @@ "problem": "SpreadOperator", "autofixable": false, "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule69.ts.relax.json b/linter-4.2/test_rules/rule69.ts.relax.json index 740d7e2ea..683feccb8 100644 --- a/linter-4.2/test_rules/rule69.ts.relax.json +++ b/linter-4.2/test_rules/rule69.ts.relax.json @@ -19,7 +19,7 @@ "column": 8, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule69.ts.strict.json b/linter-4.2/test_rules/rule69.ts.strict.json index d09d39688..eb5a79b2a 100644 --- a/linter-4.2/test_rules/rule69.ts.strict.json +++ b/linter-4.2/test_rules/rule69.ts.strict.json @@ -40,7 +40,7 @@ "column": 8, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule99.ts b/linter-4.2/test_rules/rule99.ts index 61f72c85a..aa9b0f100 100644 --- a/linter-4.2/test_rules/rule99.ts +++ b/linter-4.2/test_rules/rule99.ts @@ -45,4 +45,13 @@ class Point3D { } let p3d = new Point3D({x: 1, y: 2} as Point2D, 3) -console.log(p3d.x, p3d.y, p3d.z) \ No newline at end of file +console.log(p3d.x, p3d.y, p3d.z) + +class DerivedFromArray extends Uint16Array { +}; + +let arr1 = [1, 2, 3]; +let arr2 = new Uint16Array([4, 5, 6]); +let arr3 = new DerivedFromArray([7, 8, 9]) + +let arr4 = [...arr1, 10, ...arr2, 11, ...arr3] diff --git a/linter-4.2/test_rules/rule99.ts.autofix.json b/linter-4.2/test_rules/rule99.ts.autofix.json index b2639eb97..35f8ae0de 100644 --- a/linter-4.2/test_rules/rule99.ts.autofix.json +++ b/linter-4.2/test_rules/rule99.ts.autofix.json @@ -14,15 +14,7 @@ "problem": "SpreadOperator", "autofixable": false, "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" - }, - { - "line": 9, - "column": 14, - "problem": "SpreadOperator", - "autofixable": false, - "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" }, { "line": 11, @@ -46,7 +38,7 @@ "problem": "SpreadOperator", "autofixable": false, "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule99.ts.relax.json b/linter-4.2/test_rules/rule99.ts.relax.json index df5204fcf..21a12fd10 100644 --- a/linter-4.2/test_rules/rule99.ts.relax.json +++ b/linter-4.2/test_rules/rule99.ts.relax.json @@ -12,14 +12,7 @@ "column": 5, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" - }, - { - "line": 9, - "column": 14, - "problem": "SpreadOperator", - "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" }, { "line": 11, @@ -40,7 +33,7 @@ "column": 16, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule99.ts.strict.json b/linter-4.2/test_rules/rule99.ts.strict.json index df5204fcf..21a12fd10 100644 --- a/linter-4.2/test_rules/rule99.ts.strict.json +++ b/linter-4.2/test_rules/rule99.ts.strict.json @@ -12,14 +12,7 @@ "column": 5, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" - }, - { - "line": 9, - "column": 14, - "problem": "SpreadOperator", - "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" }, { "line": 11, @@ -40,7 +33,7 @@ "column": 16, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter/docs/rules/recipe99.md b/linter/docs/rules/recipe99.md index 3b8fb7974..b5c78af07 100644 --- a/linter/docs/rules/recipe99.md +++ b/linter/docs/rules/recipe99.md @@ -1,13 +1,14 @@ -# It is possible to spread only arrays into the rest parameter +# It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals Rule ``arkts-no-spread`` **Severity: error** -The only supported scenario for the spread operator is to spread an array into -the rest parameter. Otherwise, manually "unpack" data from arrays and objects, -where necessary. All typed arrays from the standard library (for example, -``Int32Array``) are also supported. +The only supported scenario for the spread operator is to spread an array or +class derived from array into the rest parameter or array literal. +Otherwise, manually "unpack" data from arrays and objects, where necessary. +All typed arrays from the standard library (for example, ``Int32Array``) +are also supported. ## TypeScript @@ -68,6 +69,13 @@ where necessary. All typed arrays from the standard library (for example, let p3d = new Point3D({x: 1, y: 2} as Point2D, 3) console.log(p3d.x, p3d.y, p3d.z) + class DerivedFromArray extends Uint16Array {}; + + let arr1 = [1, 2, 3]; + let arr2 = new Uint16Array([4, 5, 6]); + let arr3 = new DerivedFromArray([7, 8, 9]) + let arr4 = [...arr1, 10, ...arr2, 11, ...arr3] + ``` diff --git a/linter/src/CookBookMsg.ts b/linter/src/CookBookMsg.ts index 87c5dc8ff..621eeb670 100644 --- a/linter/src/CookBookMsg.ts +++ b/linter/src/CookBookMsg.ts @@ -118,7 +118,7 @@ cookBookTag[95] = ''; cookBookTag[96] = 'Type guarding is supported with "instanceof" and "as" (arkts-no-is)'; cookBookTag[97] = '"keyof" operator is not supported (arkts-no-keyof)'; cookBookTag[98] = ''; -cookBookTag[99] = 'It is possible to spread only arrays into the rest parameter (arkts-no-spread)'; +cookBookTag[99] = 'It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)'; cookBookTag[100] = ''; cookBookTag[101] = ''; cookBookTag[102] = 'Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)'; diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index ea461af04..a2f70aae4 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -1654,8 +1654,9 @@ export class TypeScriptLinter { let spreadExprType = this.tsTypeChecker.getTypeAtLocation(spreadElemNode.expression); if (spreadExprType) { const spreadExprTypeNode = this.tsTypeChecker.typeToTypeNode(spreadExprType, undefined, ts.NodeBuilderFlags.None); - if (spreadExprTypeNode !== undefined && ts.isCallLikeExpression(node.parent)) { - if (ts.isArrayTypeNode(spreadExprTypeNode) || this.tsUtils.isTypedArray(spreadExprTypeNode)) { + if (spreadExprTypeNode !== undefined && (ts.isCallLikeExpression(node.parent) || ts.isArrayLiteralExpression(node.parent))) { + if (ts.isArrayTypeNode(spreadExprTypeNode) || this.tsUtils.isTypedArray(spreadExprTypeNode) || + this.tsUtils.isDerivedFromArray(spreadExprType)) { return } } diff --git a/linter/test/array_literal_spread.ts b/linter/test/array_literal_spread.ts new file mode 100644 index 000000000..233c2c5d7 --- /dev/null +++ b/linter/test/array_literal_spread.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +class DerivedFromArray extends Uint16Array { +}; + +let arr1 = [1, 2, 3]; +let arr2 = new Uint16Array([4, 5, 6]); +let arr3 = new DerivedFromArray([7, 8, 9]) + +let arr4 = [...arr1, 10, ...arr2, 11, ...arr3] diff --git a/linter/test/array_literal_spread.ts.autofix.skip b/linter/test/array_literal_spread.ts.autofix.skip new file mode 100644 index 000000000..e69de29bb diff --git a/linter/test/array_literal_spread.ts.relax.json b/linter/test/array_literal_spread.ts.relax.json new file mode 100644 index 000000000..b06227021 --- /dev/null +++ b/linter/test/array_literal_spread.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/array_literal_spread.ts.strict.json b/linter/test/array_literal_spread.ts.strict.json new file mode 100644 index 000000000..b06227021 --- /dev/null +++ b/linter/test/array_literal_spread.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/destructuring.ts.relax.json b/linter/test/destructuring.ts.relax.json index 7053e79b9..14ae01cc1 100644 --- a/linter/test/destructuring.ts.relax.json +++ b/linter/test/destructuring.ts.relax.json @@ -59,11 +59,6 @@ "column": 10, "problem": "SpreadOperator" }, - { - "line": 51, - "column": 11, - "problem": "SpreadOperator" - }, { "line": 55, "column": 12, diff --git a/linter/test/destructuring.ts.strict.json b/linter/test/destructuring.ts.strict.json index 2bf3ea978..0c913b11c 100644 --- a/linter/test/destructuring.ts.strict.json +++ b/linter/test/destructuring.ts.strict.json @@ -84,11 +84,6 @@ "column": 10, "problem": "SpreadOperator" }, - { - "line": 51, - "column": 11, - "problem": "SpreadOperator" - }, { "line": 55, "column": 12, diff --git a/linter/test_rules/rule69.ts.autofix.json b/linter/test_rules/rule69.ts.autofix.json index 0c8f1f91d..647cff3bb 100644 --- a/linter/test_rules/rule69.ts.autofix.json +++ b/linter/test_rules/rule69.ts.autofix.json @@ -46,7 +46,7 @@ "problem": "SpreadOperator", "autofixable": false, "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule69.ts.relax.json b/linter/test_rules/rule69.ts.relax.json index 740d7e2ea..683feccb8 100644 --- a/linter/test_rules/rule69.ts.relax.json +++ b/linter/test_rules/rule69.ts.relax.json @@ -19,7 +19,7 @@ "column": 8, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule69.ts.strict.json b/linter/test_rules/rule69.ts.strict.json index d09d39688..eb5a79b2a 100644 --- a/linter/test_rules/rule69.ts.strict.json +++ b/linter/test_rules/rule69.ts.strict.json @@ -40,7 +40,7 @@ "column": 8, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule99.ts b/linter/test_rules/rule99.ts index 61f72c85a..aa9b0f100 100644 --- a/linter/test_rules/rule99.ts +++ b/linter/test_rules/rule99.ts @@ -45,4 +45,13 @@ class Point3D { } let p3d = new Point3D({x: 1, y: 2} as Point2D, 3) -console.log(p3d.x, p3d.y, p3d.z) \ No newline at end of file +console.log(p3d.x, p3d.y, p3d.z) + +class DerivedFromArray extends Uint16Array { +}; + +let arr1 = [1, 2, 3]; +let arr2 = new Uint16Array([4, 5, 6]); +let arr3 = new DerivedFromArray([7, 8, 9]) + +let arr4 = [...arr1, 10, ...arr2, 11, ...arr3] diff --git a/linter/test_rules/rule99.ts.autofix.json b/linter/test_rules/rule99.ts.autofix.json index b2639eb97..35f8ae0de 100644 --- a/linter/test_rules/rule99.ts.autofix.json +++ b/linter/test_rules/rule99.ts.autofix.json @@ -14,15 +14,7 @@ "problem": "SpreadOperator", "autofixable": false, "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" - }, - { - "line": 9, - "column": 14, - "problem": "SpreadOperator", - "autofixable": false, - "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" }, { "line": 11, @@ -46,7 +38,7 @@ "problem": "SpreadOperator", "autofixable": false, "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule99.ts.relax.json b/linter/test_rules/rule99.ts.relax.json index df5204fcf..21a12fd10 100644 --- a/linter/test_rules/rule99.ts.relax.json +++ b/linter/test_rules/rule99.ts.relax.json @@ -12,14 +12,7 @@ "column": 5, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" - }, - { - "line": 9, - "column": 14, - "problem": "SpreadOperator", - "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" }, { "line": 11, @@ -40,7 +33,7 @@ "column": 16, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule99.ts.strict.json b/linter/test_rules/rule99.ts.strict.json index df5204fcf..21a12fd10 100644 --- a/linter/test_rules/rule99.ts.strict.json +++ b/linter/test_rules/rule99.ts.strict.json @@ -12,14 +12,7 @@ "column": 5, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" - }, - { - "line": 9, - "column": 14, - "problem": "SpreadOperator", - "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" }, { "line": 11, @@ -40,7 +33,7 @@ "column": 16, "problem": "SpreadOperator", "suggest": "", - "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + "rule": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)" } ] } \ No newline at end of file -- Gitee