• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16// Fixable
17
18function addNum(a: number, b: number): void {
19    let logToConsole: (message: String) => void = (message: String): void => {
20    console.log(message);
21};
22
23    let result = a + b
24
25    logToConsole("result is " + result)
26}
27
28
29function addNum2(a: number, b: number): void {
30    // Use lambda instead of a nested function:
31    let logToConsole: (message: string) => void = (message: string): void => {
32        console.log(message)
33    }
34
35    let result = a + b
36
37    logToConsole("result is " + result)
38}
39
40
41function NestedOne(a: number, b: number): void {
42    let NestedTwo: (message: String) => void = (message: String): void => {
43    let NestedThree: (message: String) => void = (message: String): void => {
44    console.log("NestedThree");
45};
46};
47}
48
49
50function NestedOne1(a: number, b: number): void {
51    let NestedTwo: (message: String) => void = (message: String): void => {
52    console.log("NestedTwo");
53};
54
55    let NestedTooToo: (message: String) => void = (message: String): void => {
56    console.log("NestedTooToo");
57};
58}
59
60function NestedOne2(a: number, b: number): void {
61    let NestedTwo: (message: String) => void = (message: String): void => {
62    let NestedThree: (message: String) => void = (message: String): void => {
63    console.log("NestedThree");
64};
65    let NestedThreeToo: (message: String) => void = (message: String): void => {
66    console.log("NestedThreeToo");
67};
68};
69}
70
71// Not fixable
72function decoratorFoo(): void {
73    @decorator
74    function decorated(): void {
75    }
76
77    function* generatorFunction() {
78        return 3;
79    }
80
81    function thisFoo() {
82        return this.what;
83    }
84
85    notFixable();
86
87    function notFixable(): void {
88    }
89}
90
91