|
| 1 | +import { describe, expect, test } from "@jest/globals"; |
| 2 | + |
| 3 | +import { convertTypedef } from "../typedef"; |
| 4 | + |
| 5 | +describe("convertTypedef", () => { |
| 6 | + test("conversion without arguments", () => { |
| 7 | + const result = convertTypedef({ |
| 8 | + ruleArguments: [], |
| 9 | + }); |
| 10 | + |
| 11 | + expect(result).toEqual({ |
| 12 | + rules: [ |
| 13 | + { |
| 14 | + ruleName: "@typescript-eslint/typedef", |
| 15 | + }, |
| 16 | + { |
| 17 | + ruleName: "@typescript-eslint/explicit-function-return-type", |
| 18 | + }, |
| 19 | + { |
| 20 | + ruleName: "@typescript-eslint/explicit-module-boundary-types", |
| 21 | + }, |
| 22 | + ], |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + test("conversion with a few arguments", () => { |
| 27 | + const result = convertTypedef({ |
| 28 | + ruleArguments: [ |
| 29 | + "parameter", |
| 30 | + "variable-declaration-ignore-function", |
| 31 | + "array-destructuring", |
| 32 | + ], |
| 33 | + }); |
| 34 | + |
| 35 | + expect(result).toEqual({ |
| 36 | + rules: [ |
| 37 | + { |
| 38 | + ruleArguments: [ |
| 39 | + { |
| 40 | + parameter: true, |
| 41 | + variableDeclarationIgnoreFunction: true, |
| 42 | + arrayDestructuring: true, |
| 43 | + }, |
| 44 | + ], |
| 45 | + ruleName: "@typescript-eslint/typedef", |
| 46 | + }, |
| 47 | + { |
| 48 | + ruleName: "@typescript-eslint/explicit-function-return-type", |
| 49 | + }, |
| 50 | + { |
| 51 | + ruleName: "@typescript-eslint/explicit-module-boundary-types", |
| 52 | + }, |
| 53 | + ], |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + test("conversion with all arguments", () => { |
| 58 | + const result = convertTypedef({ |
| 59 | + ruleArguments: [ |
| 60 | + "parameter", |
| 61 | + "arrow-parameter", |
| 62 | + "property-declaration", |
| 63 | + "variable-declaration", |
| 64 | + "variable-declaration-ignore-function", |
| 65 | + "member-variable-declaration", |
| 66 | + "object-destructuring", |
| 67 | + "array-destructuring", |
| 68 | + ], |
| 69 | + }); |
| 70 | + |
| 71 | + expect(result).toEqual({ |
| 72 | + rules: [ |
| 73 | + { |
| 74 | + ruleArguments: [ |
| 75 | + { |
| 76 | + parameter: true, |
| 77 | + arrowParameter: true, |
| 78 | + propertyDeclaration: true, |
| 79 | + variableDeclaration: true, |
| 80 | + variableDeclarationIgnoreFunction: true, |
| 81 | + memberVariableDeclaration: true, |
| 82 | + objectDestructuring: true, |
| 83 | + arrayDestructuring: true, |
| 84 | + }, |
| 85 | + ], |
| 86 | + ruleName: "@typescript-eslint/typedef", |
| 87 | + }, |
| 88 | + { |
| 89 | + ruleName: "@typescript-eslint/explicit-function-return-type", |
| 90 | + }, |
| 91 | + { |
| 92 | + ruleName: "@typescript-eslint/explicit-module-boundary-types", |
| 93 | + }, |
| 94 | + ], |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + test("conversion with call-signature", () => { |
| 99 | + const result = convertTypedef({ |
| 100 | + ruleArguments: ["call-signature"], |
| 101 | + }); |
| 102 | + |
| 103 | + expect(result).toEqual({ |
| 104 | + notices: [ |
| 105 | + "ESLint does not differentiate between the call signatures of arrow and non-arrow functions. Both will be checked", |
| 106 | + ], |
| 107 | + rules: [ |
| 108 | + { |
| 109 | + ruleName: "@typescript-eslint/typedef", |
| 110 | + }, |
| 111 | + { |
| 112 | + ruleArguments: [ |
| 113 | + { |
| 114 | + allowExpressions: false, |
| 115 | + allowTypedFunctionExpressions: false, |
| 116 | + allowHigherOrderFunctions: false, |
| 117 | + allowDirectConstAssertionInArrowFunctions: true, |
| 118 | + allowConciseArrowFunctionExpressionsStartingWithVoid: true, |
| 119 | + }, |
| 120 | + ], |
| 121 | + ruleName: "@typescript-eslint/explicit-function-return-type", |
| 122 | + }, |
| 123 | + { |
| 124 | + ruleArguments: [ |
| 125 | + { |
| 126 | + allowArgumentsExplicitlyTypedAsAny: true, |
| 127 | + allowDirectConstAssertionInArrowFunctions: true, |
| 128 | + allowHigherOrderFunctions: false, |
| 129 | + allowTypedFunctionExpressions: false, |
| 130 | + }, |
| 131 | + ], |
| 132 | + ruleName: "@typescript-eslint/explicit-module-boundary-types", |
| 133 | + }, |
| 134 | + ], |
| 135 | + }); |
| 136 | + }); |
| 137 | + |
| 138 | + test("conversion with arrow-call-signature", () => { |
| 139 | + const result = convertTypedef({ |
| 140 | + ruleArguments: ["arrow-call-signature"], |
| 141 | + }); |
| 142 | + |
| 143 | + expect(result).toEqual({ |
| 144 | + notices: [ |
| 145 | + "ESLint does not differentiate between the call signatures of arrow and non-arrow functions. Both will be checked", |
| 146 | + ], |
| 147 | + rules: [ |
| 148 | + { |
| 149 | + ruleName: "@typescript-eslint/typedef", |
| 150 | + }, |
| 151 | + { |
| 152 | + ruleArguments: [ |
| 153 | + { |
| 154 | + allowExpressions: false, |
| 155 | + allowTypedFunctionExpressions: false, |
| 156 | + allowHigherOrderFunctions: false, |
| 157 | + allowDirectConstAssertionInArrowFunctions: true, |
| 158 | + allowConciseArrowFunctionExpressionsStartingWithVoid: true, |
| 159 | + }, |
| 160 | + ], |
| 161 | + ruleName: "@typescript-eslint/explicit-function-return-type", |
| 162 | + }, |
| 163 | + { |
| 164 | + ruleArguments: [ |
| 165 | + { |
| 166 | + allowArgumentsExplicitlyTypedAsAny: true, |
| 167 | + allowDirectConstAssertionInArrowFunctions: true, |
| 168 | + allowHigherOrderFunctions: false, |
| 169 | + allowTypedFunctionExpressions: false, |
| 170 | + }, |
| 171 | + ], |
| 172 | + ruleName: "@typescript-eslint/explicit-module-boundary-types", |
| 173 | + }, |
| 174 | + ], |
| 175 | + }); |
| 176 | + }); |
| 177 | +}); |
0 commit comments