Skip to content

Commit bba65d2

Browse files
2 parents 61bbffb + d435ae6 commit bba65d2

File tree

9 files changed

+120
-11
lines changed

9 files changed

+120
-11
lines changed

src/creation/writeConversionResults.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ describe("writeConversionResults", () => {
4646
sourceType: "module",
4747
},
4848
plugins: ["@typescript-eslint"],
49-
rules: {},
5049
}),
5150
);
5251
});
@@ -137,8 +136,6 @@ describe("writeConversionResults", () => {
137136
es6: true,
138137
node: true,
139138
},
140-
extends: [],
141-
rules: {},
142139
parser: "@typescript-eslint/parser",
143140
parserOptions: {
144141
project: "tsconfig.json",
@@ -182,7 +179,6 @@ describe("writeConversionResults", () => {
182179
sourceType: "module",
183180
},
184181
plugins: ["@typescript-eslint"],
185-
rules: {},
186182
}),
187183
);
188184
});
@@ -224,8 +220,6 @@ describe("writeConversionResults", () => {
224220
es6: true,
225221
node: true,
226222
},
227-
extends: [],
228-
rules: {},
229223
globals: {
230224
Promise: true,
231225
},

src/creation/writeConversionResults.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FileSystem } from "../adapters/fileSystem";
22
import { AllOriginalConfigurations } from "../input/findOriginalConfigurations";
3+
import { removeEmptyMembers } from "../utils";
34
import { createEnv } from "./eslint/createEnv";
45
import { formatConvertedRules } from "./formatConvertedRules";
56
import { formatOutput } from "./formatting/formatOutput";
@@ -22,11 +23,11 @@ export const writeConversionResults = async (
2223
plugins.push("@typescript-eslint/tslint");
2324
}
2425

25-
const output = {
26+
const output = removeEmptyMembers({
2627
...eslint?.full,
2728
env: createEnv(originalConfigurations),
2829
...(eslint && { globals: eslint.raw.globals }),
29-
...(summarizedResults.extends?.length !== 0 && { extends: summarizedResults.extends }),
30+
...(summarizedResults.extends && { extends: summarizedResults.extends }),
3031
parser: "@typescript-eslint/parser",
3132
parserOptions: {
3233
project: "tsconfig.json",
@@ -37,7 +38,7 @@ export const writeConversionResults = async (
3738
// ...trimESLintRules(eslint?.full.rules, summarizedResults.extensionRules),
3839
...formatConvertedRules(summarizedResults, tslint.full),
3940
},
40-
};
41+
});
4142

4243
return await dependencies.fileSystem.writeFile(outputPath, formatOutput(outputPath, output));
4344
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { RuleConverter } from "../../converter";
2+
3+
export const convertNoConflictingLifecycle: RuleConverter = () => {
4+
return {
5+
rules: [
6+
{
7+
ruleName: "@angular-eslint/no-conflicting-lifecycle",
8+
},
9+
],
10+
plugins: ["@angular-eslint/eslint-plugin"],
11+
};
12+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { RuleConverter } from "../../converter";
2+
3+
export const convertNoLifecycleCall: RuleConverter = () => {
4+
return {
5+
rules: [
6+
{
7+
ruleName: "@angular-eslint/no-lifecycle-call",
8+
},
9+
],
10+
plugins: ["@angular-eslint/eslint-plugin"],
11+
};
12+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { convertNoConflictingLifecycle } from "../no-conflicting-lifecycle";
2+
3+
describe(convertNoConflictingLifecycle, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertNoConflictingLifecycle({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleName: "@angular-eslint/no-conflicting-lifecycle",
13+
},
14+
],
15+
plugins: ["@angular-eslint/eslint-plugin"],
16+
});
17+
});
18+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { convertNoLifecycleCall } from "../no-lifecycle-call";
2+
3+
describe(convertNoLifecycleCall, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertNoLifecycleCall({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleName: "@angular-eslint/no-lifecycle-call",
13+
},
14+
],
15+
plugins: ["@angular-eslint/eslint-plugin"],
16+
});
17+
});
18+
});

src/rules/rulesConverters.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,14 @@ import { convertContextualLifecycle } from "./converters/codelyzer/contextual-li
145145
import { convertDirectiveClassSuffix } from "./converters/codelyzer/directive-class-suffix";
146146
import { convertDirectiveSelector } from "./converters/codelyzer/directive-selector";
147147
import { convertNoAttributeDecorator } from "./converters/codelyzer/no-attribute-decorator";
148-
import { convertUsePipeDecorator } from "./converters/codelyzer/use-pipe-decorator";
148+
import { convertNoConflictingLifecycle } from "./converters/codelyzer/no-conflicting-lifecycle";
149149
import { convertNoForwardRef } from "./converters/codelyzer/no-forward-ref";
150150
import { convertNoHostMetadataProperty } from "./converters/codelyzer/no-host-metadata-property";
151151
import { convertNoInputPrefix } from "./converters/codelyzer/no-input-prefix";
152152
import { convertNoInputRename } from "./converters/codelyzer/no-input-rename";
153153
import { convertNoInputsMetadataProperty } from "./converters/codelyzer/no-inputs-metadata-property";
154+
import { convertNoLifecycleCall } from "./converters/codelyzer/no-lifecycle-call";
155+
import { convertUsePipeDecorator } from "./converters/codelyzer/use-pipe-decorator";
154156

155157
/**
156158
* Keys TSLint rule names to their ESLint rule converters.
@@ -207,6 +209,7 @@ export const rulesConverters = new Map([
207209
["no-bitwise", convertNoBitwise],
208210
["no-boolean-literal-compare", convertNoBooleanLiteralCompare],
209211
["no-conditional-assignment", convertNoConditionalAssignment],
212+
["no-conflicting-lifecycle", convertNoConflictingLifecycle],
210213
["no-consecutive-blank-lines", convertNoConsecutiveBlankLines],
211214
["no-console", convertNoConsole],
212215
["no-constant-condition", convertNoConstantCondition],
@@ -237,6 +240,7 @@ export const rulesConverters = new Map([
237240
["no-invalid-template-strings", convertNoInvalidTemplateStrings],
238241
["no-invalid-this", convertNoInvalidThis],
239242
["no-irregular-whitespace", convertNoIrregularWhitespace],
243+
["no-lifecycle-call", convertNoLifecycleCall],
240244
["no-magic-numbers", convertNoMagicNumbers],
241245
["no-misused-new", convertNoMisusedNew],
242246
["no-multiline-string", convertNoMultilineString],

src/utils.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isDefined, isError, uniqueFromSources, separateErrors } from "./utils";
1+
import { isDefined, isError, uniqueFromSources, separateErrors, removeEmptyMembers } from "./utils";
22

33
describe("isDefined", () => {
44
it("returns true when the item is defined", () => {
@@ -48,6 +48,41 @@ describe("isError", () => {
4848
});
4949
});
5050

51+
describe("removeEmptyMembers", () => {
52+
it("remove an object member when it is empty", () => {
53+
// Arrange
54+
const items = { kept: { value: true }, removed: {} };
55+
56+
// Act
57+
const result = removeEmptyMembers(items);
58+
59+
// Assert
60+
expect(result).toEqual({ kept: { value: true } });
61+
});
62+
63+
it("removes an array member when it is empty", () => {
64+
// Arrange
65+
const items = { kept: [true], removed: [] };
66+
67+
// Act
68+
const result = removeEmptyMembers(items);
69+
70+
// Assert
71+
expect(result).toEqual({ kept: [true] });
72+
});
73+
74+
it("keeps a member when it isn't an array or object", () => {
75+
// Arrange
76+
const items = { kept: true };
77+
78+
// Act
79+
const result = removeEmptyMembers(items);
80+
81+
// Assert
82+
expect(result).toEqual({ kept: true });
83+
});
84+
});
85+
5186
describe("separateErrors", () => {
5287
it("splits the input array into errors and items", () => {
5388
// Arrange

src/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ export const isError = <Item>(item: Item | Error): item is Error => item instanc
44

55
export const isTruthy = <Item>(item: Item | false | undefined | null | 0): item is Item => !!item;
66

7+
export const removeEmptyMembers = <Item>(items: Item): Item => {
8+
const result: any = {};
9+
10+
for (const [key, value] of Object.entries(items)) {
11+
if (
12+
!(value instanceof Array && value.length === 0) &&
13+
!(value instanceof Object && Object.keys(value).length === 0)
14+
) {
15+
result[key] = value;
16+
}
17+
}
18+
19+
return result;
20+
};
21+
722
export const separateErrors = <Item>(mixed: (Error | Item)[]): [Error[], Item[]] => {
823
const errors: Error[] = [];
924
const items: Item[] = [];

0 commit comments

Comments
 (0)