diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 70ab7059c246a0cac14219687a5714b5ac12ab36..d39adfd11826c264c5ca78cf2deb47fccf63c12c 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -5377,6 +5377,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleObjectLiteralAssignmentToClass(tsAsExpr); this.handleArrayTypeImmutable(tsAsExpr, exprType, targetType); this.handleNotsLikeSmartTypeOnAsExpression(tsAsExpr); + this.handleLimitedVoidTypeOnAsExpression(tsAsExpr); } private isExemptedAsExpression(node: ts.AsExpression): boolean { @@ -6389,6 +6390,16 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } + private handleLimitedVoidTypeOnAsExpression(node: ts.AsExpression): void { + if (!this.options.arkts2) { + return; + } + const targetType = this.tsTypeChecker.getTypeAtLocation(node.type); + if (TsUtils.isVoidType(targetType)) { + this.incrementCounters(node.type, FaultID.LimitedVoidType); + } + } + private handleLimitedVoidWithCall(node: ts.CallExpression): void { if ( ts.isExpressionStatement(node.parent) || diff --git a/ets2panda/linter/test/main/limit_void_type.ets b/ets2panda/linter/test/main/limit_void_type.ets index 7979014031e6df6a469accd63d0acf47bcdba847..3dc13d8696c499bade5e2c1757b85042f991f59d 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets +++ b/ets2panda/linter/test/main/limit_void_type.ets @@ -13,7 +13,7 @@ * limitations under the License. */ - +import {unionVoidVal,undefinedFooFun,func3Void,fun4undefined,fun5String} from './limit_void_type2' // Example 1: Basic function function func1(): void { } let a: void = func1(); @@ -339,4 +339,27 @@ function test3(a: number): void | boolean { function test4(a: number): void | boolean { // will return -} \ No newline at end of file +} + +let unionVoid = (()=>{ + return undefined; +})() as void; //error +function undefinedFoo(){ + return undefined; +} +function unionFoo(): undefined | boolean{ + return undefined; +} +let asVoidFun = undefinedFoo() as void; //error +let undefinedAsVoid = undefined as void; //error +let unionFooAsVoid = unionFoo() as void; //error + +function func6() { + return undefined as void; //error +} + +let exportAsVoidFun = unionVoidVal as void; +let exportUndefinedFooFun = undefinedFooFun() as void; //error +let exportfunc3Void = func3Void() as void; //error +console.log(fun5String() as void); +typeof (fun4undefined() as void) //error diff --git a/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json b/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json index ba6319381d497e482a74b53b2929a47ec46ab4b5..869dd5a745d032086922850b518faa45edc6763f 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json @@ -144,6 +144,16 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, + { + "line": 39, + "column": 26, + "endLine": 39, + "endColumn": 30, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, { "line": 39, "column": 15, @@ -1723,6 +1733,116 @@ "suggest": "", "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" + }, + { + "line": 346, + "column": 9, + "endLine": 346, + "endColumn": 13, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 353, + "column": 35, + "endLine": 353, + "endColumn": 39, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 354, + "column": 36, + "endLine": 354, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 355, + "column": 36, + "endLine": 355, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 358, + "column": 23, + "endLine": 358, + "endColumn": 27, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 361, + "column": 39, + "endLine": 361, + "endColumn": 43, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 362, + "column": 50, + "endLine": 362, + "endColumn": 54, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 363, + "column": 38, + "endLine": 363, + "endColumn": 42, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 363, + "column": 23, + "endLine": 363, + "endColumn": 34, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 364, + "column": 29, + "endLine": 364, + "endColumn": 33, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 365, + "column": 28, + "endLine": 365, + "endColumn": 32, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type.ets.autofix.json b/ets2panda/linter/test/main/limit_void_type.ets.autofix.json index c8bcf12082781c3bbe1fd5d85908724b1ec36219..5354ed4de262bf52837a0a2116153e2b6997c4fb 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.autofix.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.autofix.json @@ -102,8 +102,8 @@ "problem": "FunctionExpression", "autofix": [ { - "start": 942, - "end": 963, + "start": 1040, + "end": 1061, "replacementText": "(): void => { }", "line": 29, "column": 16, @@ -155,6 +155,16 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, + { + "line": 39, + "column": 26, + "endLine": 39, + "endColumn": 30, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, { "line": 39, "column": 15, @@ -173,8 +183,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 1322, - "end": 1326, + "start": 1420, + "end": 1424, "replacementText": "1000.0", "line": 41, "column": 29, @@ -204,8 +214,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 1365, - "end": 1369, + "start": 1463, + "end": 1467, "replacementText": "1000.0", "line": 42, "column": 37, @@ -485,8 +495,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2527, - "end": 2528, + "start": 2625, + "end": 2626, "replacementText": "1.0", "line": 83, "column": 19, @@ -506,8 +516,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2530, - "end": 2531, + "start": 2628, + "end": 2629, "replacementText": "2.0", "line": 83, "column": 22, @@ -527,8 +537,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2533, - "end": 2534, + "start": 2631, + "end": 2632, "replacementText": "3.0", "line": 83, "column": 25, @@ -669,8 +679,8 @@ "autofix": [ { "replacementText": "GeneratedDestructArray_1", - "start": 3050, - "end": 3056, + "start": 3148, + "end": 3154, "line": 102, "column": 7, "endLine": 102, @@ -678,8 +688,8 @@ }, { "replacementText": "\nconst func = GeneratedDestructArray_1[0];\n", - "start": 3077, - "end": 3077, + "start": 3175, + "end": 3175, "line": 102, "column": 7, "endLine": 102, @@ -718,8 +728,8 @@ "problem": "ObjectTypeLiteral", "autofix": [ { - "start": 3128, - "end": 3159, + "start": 3226, + "end": 3257, "replacementText": "interface Wrapper {\n value: T;\n}", "line": 105, "column": 19, @@ -879,8 +889,8 @@ "problem": "FunctionExpression", "autofix": [ { - "start": 3757, - "end": 3783, + "start": 3855, + "end": 3881, "replacementText": "(target: any) => { }", "line": 126, "column": 10, @@ -1100,8 +1110,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 4599, - "end": 4619, + "start": 4697, + "end": 4717, "replacementText": "undefined | Promise", "line": 162, "column": 16, @@ -1109,8 +1119,8 @@ "endColumn": 36 }, { - "start": 4622, - "end": 4622, + "start": 4720, + "end": 4720, "replacementText": "\nreturn undefined;\n", "line": 162, "column": 16, @@ -1140,8 +1150,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 4686, - "end": 4699, + "start": 4784, + "end": 4797, "replacementText": "undefined | number", "line": 165, "column": 8, @@ -1149,8 +1159,8 @@ "endColumn": 21 }, { - "start": 4702, - "end": 4702, + "start": 4800, + "end": 4800, "replacementText": "\nreturn undefined;\n", "line": 165, "column": 8, @@ -1280,8 +1290,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5432, - "end": 5445, + "start": 5530, + "end": 5543, "replacementText": "string | undefined", "line": 211, "column": 29, @@ -1289,8 +1299,8 @@ "endColumn": 42 }, { - "start": 5489, - "end": 5489, + "start": 5587, + "end": 5587, "replacementText": "\nreturn undefined;\n", "line": 211, "column": 29, @@ -1320,8 +1330,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5459, - "end": 5460, + "start": 5557, + "end": 5558, "replacementText": "0.0", "line": 212, "column": 12, @@ -1341,8 +1351,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5521, - "end": 5534, + "start": 5619, + "end": 5632, "replacementText": "string | undefined", "line": 217, "column": 30, @@ -1350,8 +1360,8 @@ "endColumn": 43 }, { - "start": 5556, - "end": 5563, + "start": 5654, + "end": 5661, "replacementText": "return undefined;", "line": 217, "column": 30, @@ -1381,8 +1391,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5547, - "end": 5548, + "start": 5645, + "end": 5646, "replacementText": "0.0", "line": 218, "column": 11, @@ -1482,8 +1492,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5691, - "end": 5692, + "start": 5789, + "end": 5790, "replacementText": "1.0", "line": 226, "column": 25, @@ -1503,8 +1513,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5725, - "end": 5738, + "start": 5823, + "end": 5836, "replacementText": "string | undefined", "line": 228, "column": 31, @@ -1512,8 +1522,8 @@ "endColumn": 44 }, { - "start": 5764, - "end": 5771, + "start": 5862, + "end": 5869, "replacementText": "return undefined;", "line": 228, "column": 31, @@ -1521,8 +1531,8 @@ "endColumn": 44 }, { - "start": 5842, - "end": 5849, + "start": 5940, + "end": 5947, "replacementText": "return undefined;", "line": 228, "column": 31, @@ -1530,8 +1540,8 @@ "endColumn": 44 }, { - "start": 5854, - "end": 5854, + "start": 5952, + "end": 5952, "replacementText": "\nreturn undefined;\n", "line": 228, "column": 31, @@ -1561,8 +1571,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5754, - "end": 5756, + "start": 5852, + "end": 5854, "replacementText": "12.0", "line": 229, "column": 14, @@ -1582,8 +1592,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5792, - "end": 5794, + "start": 5890, + "end": 5892, "replacementText": "18.0", "line": 231, "column": 21, @@ -1603,8 +1613,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5894, - "end": 5907, + "start": 5992, + "end": 6005, "replacementText": "string | undefined", "line": 238, "column": 38, @@ -1612,8 +1622,8 @@ "endColumn": 51 }, { - "start": 5989, - "end": 5996, + "start": 6087, + "end": 6094, "replacementText": "return undefined;", "line": 238, "column": 38, @@ -1643,8 +1653,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6021, - "end": 6034, + "start": 6119, + "end": 6132, "replacementText": "string | undefined", "line": 246, "column": 22, @@ -1652,8 +1662,8 @@ "endColumn": 35 }, { - "start": 6062, - "end": 6062, + "start": 6160, + "end": 6160, "replacementText": "\nreturn undefined;\n", "line": 246, "column": 22, @@ -1683,8 +1693,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6099, - "end": 6112, + "start": 6197, + "end": 6210, "replacementText": "string | undefined", "line": 250, "column": 35, @@ -1692,8 +1702,8 @@ "endColumn": 48 }, { - "start": 6192, - "end": 6192, + "start": 6290, + "end": 6290, "replacementText": "\nreturn undefined;\n", "line": 250, "column": 35, @@ -1733,8 +1743,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6142, - "end": 6143, + "start": 6240, + "end": 6241, "replacementText": "1.0", "line": 252, "column": 10, @@ -1754,8 +1764,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6167, - "end": 6168, + "start": 6265, + "end": 6266, "replacementText": "2.0", "line": 253, "column": 10, @@ -1775,8 +1785,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6216, - "end": 6229, + "start": 6314, + "end": 6327, "replacementText": "string | undefined", "line": 257, "column": 22, @@ -1784,8 +1794,8 @@ "endColumn": 35 }, { - "start": 6304, - "end": 6304, + "start": 6402, + "end": 6402, "replacementText": "\nreturn undefined;\n", "line": 257, "column": 22, @@ -1835,8 +1845,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6370, - "end": 6384, + "start": 6468, + "end": 6482, "replacementText": "boolean | undefined", "line": 269, "column": 20, @@ -1844,8 +1854,8 @@ "endColumn": 34 }, { - "start": 6431, - "end": 6438, + "start": 6529, + "end": 6536, "replacementText": "return undefined;", "line": 269, "column": 20, @@ -1853,8 +1863,8 @@ "endColumn": 34 }, { - "start": 6468, - "end": 6475, + "start": 6566, + "end": 6573, "replacementText": "return undefined;", "line": 269, "column": 20, @@ -1884,8 +1894,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6399, - "end": 6400, + "start": 6497, + "end": 6498, "replacementText": "0.0", "line": 270, "column": 13, @@ -1905,8 +1915,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6501, - "end": 6515, + "start": 6599, + "end": 6613, "replacementText": "undefined | boolean", "line": 278, "column": 21, @@ -1914,8 +1924,8 @@ "endColumn": 35 }, { - "start": 6604, - "end": 6611, + "start": 6702, + "end": 6709, "replacementText": "return undefined;", "line": 278, "column": 21, @@ -1945,8 +1955,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6530, - "end": 6531, + "start": 6628, + "end": 6629, "replacementText": "0.0", "line": 279, "column": 13, @@ -1966,8 +1976,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6637, - "end": 6651, + "start": 6735, + "end": 6749, "replacementText": "undefined | boolean", "line": 287, "column": 21, @@ -1975,8 +1985,8 @@ "endColumn": 35 }, { - "start": 6698, - "end": 6705, + "start": 6796, + "end": 6803, "replacementText": "return undefined;", "line": 287, "column": 21, @@ -1984,8 +1994,8 @@ "endColumn": 35 }, { - "start": 6714, - "end": 6714, + "start": 6812, + "end": 6812, "replacementText": "\nreturn undefined;\n", "line": 287, "column": 21, @@ -2015,8 +2025,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6666, - "end": 6667, + "start": 6764, + "end": 6765, "replacementText": "0.0", "line": 288, "column": 13, @@ -2036,8 +2046,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6737, - "end": 6751, + "start": 6835, + "end": 6849, "replacementText": "undefined | boolean", "line": 294, "column": 21, @@ -2045,8 +2055,8 @@ "endColumn": 35 }, { - "start": 6798, - "end": 6805, + "start": 6896, + "end": 6903, "replacementText": "return undefined;", "line": 294, "column": 21, @@ -2076,8 +2086,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6766, - "end": 6767, + "start": 6864, + "end": 6865, "replacementText": "0.0", "line": 295, "column": 13, @@ -2097,8 +2107,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6846, - "end": 6860, + "start": 6944, + "end": 6958, "replacementText": "undefined | boolean", "line": 302, "column": 12, @@ -2106,8 +2116,8 @@ "endColumn": 26 }, { - "start": 6884, - "end": 6884, + "start": 6982, + "end": 6982, "replacementText": "\nreturn undefined;\n", "line": 302, "column": 12, @@ -2137,8 +2147,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6915, - "end": 6929, + "start": 7013, + "end": 7027, "replacementText": "boolean | undefined", "line": 307, "column": 27, @@ -2146,8 +2156,8 @@ "endColumn": 41 }, { - "start": 6970, - "end": 6977, + "start": 7068, + "end": 7075, "replacementText": "return undefined;", "line": 307, "column": 27, @@ -2155,8 +2165,8 @@ "endColumn": 41 }, { - "start": 7001, - "end": 7008, + "start": 7099, + "end": 7106, "replacementText": "return undefined;", "line": 307, "column": 27, @@ -2186,8 +2196,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6942, - "end": 6943, + "start": 7040, + "end": 7041, "replacementText": "0.0", "line": 308, "column": 11, @@ -2207,8 +2217,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7039, - "end": 7053, + "start": 7137, + "end": 7151, "replacementText": "undefined | boolean", "line": 316, "column": 28, @@ -2216,8 +2226,8 @@ "endColumn": 42 }, { - "start": 7130, - "end": 7137, + "start": 7228, + "end": 7235, "replacementText": "return undefined;", "line": 316, "column": 28, @@ -2247,8 +2257,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 7066, - "end": 7067, + "start": 7164, + "end": 7165, "replacementText": "0.0", "line": 317, "column": 11, @@ -2268,8 +2278,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7168, - "end": 7182, + "start": 7266, + "end": 7280, "replacementText": "undefined | boolean", "line": 325, "column": 28, @@ -2277,8 +2287,8 @@ "endColumn": 42 }, { - "start": 7223, - "end": 7230, + "start": 7321, + "end": 7328, "replacementText": "return undefined;", "line": 325, "column": 28, @@ -2286,8 +2296,8 @@ "endColumn": 42 }, { - "start": 7235, - "end": 7235, + "start": 7333, + "end": 7333, "replacementText": "\nreturn undefined;\n", "line": 325, "column": 28, @@ -2317,8 +2327,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 7195, - "end": 7196, + "start": 7293, + "end": 7294, "replacementText": "0.0", "line": 326, "column": 11, @@ -2338,8 +2348,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7265, - "end": 7279, + "start": 7363, + "end": 7377, "replacementText": "undefined | boolean", "line": 332, "column": 28, @@ -2347,8 +2357,8 @@ "endColumn": 42 }, { - "start": 7320, - "end": 7327, + "start": 7418, + "end": 7425, "replacementText": "return undefined;", "line": 332, "column": 28, @@ -2378,8 +2388,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 7292, - "end": 7293, + "start": 7390, + "end": 7391, "replacementText": "0.0", "line": 333, "column": 11, @@ -2399,8 +2409,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7378, - "end": 7392, + "start": 7476, + "end": 7490, "replacementText": "undefined | boolean", "line": 340, "column": 28, @@ -2408,8 +2418,8 @@ "endColumn": 42 }, { - "start": 7412, - "end": 7412, + "start": 7510, + "end": 7510, "replacementText": "\nreturn undefined;\n", "line": 340, "column": 28, @@ -2430,6 +2440,116 @@ "suggest": "", "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" + }, + { + "line": 346, + "column": 9, + "endLine": 346, + "endColumn": 13, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 353, + "column": 35, + "endLine": 353, + "endColumn": 39, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 354, + "column": 36, + "endLine": 354, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 355, + "column": 36, + "endLine": 355, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 358, + "column": 23, + "endLine": 358, + "endColumn": 27, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 361, + "column": 39, + "endLine": 361, + "endColumn": 43, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 362, + "column": 50, + "endLine": 362, + "endColumn": 54, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 363, + "column": 38, + "endLine": 363, + "endColumn": 42, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 363, + "column": 23, + "endLine": 363, + "endColumn": 34, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 364, + "column": 29, + "endLine": 364, + "endColumn": 33, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 365, + "column": 28, + "endLine": 365, + "endColumn": 32, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type.ets.migrate.ets b/ets2panda/linter/test/main/limit_void_type.ets.migrate.ets index 62243efb6d249edbb2f93496093630c17acb1888..6fb52453a31411d68a9504689737838b84db7982 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.migrate.ets +++ b/ets2panda/linter/test/main/limit_void_type.ets.migrate.ets @@ -13,7 +13,7 @@ * limitations under the License. */ - +import {unionVoidVal,undefinedFooFun,func3Void,fun4undefined,fun5String} from './limit_void_type2' // Example 1: Basic function function func1(): void { } let a: void = func1(); @@ -365,4 +365,27 @@ function test4(a: number): undefined | boolean { // will return return undefined; -} \ No newline at end of file +} + +let unionVoid = (()=>{ + return undefined; +})() as void; //error +function undefinedFoo(){ + return undefined; +} +function unionFoo(): undefined | boolean{ + return undefined; +} +let asVoidFun = undefinedFoo() as void; //error +let undefinedAsVoid = undefined as void; //error +let unionFooAsVoid = unionFoo() as void; //error + +function func6() { + return undefined as void; //error +} + +let exportAsVoidFun = unionVoidVal as void; +let exportUndefinedFooFun = undefinedFooFun() as void; //error +let exportfunc3Void = func3Void() as void; //error +console.log(fun5String() as void); +typeof (fun4undefined() as void) //error diff --git a/ets2panda/linter/test/main/limit_void_type.ets.migrate.json b/ets2panda/linter/test/main/limit_void_type.ets.migrate.json index cef5d595cb318cefba01dc8098f4154b713ee62b..c2f3a35660609daaba6cfc031f6767337b0846c0 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.migrate.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.migrate.json @@ -134,6 +134,16 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, + { + "line": 39, + "column": 26, + "endLine": 39, + "endColumn": 30, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, { "line": 39, "column": 15, @@ -1103,6 +1113,116 @@ "suggest": "", "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" + }, + { + "line": 372, + "column": 9, + "endLine": 372, + "endColumn": 13, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 379, + "column": 35, + "endLine": 379, + "endColumn": 39, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 380, + "column": 36, + "endLine": 380, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 381, + "column": 36, + "endLine": 381, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 384, + "column": 23, + "endLine": 384, + "endColumn": 27, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 387, + "column": 39, + "endLine": 387, + "endColumn": 43, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 388, + "column": 50, + "endLine": 388, + "endColumn": 54, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 389, + "column": 38, + "endLine": 389, + "endColumn": 42, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 389, + "column": 23, + "endLine": 389, + "endColumn": 34, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 390, + "column": 29, + "endLine": 390, + "endColumn": 33, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 391, + "column": 28, + "endLine": 391, + "endColumn": 32, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type2.ets b/ets2panda/linter/test/main/limit_void_type2.ets new file mode 100644 index 0000000000000000000000000000000000000000..dc2727c71674f9af7c6792bed305307b620a86ce --- /dev/null +++ b/ets2panda/linter/test/main/limit_void_type2.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export let unionVoidVal = (()=>{ + return undefined; +})() as void; +export function undefinedFooFun(){ + return undefined; +} +export function func3Void(): void { } +export function fun4undefined(): undefined | boolean { } +export function fun5String(): string { + return ''; +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type2.ets.json b/ets2panda/linter/test/main/limit_void_type2.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/limit_void_type2.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 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." + ], + "result": [] +} \ No newline at end of file