@openrewrite/rewrite 8.69.0-20251207-141831 → 8.69.0-20251207-160255
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/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/javascript/cleanup/add-parse-int-radix.d.ts +22 -0
- package/dist/javascript/cleanup/add-parse-int-radix.d.ts.map +1 -0
- package/dist/javascript/cleanup/add-parse-int-radix.js +104 -0
- package/dist/javascript/cleanup/add-parse-int-radix.js.map +1 -0
- package/dist/javascript/cleanup/index.d.ts +1 -0
- package/dist/javascript/cleanup/index.d.ts.map +1 -1
- package/dist/javascript/cleanup/index.js +3 -1
- package/dist/javascript/cleanup/index.js.map +1 -1
- package/dist/version.txt +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/javascript/cleanup/add-parse-int-radix.ts +103 -0
- package/src/javascript/cleanup/index.ts +1 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AAGtB,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AAGtB,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBtE"}
|
package/dist/index.js
CHANGED
|
@@ -62,7 +62,7 @@ function activate(registry) {
|
|
|
62
62
|
const { OrderImports } = yield import("./recipe/index.js");
|
|
63
63
|
const { ModernizeOctalEscapeSequences, ModernizeOctalLiterals, RemoveDuplicateObjectKeys } = yield import("./javascript/migrate/es6/index.js");
|
|
64
64
|
const { ExportAssignmentToExportDefault } = yield import("./javascript/migrate/typescript/index.js");
|
|
65
|
-
const { UseObjectPropertyShorthand, PreferOptionalChain } = yield import("./javascript/cleanup/index.js");
|
|
65
|
+
const { UseObjectPropertyShorthand, PreferOptionalChain, AddParseIntRadix } = yield import("./javascript/cleanup/index.js");
|
|
66
66
|
const { UpgradeDependencyVersion } = yield import("./javascript/recipes/index.js");
|
|
67
67
|
const { FindDependency } = yield import("./javascript/search/index.js");
|
|
68
68
|
registry.register(ExportAssignmentToExportDefault);
|
|
@@ -73,6 +73,7 @@ function activate(registry) {
|
|
|
73
73
|
registry.register(RemoveDuplicateObjectKeys);
|
|
74
74
|
registry.register(UseObjectPropertyShorthand);
|
|
75
75
|
registry.register(PreferOptionalChain);
|
|
76
|
+
registry.register(AddParseIntRadix);
|
|
76
77
|
registry.register(UpgradeDependencyVersion);
|
|
77
78
|
});
|
|
78
79
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Recipe } from "../../recipe";
|
|
2
|
+
import { TreeVisitor } from "../../visitor";
|
|
3
|
+
import { ExecutionContext } from "../../execution";
|
|
4
|
+
/**
|
|
5
|
+
* Adds the radix parameter to parseInt() calls when missing.
|
|
6
|
+
*
|
|
7
|
+
* The radix parameter specifies the base of the numeral system to use.
|
|
8
|
+
* Without it, parseInt can produce unexpected results:
|
|
9
|
+
* - parseInt("08") was 0 in older JavaScript (octal interpretation)
|
|
10
|
+
* - Modern JavaScript defaults to base 10, but explicit radix is clearer
|
|
11
|
+
*
|
|
12
|
+
* Examples:
|
|
13
|
+
* - `parseInt(x)` becomes `parseInt(x, 10)`
|
|
14
|
+
* - `parseInt(str)` becomes `parseInt(str, 10)`
|
|
15
|
+
*/
|
|
16
|
+
export declare class AddParseIntRadix extends Recipe {
|
|
17
|
+
name: string;
|
|
18
|
+
displayName: string;
|
|
19
|
+
description: string;
|
|
20
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=add-parse-int-radix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-parse-int-radix.d.ts","sourceRoot":"","sources":["../../../src/javascript/cleanup/add-parse-int-radix.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAMjD;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAiB,SAAQ,MAAM;IACxC,IAAI,SAA4D;IAChE,WAAW,SAA6B;IACxC,WAAW,SAAwH;IAE7H,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA6D9D"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2025 the original author or authors.
|
|
4
|
+
* <p>
|
|
5
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
* <p>
|
|
9
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
10
|
+
* <p>
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.AddParseIntRadix = void 0;
|
|
28
|
+
const recipe_1 = require("../../recipe");
|
|
29
|
+
const visitor_1 = require("../visitor");
|
|
30
|
+
const java_1 = require("../../java");
|
|
31
|
+
const markers_1 = require("../../markers");
|
|
32
|
+
const uuid_1 = require("../../uuid");
|
|
33
|
+
/**
|
|
34
|
+
* Adds the radix parameter to parseInt() calls when missing.
|
|
35
|
+
*
|
|
36
|
+
* The radix parameter specifies the base of the numeral system to use.
|
|
37
|
+
* Without it, parseInt can produce unexpected results:
|
|
38
|
+
* - parseInt("08") was 0 in older JavaScript (octal interpretation)
|
|
39
|
+
* - Modern JavaScript defaults to base 10, but explicit radix is clearer
|
|
40
|
+
*
|
|
41
|
+
* Examples:
|
|
42
|
+
* - `parseInt(x)` becomes `parseInt(x, 10)`
|
|
43
|
+
* - `parseInt(str)` becomes `parseInt(str, 10)`
|
|
44
|
+
*/
|
|
45
|
+
class AddParseIntRadix extends recipe_1.Recipe {
|
|
46
|
+
constructor() {
|
|
47
|
+
super(...arguments);
|
|
48
|
+
this.name = "org.openrewrite.javascript.cleanup.add-parse-int-radix";
|
|
49
|
+
this.displayName = "Add radix to `parseInt`";
|
|
50
|
+
this.description = "Adds the radix parameter (base 10) to `parseInt()` calls that are missing it, preventing potential parsing issues.";
|
|
51
|
+
}
|
|
52
|
+
editor() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
return new class extends visitor_1.JavaScriptVisitor {
|
|
55
|
+
visitMethodInvocation(method, ctx) {
|
|
56
|
+
const _super = Object.create(null, {
|
|
57
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
58
|
+
});
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const visited = yield _super.visitMethodInvocation.call(this, method, ctx);
|
|
61
|
+
// Check if this is a call to parseInt
|
|
62
|
+
if (visited.select) {
|
|
63
|
+
// This is a method call on an object (e.g., obj.parseInt())
|
|
64
|
+
// parseInt is typically called as a global function, not a method
|
|
65
|
+
return visited;
|
|
66
|
+
}
|
|
67
|
+
// Check the method name
|
|
68
|
+
if (visited.name.simpleName !== 'parseInt') {
|
|
69
|
+
return visited;
|
|
70
|
+
}
|
|
71
|
+
// Check if there's exactly one argument (no radix)
|
|
72
|
+
const args = visited.arguments;
|
|
73
|
+
if (!args || args.elements.length !== 1) {
|
|
74
|
+
return visited;
|
|
75
|
+
}
|
|
76
|
+
// Add the radix parameter (10)
|
|
77
|
+
const existingArg = args.elements[0];
|
|
78
|
+
const radixLiteral = {
|
|
79
|
+
kind: java_1.J.Kind.Literal,
|
|
80
|
+
id: (0, uuid_1.randomId)(),
|
|
81
|
+
prefix: java_1.singleSpace,
|
|
82
|
+
markers: markers_1.emptyMarkers,
|
|
83
|
+
value: 10,
|
|
84
|
+
valueSource: '10',
|
|
85
|
+
unicodeEscapes: undefined,
|
|
86
|
+
type: undefined
|
|
87
|
+
};
|
|
88
|
+
return Object.assign(Object.assign({}, visited), { arguments: Object.assign(Object.assign({}, args), { elements: [
|
|
89
|
+
Object.assign(Object.assign({}, existingArg), { after: Object.assign(Object.assign({}, existingArg.after), { whitespace: '' }) }),
|
|
90
|
+
{
|
|
91
|
+
kind: java_1.J.Kind.RightPadded,
|
|
92
|
+
element: radixLiteral,
|
|
93
|
+
after: existingArg.after,
|
|
94
|
+
markers: markers_1.emptyMarkers
|
|
95
|
+
}
|
|
96
|
+
] }) });
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.AddParseIntRadix = AddParseIntRadix;
|
|
104
|
+
//# sourceMappingURL=add-parse-int-radix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-parse-int-radix.js","sourceRoot":"","sources":["../../../src/javascript/cleanup/add-parse-int-radix.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,yCAAoC;AAGpC,wCAA6C;AAC7C,qCAA0C;AAC1C,2CAA2C;AAC3C,qCAAoC;AAEpC;;;;;;;;;;;GAWG;AACH,MAAa,gBAAiB,SAAQ,eAAM;IAA5C;;QACI,SAAI,GAAG,wDAAwD,CAAC;QAChE,gBAAW,GAAG,yBAAyB,CAAC;QACxC,gBAAW,GAAG,oHAAoH,CAAC;IA+DvI,CAAC;IA7DS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,2BAAmC;gBAExC,qBAAqB,CAAC,MAA0B,EAAE,GAAqB;;;;;wBACnF,MAAM,OAAO,GAAG,MAAM,OAAM,qBAAqB,YAAC,MAAM,EAAE,GAAG,CAAuB,CAAC;wBAErF,sCAAsC;wBACtC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;4BACjB,4DAA4D;4BAC5D,kEAAkE;4BAClE,OAAO,OAAO,CAAC;wBACnB,CAAC;wBAED,wBAAwB;wBACxB,IAAI,OAAO,CAAC,IAAI,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;4BACzC,OAAO,OAAO,CAAC;wBACnB,CAAC;wBAED,mDAAmD;wBACnD,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC;wBAC/B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;4BACtC,OAAO,OAAO,CAAC;wBACnB,CAAC;wBAED,+BAA+B;wBAC/B,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;wBACrC,MAAM,YAAY,GAAc;4BAC5B,IAAI,EAAE,QAAC,CAAC,IAAI,CAAC,OAAO;4BACpB,EAAE,EAAE,IAAA,eAAQ,GAAE;4BACd,MAAM,EAAE,kBAAW;4BACnB,OAAO,EAAE,sBAAY;4BACrB,KAAK,EAAE,EAAE;4BACT,WAAW,EAAE,IAAI;4BACjB,cAAc,EAAE,SAAS;4BACzB,IAAI,EAAE,SAAS;yBAClB,CAAC;wBAEF,OAAO,gCACA,OAAO,KACV,SAAS,kCACF,IAAI,KACP,QAAQ,EAAE;oEAEC,WAAW,KACd,KAAK,kCACE,WAAW,CAAC,KAAK,KACpB,UAAU,EAAE,EAAE;oCAGtB;wCACI,IAAI,EAAE,QAAC,CAAC,IAAI,CAAC,WAAW;wCACxB,OAAO,EAAE,YAAY;wCACrB,KAAK,EAAE,WAAW,CAAC,KAAK;wCACxB,OAAO,EAAE,sBAAY;qCACxB;iCACJ,MAEc,CAAC;oBAC5B,CAAC;iBAAA;aACJ,CAAC;QACN,CAAC;KAAA;CACJ;AAlED,4CAkEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/javascript/cleanup/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,0BAA0B,EAAC,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/javascript/cleanup/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,0BAA0B,EAAC,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC"}
|
|
@@ -15,9 +15,11 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.PreferOptionalChain = exports.UseObjectPropertyShorthand = void 0;
|
|
18
|
+
exports.AddParseIntRadix = exports.PreferOptionalChain = exports.UseObjectPropertyShorthand = void 0;
|
|
19
19
|
var use_object_property_shorthand_1 = require("./use-object-property-shorthand");
|
|
20
20
|
Object.defineProperty(exports, "UseObjectPropertyShorthand", { enumerable: true, get: function () { return use_object_property_shorthand_1.UseObjectPropertyShorthand; } });
|
|
21
21
|
var prefer_optional_chain_1 = require("./prefer-optional-chain");
|
|
22
22
|
Object.defineProperty(exports, "PreferOptionalChain", { enumerable: true, get: function () { return prefer_optional_chain_1.PreferOptionalChain; } });
|
|
23
|
+
var add_parse_int_radix_1 = require("./add-parse-int-radix");
|
|
24
|
+
Object.defineProperty(exports, "AddParseIntRadix", { enumerable: true, get: function () { return add_parse_int_radix_1.AddParseIntRadix; } });
|
|
23
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/javascript/cleanup/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,iFAA2E;AAAnE,2IAAA,0BAA0B,OAAA;AAClC,iEAA4D;AAApD,4HAAA,mBAAmB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/javascript/cleanup/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,iFAA2E;AAAnE,2IAAA,0BAA0B,OAAA;AAClC,iEAA4D;AAApD,4HAAA,mBAAmB,OAAA;AAC3B,6DAAuD;AAA/C,uHAAA,gBAAgB,OAAA"}
|
package/dist/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
8.69.0-20251207-
|
|
1
|
+
8.69.0-20251207-160255
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -38,7 +38,7 @@ export async function activate(registry: RecipeRegistry): Promise<void> {
|
|
|
38
38
|
const {OrderImports} = await import("./recipe/index.js");
|
|
39
39
|
const {ModernizeOctalEscapeSequences, ModernizeOctalLiterals, RemoveDuplicateObjectKeys} = await import("./javascript/migrate/es6/index.js");
|
|
40
40
|
const {ExportAssignmentToExportDefault} = await import("./javascript/migrate/typescript/index.js");
|
|
41
|
-
const {UseObjectPropertyShorthand, PreferOptionalChain} = await import("./javascript/cleanup/index.js");
|
|
41
|
+
const {UseObjectPropertyShorthand, PreferOptionalChain, AddParseIntRadix} = await import("./javascript/cleanup/index.js");
|
|
42
42
|
const {UpgradeDependencyVersion} = await import("./javascript/recipes/index.js");
|
|
43
43
|
const {FindDependency} = await import("./javascript/search/index.js");
|
|
44
44
|
|
|
@@ -50,6 +50,7 @@ export async function activate(registry: RecipeRegistry): Promise<void> {
|
|
|
50
50
|
registry.register(RemoveDuplicateObjectKeys);
|
|
51
51
|
registry.register(UseObjectPropertyShorthand);
|
|
52
52
|
registry.register(PreferOptionalChain);
|
|
53
|
+
registry.register(AddParseIntRadix);
|
|
53
54
|
registry.register(UpgradeDependencyVersion);
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 the original author or authors.
|
|
3
|
+
* <p>
|
|
4
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
* <p>
|
|
8
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
9
|
+
* <p>
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {Recipe} from "../../recipe";
|
|
18
|
+
import {TreeVisitor} from "../../visitor";
|
|
19
|
+
import {ExecutionContext} from "../../execution";
|
|
20
|
+
import {JavaScriptVisitor} from "../visitor";
|
|
21
|
+
import {J, singleSpace} from "../../java";
|
|
22
|
+
import {emptyMarkers} from "../../markers";
|
|
23
|
+
import {randomId} from "../../uuid";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Adds the radix parameter to parseInt() calls when missing.
|
|
27
|
+
*
|
|
28
|
+
* The radix parameter specifies the base of the numeral system to use.
|
|
29
|
+
* Without it, parseInt can produce unexpected results:
|
|
30
|
+
* - parseInt("08") was 0 in older JavaScript (octal interpretation)
|
|
31
|
+
* - Modern JavaScript defaults to base 10, but explicit radix is clearer
|
|
32
|
+
*
|
|
33
|
+
* Examples:
|
|
34
|
+
* - `parseInt(x)` becomes `parseInt(x, 10)`
|
|
35
|
+
* - `parseInt(str)` becomes `parseInt(str, 10)`
|
|
36
|
+
*/
|
|
37
|
+
export class AddParseIntRadix extends Recipe {
|
|
38
|
+
name = "org.openrewrite.javascript.cleanup.add-parse-int-radix";
|
|
39
|
+
displayName = "Add radix to `parseInt`";
|
|
40
|
+
description = "Adds the radix parameter (base 10) to `parseInt()` calls that are missing it, preventing potential parsing issues.";
|
|
41
|
+
|
|
42
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
43
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
44
|
+
|
|
45
|
+
protected async visitMethodInvocation(method: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
|
|
46
|
+
const visited = await super.visitMethodInvocation(method, ctx) as J.MethodInvocation;
|
|
47
|
+
|
|
48
|
+
// Check if this is a call to parseInt
|
|
49
|
+
if (visited.select) {
|
|
50
|
+
// This is a method call on an object (e.g., obj.parseInt())
|
|
51
|
+
// parseInt is typically called as a global function, not a method
|
|
52
|
+
return visited;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Check the method name
|
|
56
|
+
if (visited.name.simpleName !== 'parseInt') {
|
|
57
|
+
return visited;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Check if there's exactly one argument (no radix)
|
|
61
|
+
const args = visited.arguments;
|
|
62
|
+
if (!args || args.elements.length !== 1) {
|
|
63
|
+
return visited;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Add the radix parameter (10)
|
|
67
|
+
const existingArg = args.elements[0];
|
|
68
|
+
const radixLiteral: J.Literal = {
|
|
69
|
+
kind: J.Kind.Literal,
|
|
70
|
+
id: randomId(),
|
|
71
|
+
prefix: singleSpace,
|
|
72
|
+
markers: emptyMarkers,
|
|
73
|
+
value: 10,
|
|
74
|
+
valueSource: '10',
|
|
75
|
+
unicodeEscapes: undefined,
|
|
76
|
+
type: undefined
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
...visited,
|
|
81
|
+
arguments: {
|
|
82
|
+
...args,
|
|
83
|
+
elements: [
|
|
84
|
+
{
|
|
85
|
+
...existingArg,
|
|
86
|
+
after: {
|
|
87
|
+
...existingArg.after,
|
|
88
|
+
whitespace: ''
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
kind: J.Kind.RightPadded,
|
|
93
|
+
element: radixLiteral,
|
|
94
|
+
after: existingArg.after,
|
|
95
|
+
markers: emptyMarkers
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
} as J.MethodInvocation;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|