1/*
2 * Copyright (c) 2023-2024 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    function logToConsole(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    function NestedTwo(message: String): void {
43        function NestedThree(message: String): void {
44            console.log("NestedThree");
45        }
46    }
47}
48
49
50function NestedOne1(a: number, b: number): void {
51    function NestedTwo(message: String): void {
52        console.log("NestedTwo")
53    }
54
55    function NestedTooToo(message: String): void {
56        console.log("NestedTooToo")
57    }
58}
59
60function NestedOne2(a: number, b: number): void {
61    function NestedTwo(message: String): void {
62        function NestedThree(message: String): void {
63            console.log("NestedThree")
64        }
65
66        function NestedThreeToo(message: String): void {
67            console.log("NestedThreeToo")
68        }
69    }
70}
71
72// Not fixable
73function decoratorFoo(): void {
74    @decorator
75    function decorated(): void {
76    }
77
78    function* generatorFunction() {
79        return 3;
80    }
81
82    function thisFoo() {
83        return this.what;
84    }
85
86    notFixable();
87
88    function notFixable(): void {
89    }
90}
91
92