Enable the radix ESLint rule

Many `parseInt` call-sites already provide the `radix` argument, and this rule helps improve consistency in the code-base; see https://eslint.org/docs/latest/rules/radix

*Please note:* The rule is disabled in `src/scripting_api/util.js` for now, since it's not obvious at a glance (at least to me) what the correct `radix` argument should be there.
This commit is contained in:
Jonas Jenwald 2026-04-25 12:09:18 +02:00
parent f41c60ab7e
commit e6dba6ee34
17 changed files with 30 additions and 27 deletions

View File

@ -269,6 +269,7 @@ export default [
"prefer-object-has-own": "error", "prefer-object-has-own": "error",
"prefer-promise-reject-errors": "error", "prefer-promise-reject-errors": "error",
"prefer-spread": "error", "prefer-spread": "error",
radix: "error",
"wrap-iife": ["error", "any"], "wrap-iife": ["error", "any"],
yoda: ["error", "never", { exceptRange: true }], yoda: ["error", "never", { exceptRange: true }],

View File

@ -168,7 +168,7 @@ function renderEnumPref(shortDescription, prefName) {
var select = wrapper.querySelector("select"); var select = wrapper.querySelector("select");
select.onchange = function () { select.onchange = function () {
var pref = {}; var pref = {};
pref[prefName] = parseInt(this.value); pref[prefName] = parseInt(this.value, 10);
storageArea.set(pref); storageArea.set(pref);
}; };
wrapper.querySelector("span").textContent = shortDescription; wrapper.querySelector("span").textContent = shortDescription;

View File

@ -96,7 +96,7 @@ limitations under the License.
chrome.storage.local.get(localStorage, items => { chrome.storage.local.get(localStorage, items => {
Object.assign(localStorage, items); Object.assign(localStorage, items);
var lastTime = parseInt(localStorage.telemetryLastTime) || 0; var lastTime = parseInt(localStorage.telemetryLastTime, 10) || 0;
var wasUpdated = didUpdateSinceLastCheck(); var wasUpdated = didUpdateSinceLastCheck();
if (!wasUpdated && Date.now() - lastTime < MINIMUM_TIME_BETWEEN_PING) { if (!wasUpdated && Date.now() - lastTime < MINIMUM_TIME_BETWEEN_PING) {
return; return;

View File

@ -316,8 +316,8 @@ class Ref {
// eslint-disable-next-line no-restricted-syntax // eslint-disable-next-line no-restricted-syntax
return (RefCache[str] = new Ref( return (RefCache[str] = new Ref(
parseInt(m[1]), parseInt(m[1], 10),
!m[2] ? 0 : parseInt(m[2]) !m[2] ? 0 : parseInt(m[2], 10)
)); ));
} }

View File

@ -74,7 +74,7 @@ class XFAFactory {
this.pages = await this._createPagesHelper(); this.pages = await this._createPagesHelper();
this.dims = this.pages.children.map(c => { this.dims = this.pages.children.map(c => {
const { width, height } = c.attributes.style; const { width, height } = c.attributes.style;
return [0, 0, parseInt(width), parseInt(height)]; return [0, 0, parseInt(width, 10), parseInt(height, 10)];
}); });
} catch (e) { } catch (e) {
warn(`XFA - an error occurred during layout: ${e}`); warn(`XFA - an error occurred during layout: ${e}`);

View File

@ -81,11 +81,11 @@ const StyleMapping = new Map([
["kerning-mode", value => (value === "none" ? "none" : "normal")], ["kerning-mode", value => (value === "none" ? "none" : "normal")],
[ [
"xfa-font-horizontal-scale", "xfa-font-horizontal-scale",
value => `scaleX(${Math.max(0, parseInt(value) / 100).toFixed(2)})`, value => `scaleX(${Math.max(0, parseInt(value, 10) / 100).toFixed(2)})`,
], ],
[ [
"xfa-font-vertical-scale", "xfa-font-vertical-scale",
value => `scaleY(${Math.max(0, parseInt(value) / 100).toFixed(2)})`, value => `scaleY(${Math.max(0, parseInt(value, 10) / 100).toFixed(2)})`,
], ],
["xfa-spacerun", ""], ["xfa-spacerun", ""],
["xfa-tab-stops", ""], ["xfa-tab-stops", ""],

View File

@ -687,7 +687,7 @@ class XRef {
if (!entry) { if (!entry) {
continue; continue;
} }
const ref = Ref.get(parseInt(num), entry.gen); const ref = Ref.get(parseInt(num, 10), entry.gen);
let obj; let obj;
try { try {

View File

@ -3024,7 +3024,7 @@ class PopupElement {
this.#setPosition(); this.#setPosition();
this.#container.hidden = false; this.#container.hidden = false;
this.#container.style.zIndex = this.#container.style.zIndex =
parseInt(this.#container.style.zIndex) + 1000; parseInt(this.#container.style.zIndex, 10) + 1000;
} else if (this.#pinned) { } else if (this.#pinned) {
this.#container.classList.add("focused"); this.#container.classList.add("focused");
} }
@ -3040,7 +3040,7 @@ class PopupElement {
} }
this.#container.hidden = true; this.#container.hidden = true;
this.#container.style.zIndex = this.#container.style.zIndex =
parseInt(this.#container.style.zIndex) - 1000; parseInt(this.#container.style.zIndex, 10) - 1000;
} }
forceHide() { forceHide() {

View File

@ -569,7 +569,7 @@ class PDFDateString {
*/ */
function getXfaPageViewport(xfaPage, { scale = 1, rotation = 0 }) { function getXfaPageViewport(xfaPage, { scale = 1, rotation = 0 }) {
const { width, height } = xfaPage.attributes.style; const { width, height } = xfaPage.attributes.style;
const viewBox = [0, 0, parseInt(width), parseInt(height)]; const viewBox = [0, 0, parseInt(width, 10), parseInt(height, 10)];
return new PageViewport({ return new PageViewport({
viewBox, viewBox,
@ -596,7 +596,7 @@ function getRGBA(color) {
const [r, g, b] = color const [r, g, b] = color
.slice(/* "rgb(".length */ 4, -1) // Strip out "rgb(" and ")". .slice(/* "rgb(".length */ 4, -1) // Strip out "rgb(" and ")".
.split(",") .split(",")
.map(x => parseInt(x)); .map(x => parseInt(x, 10));
return [r, g, b, 1]; return [r, g, b, 1];
} }
@ -605,9 +605,9 @@ function getRGBA(color) {
.slice(/* "rgba(".length */ 5, -1) // Strip out "rgba(" and ")". .slice(/* "rgba(".length */ 5, -1) // Strip out "rgba(" and ")".
.split(","); .split(",");
return [ return [
parseInt(parts[0]), parseInt(parts[0], 10),
parseInt(parts[1]), parseInt(parts[1], 10),
parseInt(parts[2]), parseInt(parts[2], 10),
parseFloat(parts[3]), parseFloat(parts[3]),
]; ];
} }

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable radix */
import { PDFObject } from "./pdf_object.js"; import { PDFObject } from "./pdf_object.js";

View File

@ -155,7 +155,7 @@ function updateBrowser(window) {
window.navigator.userAgent = window.navigator.userAgent.replace( window.navigator.userAgent = window.navigator.userAgent.replace(
/Chrome\/(\d+)/, /Chrome\/(\d+)/,
function (_, v) { function (_, v) {
return "Chrome/" + (parseInt(v) + 1); return "Chrome/" + (parseInt(v, 10) + 1);
} }
); );
} }

View File

@ -1389,7 +1389,7 @@ describe("Interaction", () => {
(sel, b, a) => { (sel, b, a) => {
const el = document.querySelector(sel); const el = document.querySelector(sel);
const rotation = const rotation =
parseInt(el.getAttribute("data-main-rotation")) || 0; parseInt(el.getAttribute("data-main-rotation"), 10) || 0;
return rotation === (360 + ((360 - (b + a)) % 360)) % 360; return rotation === (360 + ((360 - (b + a)) % 360)) % 360;
}, },
{}, {},

View File

@ -532,7 +532,7 @@ function getEditors(page, kind) {
const elements = document.querySelectorAll(`.${aKind}Editor`); const elements = document.querySelectorAll(`.${aKind}Editor`);
const results = []; const results = [];
for (const { id } of elements) { for (const { id } of elements) {
results.push(parseInt(id.split("_").at(-1))); results.push(parseInt(id.split("_").at(-1), 10));
} }
results.sort(); results.sort();
return results; return results;

View File

@ -366,7 +366,7 @@ const PDFViewerApplication = {
// Set some specific preferences for tests. // Set some specific preferences for tests.
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
Object.assign(opts, { Object.assign(opts, {
capCanvasAreaFactor: x => parseInt(x), capCanvasAreaFactor: x => parseInt(x, 10),
docBaseUrl: x => x, docBaseUrl: x => x,
enableAltText: x => x === "true", enableAltText: x => x === "true",
enableAutoLinking: x => x === "true", enableAutoLinking: x => x === "true",
@ -379,15 +379,15 @@ const PDFViewerApplication = {
enableSplitMerge: x => x === "true", enableSplitMerge: x => x === "true",
enableUpdatedAddImage: x => x === "true", enableUpdatedAddImage: x => x === "true",
highlightEditorColors: x => x, highlightEditorColors: x => x,
imagesRightClickMinSize: x => parseInt(x), imagesRightClickMinSize: x => parseInt(x, 10),
maxCanvasPixels: x => parseInt(x), maxCanvasPixels: x => parseInt(x, 10),
spreadModeOnLoad: x => parseInt(x), spreadModeOnLoad: x => parseInt(x, 10),
supportsCaretBrowsingMode: x => x === "true", supportsCaretBrowsingMode: x => x === "true",
viewerCssTheme: x => parseInt(x), viewerCssTheme: x => parseInt(x, 10),
forcePageColors: x => x === "true", forcePageColors: x => x === "true",
pageColorsBackground: x => x, pageColorsBackground: x => x,
pageColorsForeground: x => x, pageColorsForeground: x => x,
sidebarViewOnLoad: x => parseInt(x), sidebarViewOnLoad: x => parseInt(x, 10),
}); });
} }

View File

@ -237,7 +237,7 @@ class CaretBrowsingMode {
#getNodeOnNextPage(textLayer, isUp) { #getNodeOnNextPage(textLayer, isUp) {
while (true) { while (true) {
const page = textLayer.closest(".page"); const page = textLayer.closest(".page");
const pageNumber = parseInt(page.getAttribute("data-page-number")); const pageNumber = parseInt(page.getAttribute("data-page-number"), 10);
const nextPage = isUp ? pageNumber - 1 : pageNumber + 1; const nextPage = isUp ? pageNumber - 1 : pageNumber + 1;
textLayer = this.#viewerContainer.querySelector( textLayer = this.#viewerContainer.querySelector(
`.page[data-page-number="${nextPage}"] .textLayer` `.page[data-page-number="${nextPage}"] .textLayer`

View File

@ -287,7 +287,8 @@ class PDFThumbnailViewer {
parseInt( parseInt(
e.target e.target
.closest(".thumbnailImageContainer") .closest(".thumbnailImageContainer")
?.parentElement.getAttribute("page-number") ?.parentElement.getAttribute("page-number"),
10
) ?? -1, ) ?? -1,
hasSelectedPages: !!this.#selectedPages?.size, hasSelectedPages: !!this.#selectedPages?.size,
canDeletePages: this.#canDelete(), canDeletePages: this.#canDelete(),

View File

@ -410,7 +410,7 @@ class SignatureManager {
this.#drawCurves = { this.#drawCurves = {
width: drawWidth, width: drawWidth,
height: drawHeight, height: drawHeight,
thickness: parseInt(this.#drawThickness.value), thickness: parseInt(this.#drawThickness.value, 10),
curves: [], curves: [],
}; };
this.#disableButtons(true); this.#disableButtons(true);