@openrewrite/recipes-code-quality 0.1.0-20260409-154017
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/all-branches-identical.d.ts +10 -0
- package/dist/all-branches-identical.d.ts.map +1 -0
- package/dist/all-branches-identical.js +116 -0
- package/dist/all-branches-identical.js.map +1 -0
- package/dist/boolean-checks-not-inverted.d.ts +10 -0
- package/dist/boolean-checks-not-inverted.d.ts.map +1 -0
- package/dist/boolean-checks-not-inverted.js +117 -0
- package/dist/boolean-checks-not-inverted.js.map +1 -0
- package/dist/collapsible-if-statements.d.ts +10 -0
- package/dist/collapsible-if-statements.d.ts.map +1 -0
- package/dist/collapsible-if-statements.js +119 -0
- package/dist/collapsible-if-statements.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/merge-identical-branches.d.ts +10 -0
- package/dist/merge-identical-branches.d.ts.map +1 -0
- package/dist/merge-identical-branches.js +118 -0
- package/dist/merge-identical-branches.js.map +1 -0
- package/dist/remove-duplicate-conditions.d.ts +10 -0
- package/dist/remove-duplicate-conditions.d.ts.map +1 -0
- package/dist/remove-duplicate-conditions.js +141 -0
- package/dist/remove-duplicate-conditions.js.map +1 -0
- package/dist/remove-self-assignment.d.ts +10 -0
- package/dist/remove-self-assignment.d.ts.map +1 -0
- package/dist/remove-self-assignment.js +86 -0
- package/dist/remove-self-assignment.js.map +1 -0
- package/dist/remove-unconditional-value-overwrite.d.ts +10 -0
- package/dist/remove-unconditional-value-overwrite.d.ts.map +1 -0
- package/dist/remove-unconditional-value-overwrite.js +112 -0
- package/dist/remove-unconditional-value-overwrite.js.map +1 -0
- package/dist/simplify-boolean-literal.d.ts +9 -0
- package/dist/simplify-boolean-literal.d.ts.map +1 -0
- package/dist/simplify-boolean-literal.js +179 -0
- package/dist/simplify-boolean-literal.js.map +1 -0
- package/dist/simplify-redundant-logical-expression.d.ts +10 -0
- package/dist/simplify-redundant-logical-expression.d.ts.map +1 -0
- package/dist/simplify-redundant-logical-expression.js +63 -0
- package/dist/simplify-redundant-logical-expression.js.map +1 -0
- package/package.json +39 -0
- package/src/all-branches-identical.ts +133 -0
- package/src/boolean-checks-not-inverted.ts +144 -0
- package/src/collapsible-if-statements.ts +162 -0
- package/src/index.ts +34 -0
- package/src/merge-identical-branches.ts +149 -0
- package/src/remove-duplicate-conditions.ts +165 -0
- package/src/remove-self-assignment.ts +98 -0
- package/src/remove-unconditional-value-overwrite.ts +128 -0
- package/src/simplify-boolean-literal.ts +220 -0
- package/src/simplify-redundant-logical-expression.ts +75 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class AllBranchesIdentical extends Recipe {
|
|
3
|
+
name: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
description: string;
|
|
6
|
+
tags: string[];
|
|
7
|
+
estimatedEffortPerOccurrence: number;
|
|
8
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=all-branches-identical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"all-branches-identical.d.ts","sourceRoot":"","sources":["../src/all-branches-identical.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,gBAAgB,EAAW,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAepF,qBAAa,oBAAqB,SAAQ,MAAM;IAC5C,IAAI,SAA6D;IACjE,WAAW,SAAgD;IAC3D,WAAW,SAE4B;IACvC,IAAI,WAAmB;IACvB,4BAA4B,SAAK;IAE3B,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAoC9D"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AllBranchesIdentical = void 0;
|
|
13
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
14
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
15
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
16
|
+
class AllBranchesIdentical extends rewrite_1.Recipe {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.name = "org.openrewrite.javascript.cleanup.AllBranchesIdentical";
|
|
20
|
+
this.displayName = "Remove conditional with identical branches";
|
|
21
|
+
this.description = "Replace `if`/`else if`/`else` chains where every branch has " +
|
|
22
|
+
"the same body with just the body, since the condition has " +
|
|
23
|
+
"no effect on what code executes.";
|
|
24
|
+
this.tags = ["RSPEC-S3923"];
|
|
25
|
+
this.estimatedEffortPerOccurrence = 5;
|
|
26
|
+
}
|
|
27
|
+
editor() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
30
|
+
visitIf(ifStmt, ctx) {
|
|
31
|
+
const _super = Object.create(null, {
|
|
32
|
+
visitIf: { get: () => super.visitIf }
|
|
33
|
+
});
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
ifStmt = (yield _super.visitIf.call(this, ifStmt, ctx));
|
|
36
|
+
const parentCursor = this.cursor.parent;
|
|
37
|
+
if (parentCursor) {
|
|
38
|
+
const parentIf = parentCursor.firstEnclosing((n) => n.kind === java_1.J.Kind.If);
|
|
39
|
+
if (parentIf) {
|
|
40
|
+
return ifStmt;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!hasExplicitElse(ifStmt)) {
|
|
44
|
+
return ifStmt;
|
|
45
|
+
}
|
|
46
|
+
const bodies = collectBodies(ifStmt);
|
|
47
|
+
if (!(yield allBodiesEqual(bodies))) {
|
|
48
|
+
return ifStmt;
|
|
49
|
+
}
|
|
50
|
+
const thenBody = ifStmt.thenPart.element;
|
|
51
|
+
return Object.assign(Object.assign({}, thenBody), { prefix: ifStmt.prefix });
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.AllBranchesIdentical = AllBranchesIdentical;
|
|
59
|
+
function hasExplicitElse(ifStmt) {
|
|
60
|
+
let current = ifStmt;
|
|
61
|
+
while (true) {
|
|
62
|
+
const elsePart = current.elsePart;
|
|
63
|
+
if (!elsePart) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const body = elsePart.body.element;
|
|
67
|
+
if (body.kind === java_1.J.Kind.If) {
|
|
68
|
+
current = body;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function collectBodies(ifStmt) {
|
|
76
|
+
const bodies = [ifStmt.thenPart.element];
|
|
77
|
+
let current = ifStmt;
|
|
78
|
+
while (true) {
|
|
79
|
+
const elsePart = current.elsePart;
|
|
80
|
+
if (!elsePart) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
const body = elsePart.body.element;
|
|
84
|
+
if (body.kind === java_1.J.Kind.If) {
|
|
85
|
+
const elseIf = body;
|
|
86
|
+
bodies.push(elseIf.thenPart.element);
|
|
87
|
+
current = elseIf;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
bodies.push(body);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return bodies;
|
|
95
|
+
}
|
|
96
|
+
function printNode(node) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const p = (0, rewrite_1.printer)("org.openrewrite.javascript.tree.JS$CompilationUnit");
|
|
99
|
+
return (yield p.print(node)).trim();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function allBodiesEqual(bodies) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
if (bodies.length < 2) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const firstText = yield printNode(bodies[0]);
|
|
108
|
+
for (let i = 1; i < bodies.length; i++) {
|
|
109
|
+
if ((yield printNode(bodies[i])) !== firstText) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=all-branches-identical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"all-branches-identical.js","sourceRoot":"","sources":["../src/all-branches-identical.ts"],"names":[],"mappings":";;;;;;;;;;;;AAeA,kDAAoF;AACpF,gEAAkE;AAClE,oDAAuD;AAavD,MAAa,oBAAqB,SAAQ,gBAAM;IAAhD;;QACI,SAAI,GAAG,yDAAyD,CAAC;QACjE,gBAAW,GAAG,4CAA4C,CAAC;QAC3D,gBAAW,GAAG,8DAA8D;YACxE,4DAA4D;YAC5D,kCAAkC,CAAC;QACvC,SAAI,GAAG,CAAC,aAAa,CAAC,CAAC;QACvB,iCAA4B,GAAG,CAAC,CAAC;IAsCrC,CAAC;IApCS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBACzC,OAAO,C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C,CAAC,CAAC,CAAC;QAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,IAAI,CAAA,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAK,SAAS,EAAE,CAAC;gBAC3C,OAAO,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class BooleanChecksNotInverted extends Recipe {
|
|
3
|
+
name: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
description: string;
|
|
6
|
+
tags: string[];
|
|
7
|
+
estimatedEffortPerOccurrence: number;
|
|
8
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=boolean-checks-not-inverted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean-checks-not-inverted.d.ts","sourceRoot":"","sources":["../src/boolean-checks-not-inverted.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAc3E,qBAAa,wBAAyB,SAAQ,MAAM;IAChD,IAAI,SAAiE;IACrE,WAAW,SAA2C;IACtD,WAAW,SAEgD;IAC3D,IAAI,WAAmB;IACvB,4BAA4B,SAAK;IAE3B,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAyG9D"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BooleanChecksNotInverted = void 0;
|
|
13
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
14
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
15
|
+
class BooleanChecksNotInverted extends rewrite_1.Recipe {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.name = "org.openrewrite.javascript.cleanup.BooleanChecksNotInverted";
|
|
19
|
+
this.displayName = "Boolean checks should not be inverted";
|
|
20
|
+
this.description = "Replaces inverted boolean comparisons with their simpler equivalents. " +
|
|
21
|
+
"For example, `!(a === b)` becomes `a !== b` and `!(a < b)` becomes `a >= b`. " +
|
|
22
|
+
"Also simplifies double negation like `!(!x)` to `x`.";
|
|
23
|
+
this.tags = ["RSPEC-S1940"];
|
|
24
|
+
this.estimatedEffortPerOccurrence = 2;
|
|
25
|
+
}
|
|
26
|
+
editor() {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const a = () => (0, javascript_1.capture)();
|
|
29
|
+
const b = () => (0, javascript_1.capture)();
|
|
30
|
+
const notStrictEquals = (0, javascript_1.rewrite)(() => {
|
|
31
|
+
const [x, y] = [a(), b()];
|
|
32
|
+
return {
|
|
33
|
+
before: (0, javascript_1.pattern) `!(${x} === ${y})`,
|
|
34
|
+
after: (0, javascript_1.template) `${x} !== ${y}`
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
const notStrictNotEquals = (0, javascript_1.rewrite)(() => {
|
|
38
|
+
const [x, y] = [a(), b()];
|
|
39
|
+
return {
|
|
40
|
+
before: (0, javascript_1.pattern) `!(${x} !== ${y})`,
|
|
41
|
+
after: (0, javascript_1.template) `${x} === ${y}`
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
const notLooseEquals = (0, javascript_1.rewrite)(() => {
|
|
45
|
+
const [x, y] = [a(), b()];
|
|
46
|
+
return {
|
|
47
|
+
before: (0, javascript_1.pattern) `!(${x} == ${y})`,
|
|
48
|
+
after: (0, javascript_1.template) `${x} != ${y}`
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
const notLooseNotEquals = (0, javascript_1.rewrite)(() => {
|
|
52
|
+
const [x, y] = [a(), b()];
|
|
53
|
+
return {
|
|
54
|
+
before: (0, javascript_1.pattern) `!(${x} != ${y})`,
|
|
55
|
+
after: (0, javascript_1.template) `${x} == ${y}`
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
const notLessThan = (0, javascript_1.rewrite)(() => {
|
|
59
|
+
const [x, y] = [a(), b()];
|
|
60
|
+
return {
|
|
61
|
+
before: (0, javascript_1.pattern) `!(${x} < ${y})`,
|
|
62
|
+
after: (0, javascript_1.template) `${x} >= ${y}`
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
const notGreaterThan = (0, javascript_1.rewrite)(() => {
|
|
66
|
+
const [x, y] = [a(), b()];
|
|
67
|
+
return {
|
|
68
|
+
before: (0, javascript_1.pattern) `!(${x} > ${y})`,
|
|
69
|
+
after: (0, javascript_1.template) `${x} <= ${y}`
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
const notLessOrEqual = (0, javascript_1.rewrite)(() => {
|
|
73
|
+
const [x, y] = [a(), b()];
|
|
74
|
+
return {
|
|
75
|
+
before: (0, javascript_1.pattern) `!(${x} <= ${y})`,
|
|
76
|
+
after: (0, javascript_1.template) `${x} > ${y}`
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
const notGreaterOrEqual = (0, javascript_1.rewrite)(() => {
|
|
80
|
+
const [x, y] = [a(), b()];
|
|
81
|
+
return {
|
|
82
|
+
before: (0, javascript_1.pattern) `!(${x} >= ${y})`,
|
|
83
|
+
after: (0, javascript_1.template) `${x} < ${y}`
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
const doubleNegation = (0, javascript_1.rewrite)(() => {
|
|
87
|
+
const x = (0, javascript_1.capture)();
|
|
88
|
+
return {
|
|
89
|
+
before: (0, javascript_1.pattern) `!(!${x})`,
|
|
90
|
+
after: (0, javascript_1.template) `${x}`
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
const rules = notStrictEquals
|
|
94
|
+
.orElse(notStrictNotEquals)
|
|
95
|
+
.orElse(notLooseEquals)
|
|
96
|
+
.orElse(notLooseNotEquals)
|
|
97
|
+
.orElse(notLessThan)
|
|
98
|
+
.orElse(notGreaterThan)
|
|
99
|
+
.orElse(notLessOrEqual)
|
|
100
|
+
.orElse(notGreaterOrEqual)
|
|
101
|
+
.orElse(doubleNegation);
|
|
102
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
103
|
+
visitUnary(unary, ctx) {
|
|
104
|
+
const _super = Object.create(null, {
|
|
105
|
+
visitUnary: { get: () => super.visitUnary }
|
|
106
|
+
});
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
unary = (yield _super.visitUnary.call(this, unary, ctx));
|
|
109
|
+
return (yield rules.tryOn(this.cursor, unary)) || unary;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.BooleanChecksNotInverted = BooleanChecksNotInverted;
|
|
117
|
+
//# sourceMappingURL=boolean-checks-not-inverted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean-checks-not-inverted.js","sourceRoot":"","sources":["../src/boolean-chec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M,CAAC,cAAc,CAAC;iBACtB,MAAM,CAAC,iBAAiB,CAAC;iBACzB,MAAM,CAAC,cAAc,CAAC,CAAC;YAE5B,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBACzC,UAAU,CACrB,KAAc,EACd,GAAqB;;;;;wBAErB,KAAK,IAAG,MAAM,OAAM,UAAU,YAAC,KAAK,EAAE,GAAG,CAAY,CAAA,CAAC;wBACtD,OAAO,CAAA,MAAM,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,KAAI,KAAK,CAAC;oBAC1D,CAAC;iBAAA;aACJ,CAAC;QACN,CAAC;KAAA;CACJ;AAlHD,4DAkHC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class CollapsibleIfStatements extends Recipe {
|
|
3
|
+
name: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
description: string;
|
|
6
|
+
tags: string[];
|
|
7
|
+
estimatedEffortPerOccurrence: number;
|
|
8
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=collapsible-if-statements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collapsible-if-statements.d.ts","sourceRoot":"","sources":["../src/collapsible-if-statements.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAc3E,qBAAa,uBAAwB,SAAQ,MAAM;IAC/C,IAAI,SAAgE;IACpE,WAAW,SAAgD;IAC3D,WAAW,SAGc;IACzB,IAAI,WAAmB;IACvB,4BAA4B,SAAK;IAE3B,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAkF9D"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CollapsibleIfStatements = void 0;
|
|
13
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
14
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
15
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
16
|
+
class CollapsibleIfStatements extends rewrite_1.Recipe {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.name = "org.openrewrite.javascript.cleanup.CollapsibleIfStatements";
|
|
20
|
+
this.displayName = "Collapsible if statements should be merged";
|
|
21
|
+
this.description = "Merges nested if statements that can be combined with `&&`. " +
|
|
22
|
+
"For example, `if (a) { if (b) { ... } }` becomes `if (a && b) { ... }`. " +
|
|
23
|
+
"Only applies when neither if has an else clause and the outer body contains " +
|
|
24
|
+
"only the inner if.";
|
|
25
|
+
this.tags = ["RSPEC-S1066"];
|
|
26
|
+
this.estimatedEffortPerOccurrence = 5;
|
|
27
|
+
}
|
|
28
|
+
editor() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
31
|
+
visitIf(ifStmt, ctx) {
|
|
32
|
+
const _super = Object.create(null, {
|
|
33
|
+
visitIf: { get: () => super.visitIf }
|
|
34
|
+
});
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
ifStmt = (yield _super.visitIf.call(this, ifStmt, ctx));
|
|
37
|
+
if (ifStmt.elsePart) {
|
|
38
|
+
return ifStmt;
|
|
39
|
+
}
|
|
40
|
+
const body = ifStmt.thenPart.element;
|
|
41
|
+
if (body.kind !== java_1.J.Kind.Block) {
|
|
42
|
+
return ifStmt;
|
|
43
|
+
}
|
|
44
|
+
const block = body;
|
|
45
|
+
if (block.statements.length !== 1) {
|
|
46
|
+
return ifStmt;
|
|
47
|
+
}
|
|
48
|
+
const inner = block.statements[0].element;
|
|
49
|
+
if (inner.kind !== java_1.J.Kind.If) {
|
|
50
|
+
return ifStmt;
|
|
51
|
+
}
|
|
52
|
+
const innerIf = inner;
|
|
53
|
+
if (innerIf.elsePart) {
|
|
54
|
+
return ifStmt;
|
|
55
|
+
}
|
|
56
|
+
const outerCond = Object.assign(Object.assign({}, ifStmt.ifCondition.tree.element), { prefix: java_1.emptySpace });
|
|
57
|
+
const innerCond = Object.assign(Object.assign({}, innerIf.ifCondition.tree.element), { prefix: java_1.emptySpace });
|
|
58
|
+
const needsParens = innerCond.kind === java_1.J.Kind.Binary &&
|
|
59
|
+
innerCond.operator.element === "Or";
|
|
60
|
+
let combined;
|
|
61
|
+
if (needsParens) {
|
|
62
|
+
combined = yield (0, javascript_1.template) `${outerCond} && (${innerCond})`.apply(ifStmt.ifCondition.tree.element, this.cursor);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
combined = yield (0, javascript_1.template) `${outerCond} && ${innerCond}`.apply(ifStmt.ifCondition.tree.element, this.cursor);
|
|
66
|
+
}
|
|
67
|
+
if (!combined) {
|
|
68
|
+
return ifStmt;
|
|
69
|
+
}
|
|
70
|
+
if (combined.kind === javascript_1.JS.Kind.ExpressionStatement) {
|
|
71
|
+
combined = combined.expression;
|
|
72
|
+
}
|
|
73
|
+
combined = stripLeadingNewline(combined);
|
|
74
|
+
const innerBody = innerIf.thenPart.element;
|
|
75
|
+
const outerIndent = getIndent(ifStmt.prefix);
|
|
76
|
+
const dedented = dedentBlock(innerBody, outerIndent);
|
|
77
|
+
return yield this.produceJava(ifStmt, ctx, draft => {
|
|
78
|
+
draft.ifCondition.tree.element = combined;
|
|
79
|
+
draft.thenPart.element = dedented;
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.CollapsibleIfStatements = CollapsibleIfStatements;
|
|
88
|
+
function stripLeadingNewline(node) {
|
|
89
|
+
if (node.prefix.whitespace.includes('\n')) {
|
|
90
|
+
return Object.assign(Object.assign({}, node), { prefix: java_1.emptySpace });
|
|
91
|
+
}
|
|
92
|
+
if (node.kind === java_1.J.Kind.Binary) {
|
|
93
|
+
const bin = node;
|
|
94
|
+
const newLeft = stripLeadingNewline(bin.left);
|
|
95
|
+
if (newLeft !== bin.left) {
|
|
96
|
+
return Object.assign(Object.assign({}, bin), { left: newLeft });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return node;
|
|
100
|
+
}
|
|
101
|
+
function getIndent(sp) {
|
|
102
|
+
const ws = sp.whitespace;
|
|
103
|
+
const lastNewline = ws.lastIndexOf('\n');
|
|
104
|
+
if (lastNewline === -1) {
|
|
105
|
+
return "";
|
|
106
|
+
}
|
|
107
|
+
return ws.substring(lastNewline + 1);
|
|
108
|
+
}
|
|
109
|
+
function dedentBlock(block, outerIndent) {
|
|
110
|
+
const bodyIndent = outerIndent + " ";
|
|
111
|
+
const newStmts = block.statements.map(stmt => {
|
|
112
|
+
const el = stmt.element;
|
|
113
|
+
const newPrefix = Object.assign(Object.assign({}, el.prefix), { whitespace: "\n" + bodyIndent });
|
|
114
|
+
return Object.assign(Object.assign({}, stmt), { element: Object.assign(Object.assign({}, el), { prefix: newPrefix }) });
|
|
115
|
+
});
|
|
116
|
+
const newEnd = Object.assign(Object.assign({}, block.end), { whitespace: "\n" + outerIndent });
|
|
117
|
+
return Object.assign(Object.assign({}, block), { statements: newStmts, end: newEnd });
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=collapsible-if-statements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collapsible-if-statements.js","sourceRoot":"","sources":["../src/collapsible-if-statements.ts"],"names":[],"mappings":";;;;;;;;;;;;AAeA,kDAA2E;AAC3E,gEAAgF;AAChF,oDAAoE;AAYpE,MAAa,uBAAwB,SAAQ,gBAAM;IAAnD;;QACI,SAAI,GAAG,4DAA4D,CAAC;QACpE,gBAAW,GAAG,4CAA4C,CAAC;QAC3D,gBAAW,GAAG,8DAA8D;YACxE,0EAA0E;YAC1E,8EAA8E;YAC9E,oBAAoB,CAAC;QACzB,SAAI,GAAG,CAAC,aAAa,CAAC,CAAC;QACvB,iCAA4B,GAAG,CAAC,CAAC;IAoFrC,CAAC;IAlFS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBACzC,OAAO,CAClB,MAAY,EACZ,GAAqB;;;;;wBAErB,MAAM,IAAG,MAAM,OAAM,OAAO,YAAC,MAAM,EAAE,GAAG,CAAS,CAAA,CAAC;wBAGlD,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;4BAClB,OAAO,MAAM,CAAC;wBAClB,CAAC;wBAGD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;wBACrC,IAAI,IAAI,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;4BAC7B,OAAO,MAAM,CAAC;wBAClB,CAAC;wBAED,MAAM,KAAK,GAAG,IAAe,CAAC;wBAC9B,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;4BAChC,OAAO,MAAM,CAAC;wBAClB,CAAC;wBAGD,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,C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AAU,CAAC;IACzB,MAAM,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACd,CAAC;IACD,OAAO,EAAE,CAAC,SAAS,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,WAAmB;IACpD,MAAM,UAAU,GAAG,WAAW,GAAG,MAAM,CAAC;IAExC,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACzC,MAAM,EAAE,GAAG,IAAI,CAAC,OAAY,CAAC;QAC7B,MAAM,SAAS,mCAAO,EAAE,CAAC,MAAM,KAAE,UAAU,EAAE,IAAI,GAAG,UAAU,GAAC,CAAC;QAChE,uCAAW,IAAI,KAAE,OAAO,kCAAM,EAAE,KAAE,MAAM,EAAE,SAAS,OAAG;IAC1D,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,mCAAO,KAAK,CAAC,GAAG,KAAE,UAAU,EAAE,IAAI,GAAG,WAAW,GAAC,CAAC;IAE9D,OAAO,gCAAI,KAAK,KAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAY,CAAC;AACpE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CategoryDescriptor, RecipeMarketplace } from "@openrewrite/rewrite";
|
|
2
|
+
export declare const CodeQuality: CategoryDescriptor[];
|
|
3
|
+
export declare function activate(marketplace: RecipeMarketplace): Promise<void>;
|
|
4
|
+
export { AllBranchesIdentical } from "./all-branches-identical";
|
|
5
|
+
export { SimplifyBooleanLiteral } from "./simplify-boolean-literal";
|
|
6
|
+
export { BooleanChecksNotInverted } from "./boolean-checks-not-inverted";
|
|
7
|
+
export { CollapsibleIfStatements } from "./collapsible-if-statements";
|
|
8
|
+
export { MergeIdenticalBranches } from "./merge-identical-branches";
|
|
9
|
+
export { RemoveDuplicateConditions } from "./remove-duplicate-conditions";
|
|
10
|
+
export { RemoveSelfAssignment } from "./remove-self-assignment";
|
|
11
|
+
export { RemoveUnconditionalValueOverwrite } from "./remove-unconditional-value-overwrite";
|
|
12
|
+
export { SimplifyRedundantLogicalExpression } from "./simplify-redundant-logical-expression";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAW3E,eAAO,MAAM,WAAW,EAAE,kBAAkB,EAAoC,CAAC;AAEjF,wBAAsB,QAAQ,CAAC,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAU5E;AAED,OAAO,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAC,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAC,wBAAwB,EAAC,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAC,uBAAuB,EAAC,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAC,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAC,yBAAyB,EAAC,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAC,iCAAiC,EAAC,MAAM,wCAAwC,CAAC;AACzF,OAAO,EAAC,kCAAkC,EAAC,MAAM,yCAAyC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SimplifyRedundantLogicalExpression = exports.RemoveUnconditionalValueOverwrite = exports.RemoveSelfAssignment = exports.RemoveDuplicateConditions = exports.MergeIdenticalBranches = exports.CollapsibleIfStatements = exports.BooleanChecksNotInverted = exports.SimplifyBooleanLiteral = exports.AllBranchesIdentical = exports.CodeQuality = void 0;
|
|
13
|
+
exports.activate = activate;
|
|
14
|
+
const all_branches_identical_1 = require("./all-branches-identical");
|
|
15
|
+
const simplify_boolean_literal_1 = require("./simplify-boolean-literal");
|
|
16
|
+
const boolean_checks_not_inverted_1 = require("./boolean-checks-not-inverted");
|
|
17
|
+
const collapsible_if_statements_1 = require("./collapsible-if-statements");
|
|
18
|
+
const merge_identical_branches_1 = require("./merge-identical-branches");
|
|
19
|
+
const remove_duplicate_conditions_1 = require("./remove-duplicate-conditions");
|
|
20
|
+
const remove_self_assignment_1 = require("./remove-self-assignment");
|
|
21
|
+
const remove_unconditional_value_overwrite_1 = require("./remove-unconditional-value-overwrite");
|
|
22
|
+
const simplify_redundant_logical_expression_1 = require("./simplify-redundant-logical-expression");
|
|
23
|
+
exports.CodeQuality = [{ displayName: "Code quality" }];
|
|
24
|
+
function activate(marketplace) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
yield marketplace.install(all_branches_identical_1.AllBranchesIdentical, exports.CodeQuality);
|
|
27
|
+
yield marketplace.install(simplify_boolean_literal_1.SimplifyBooleanLiteral, exports.CodeQuality);
|
|
28
|
+
yield marketplace.install(boolean_checks_not_inverted_1.BooleanChecksNotInverted, exports.CodeQuality);
|
|
29
|
+
yield marketplace.install(collapsible_if_statements_1.CollapsibleIfStatements, exports.CodeQuality);
|
|
30
|
+
yield marketplace.install(merge_identical_branches_1.MergeIdenticalBranches, exports.CodeQuality);
|
|
31
|
+
yield marketplace.install(remove_duplicate_conditions_1.RemoveDuplicateConditions, exports.CodeQuality);
|
|
32
|
+
yield marketplace.install(remove_self_assignment_1.RemoveSelfAssignment, exports.CodeQuality);
|
|
33
|
+
yield marketplace.install(remove_unconditional_value_overwrite_1.RemoveUnconditionalValueOverwrite, exports.CodeQuality);
|
|
34
|
+
yield marketplace.install(simplify_redundant_logical_expression_1.SimplifyRedundantLogicalExpression, exports.CodeQuality);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
var all_branches_identical_2 = require("./all-branches-identical");
|
|
38
|
+
Object.defineProperty(exports, "AllBranchesIdentical", { enumerable: true, get: function () { return all_branches_identical_2.AllBranchesIdentical; } });
|
|
39
|
+
var simplify_boolean_literal_2 = require("./simplify-boolean-literal");
|
|
40
|
+
Object.defineProperty(exports, "SimplifyBooleanLiteral", { enumerable: true, get: function () { return simplify_boolean_literal_2.SimplifyBooleanLiteral; } });
|
|
41
|
+
var boolean_checks_not_inverted_2 = require("./boolean-checks-not-inverted");
|
|
42
|
+
Object.defineProperty(exports, "BooleanChecksNotInverted", { enumerable: true, get: function () { return boolean_checks_not_inverted_2.BooleanChecksNotInverted; } });
|
|
43
|
+
var collapsible_if_statements_2 = require("./collapsible-if-statements");
|
|
44
|
+
Object.defineProperty(exports, "CollapsibleIfStatements", { enumerable: true, get: function () { return collapsible_if_statements_2.CollapsibleIfStatements; } });
|
|
45
|
+
var merge_identical_branches_2 = require("./merge-identical-branches");
|
|
46
|
+
Object.defineProperty(exports, "MergeIdenticalBranches", { enumerable: true, get: function () { return merge_identical_branches_2.MergeIdenticalBranches; } });
|
|
47
|
+
var remove_duplicate_conditions_2 = require("./remove-duplicate-conditions");
|
|
48
|
+
Object.defineProperty(exports, "RemoveDuplicateConditions", { enumerable: true, get: function () { return remove_duplicate_conditions_2.RemoveDuplicateConditions; } });
|
|
49
|
+
var remove_self_assignment_2 = require("./remove-self-assignment");
|
|
50
|
+
Object.defineProperty(exports, "RemoveSelfAssignment", { enumerable: true, get: function () { return remove_self_assignment_2.RemoveSelfAssignment; } });
|
|
51
|
+
var remove_unconditional_value_overwrite_2 = require("./remove-unconditional-value-overwrite");
|
|
52
|
+
Object.defineProperty(exports, "RemoveUnconditionalValueOverwrite", { enumerable: true, get: function () { return remove_unconditional_value_overwrite_2.RemoveUnconditionalValueOverwrite; } });
|
|
53
|
+
var simplify_redundant_logical_expression_2 = require("./simplify-redundant-logical-expression");
|
|
54
|
+
Object.defineProperty(exports, "SimplifyRedundantLogicalExpression", { enumerable: true, get: function () { return simplify_redundant_logical_expression_2.SimplifyRedundantLogicalExpression; } });
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAaA,4BAUC;AAtBD,qEAA8D;AAC9D,yEAAkE;AAClE,+EAAuE;AACvE,2EAAoE;AACpE,yEAAkE;AAClE,+EAAwE;AACxE,qEAA8D;AAC9D,iGAAyF;AACzF,mGAA2F;AAE9E,QAAA,WAAW,GAAyB,CAAC,EAAC,WAAW,EAAE,cAAc,EAAC,CAAC,CAAC;AAEjF,SAAsB,QAAQ,CAAC,WAA8B;;QACzD,MAAM,WAAW,CAAC,OAAO,CAAC,6CAAoB,EAAE,mBAAW,CAAC,CAAC;QAC7D,MAAM,WAAW,CAAC,OAAO,CAAC,iDAAsB,EAAE,mBAAW,CAAC,CAAC;QAC/D,MAAM,WAAW,CAAC,OAAO,CAAC,sDAAwB,EAAE,mBAAW,CAAC,CAAC;QACjE,MAAM,WAAW,CAAC,OAAO,CAAC,mDAAuB,EAAE,mBAAW,CAAC,CAAC;QAChE,MAAM,WAAW,CAAC,OAAO,CAAC,iDAAsB,EAAE,mBAAW,CAAC,CAAC;QAC/D,MAAM,WAAW,CAAC,OAAO,CAAC,uDAAyB,EAAE,mBAAW,CAAC,CAAC;QAClE,MAAM,WAAW,CAAC,OAAO,CAAC,6CAAoB,EAAE,mBAAW,CAAC,CAAC;QAC7D,MAAM,WAAW,CAAC,OAAO,CAAC,wEAAiC,EAAE,mBAAW,CAAC,CAAC;QAC1E,MAAM,WAAW,CAAC,OAAO,CAAC,0EAAkC,EAAE,mBAAW,CAAC,CAAC;IAC/E,CAAC;CAAA;AAED,mEAA8D;AAAtD,8HAAA,oBAAoB,OAAA;AAC5B,uEAAkE;AAA1D,kIAAA,sBAAsB,OAAA;AAC9B,6EAAuE;AAA/D,uIAAA,wBAAwB,OAAA;AAChC,yEAAoE;AAA5D,oIAAA,uBAAuB,OAAA;AAC/B,uEAAkE;AAA1D,kIAAA,sBAAsB,OAAA;AAC9B,6EAAwE;AAAhE,wIAAA,yBAAyB,OAAA;AACjC,mEAA8D;AAAtD,8HAAA,oBAAoB,OAAA;AAC5B,+FAAyF;AAAjF,yJAAA,iCAAiC,OAAA;AACzC,iGAA2F;AAAnF,2JAAA,kCAAkC,OAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class MergeIdenticalBranches extends Recipe {
|
|
3
|
+
name: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
description: string;
|
|
6
|
+
tags: string[];
|
|
7
|
+
estimatedEffortPerOccurrence: number;
|
|
8
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=merge-identical-branches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-identical-branches.d.ts","sourceRoot":"","sources":["../src/merge-identical-branches.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,gBAAgB,EAAW,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAYpF,qBAAa,sBAAuB,SAAQ,MAAM;IAC9C,IAAI,SAA+D;IACnE,WAAW,SAAsD;IACjE,WAAW,SACgD;IAC3D,IAAI,WAAmB;IACvB,4BAA4B,SAAM;IAE5B,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA0F9D"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MergeIdenticalBranches = void 0;
|
|
13
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
14
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
15
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
16
|
+
class MergeIdenticalBranches extends rewrite_1.Recipe {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.name = "org.openrewrite.javascript.cleanup.MergeIdenticalBranches";
|
|
20
|
+
this.displayName = "Merge consecutive branches with identical bodies";
|
|
21
|
+
this.description = "Combine consecutive `if`/`else if` branches that have the same body " +
|
|
22
|
+
"into a single branch with conditions joined by `||`.";
|
|
23
|
+
this.tags = ["RSPEC-S1871"];
|
|
24
|
+
this.estimatedEffortPerOccurrence = 10;
|
|
25
|
+
}
|
|
26
|
+
editor() {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
29
|
+
visitIf(ifStmt, ctx) {
|
|
30
|
+
const _super = Object.create(null, {
|
|
31
|
+
visitIf: { get: () => super.visitIf }
|
|
32
|
+
});
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
ifStmt = (yield _super.visitIf.call(this, ifStmt, ctx));
|
|
35
|
+
const parentCursor = this.cursor.parent;
|
|
36
|
+
if (parentCursor) {
|
|
37
|
+
const parentIf = parentCursor.firstEnclosing((n) => n.kind === java_1.J.Kind.If);
|
|
38
|
+
if (parentIf) {
|
|
39
|
+
return ifStmt;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!ifStmt.elsePart) {
|
|
43
|
+
return ifStmt;
|
|
44
|
+
}
|
|
45
|
+
const elseBody = ifStmt.elsePart.body.element;
|
|
46
|
+
if (elseBody.kind !== java_1.J.Kind.If) {
|
|
47
|
+
return ifStmt;
|
|
48
|
+
}
|
|
49
|
+
const elseIf = elseBody;
|
|
50
|
+
const ifBody = ifStmt.thenPart.element;
|
|
51
|
+
const elseIfBody = elseIf.thenPart.element;
|
|
52
|
+
if (!(yield bodiesEqual(ifBody, elseIfBody))) {
|
|
53
|
+
return ifStmt;
|
|
54
|
+
}
|
|
55
|
+
const ifCond = ifStmt.ifCondition.tree.element;
|
|
56
|
+
const elseIfCond = elseIf.ifCondition.tree.element;
|
|
57
|
+
const leftNeedsParens = ifCond.kind === java_1.J.Kind.Binary &&
|
|
58
|
+
ifCond.operator.element === "And";
|
|
59
|
+
const rightNeedsParens = elseIfCond.kind === java_1.J.Kind.Binary &&
|
|
60
|
+
elseIfCond.operator.element === "And";
|
|
61
|
+
const cleanLeft = Object.assign(Object.assign({}, ifCond), { prefix: java_1.emptySpace });
|
|
62
|
+
const cleanRight = Object.assign(Object.assign({}, elseIfCond), { prefix: java_1.emptySpace });
|
|
63
|
+
let combined;
|
|
64
|
+
if (leftNeedsParens && rightNeedsParens) {
|
|
65
|
+
combined = yield (0, javascript_1.template) `(${cleanLeft}) || (${cleanRight})`.apply(ifStmt.ifCondition.tree.element, this.cursor);
|
|
66
|
+
}
|
|
67
|
+
else if (leftNeedsParens) {
|
|
68
|
+
combined = yield (0, javascript_1.template) `(${cleanLeft}) || ${cleanRight}`.apply(ifStmt.ifCondition.tree.element, this.cursor);
|
|
69
|
+
}
|
|
70
|
+
else if (rightNeedsParens) {
|
|
71
|
+
combined = yield (0, javascript_1.template) `${cleanLeft} || (${cleanRight})`.apply(ifStmt.ifCondition.tree.element, this.cursor);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
combined = yield (0, javascript_1.template) `${cleanLeft} || ${cleanRight}`.apply(ifStmt.ifCondition.tree.element, this.cursor);
|
|
75
|
+
}
|
|
76
|
+
if (!combined) {
|
|
77
|
+
return ifStmt;
|
|
78
|
+
}
|
|
79
|
+
if (combined.kind === javascript_1.JS.Kind.ExpressionStatement) {
|
|
80
|
+
combined = combined.expression;
|
|
81
|
+
}
|
|
82
|
+
combined = stripLeadingNewline(combined);
|
|
83
|
+
return yield this.produceJava(ifStmt, ctx, draft => {
|
|
84
|
+
draft.ifCondition.tree.element = combined;
|
|
85
|
+
draft.elsePart = elseIf.elsePart;
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.MergeIdenticalBranches = MergeIdenticalBranches;
|
|
94
|
+
function printNode(node) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const p = (0, rewrite_1.printer)("org.openrewrite.javascript.tree.JS$CompilationUnit");
|
|
97
|
+
return (yield p.print(node)).trim();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function bodiesEqual(a, b) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
return (yield printNode(a)) === (yield printNode(b));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function stripLeadingNewline(node) {
|
|
106
|
+
if (node.prefix.whitespace.includes('\n')) {
|
|
107
|
+
return Object.assign(Object.assign({}, node), { prefix: java_1.emptySpace });
|
|
108
|
+
}
|
|
109
|
+
if (node.kind === java_1.J.Kind.Binary) {
|
|
110
|
+
const bin = node;
|
|
111
|
+
const newLeft = stripLeadingNewline(bin.left);
|
|
112
|
+
if (newLeft !== bin.left) {
|
|
113
|
+
return Object.assign(Object.assign({}, bin), { left: newLeft });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return node;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=merge-identical-branches.js.map
|