[PR #6129] [MERGED] chore(lint): forbid the Number-or-clamp idiom in direct-write settings pages #6092

Closed
opened 2026-11-02 04:06:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6129
Author: @PathGao
Created: 7/28/2026
Status: ✅ Merged
Merged: 7/29/2026
Merged by: @MHSanaei

Base: main ← Head: chore-guard-number-clamp


📝 Commits (2)

  • 02a7763 chore(lint): forbid the Number-or-clamp idiom in direct-write settings pages
  • 1365a63 chore(lint): widen the numeric-clamp guard to the shapes that actually drift

📊 Changes

3 files changed (+40 additions, -4 deletions)

View changed files

📝 frontend/eslint.config.js (+33 -0)
📝 frontend/src/pages/settings/TelegramTab.tsx (+3 -1)
📝 frontend/src/pages/xray/basics/BasicsTab.tsx (+4 -3)

📄 Description

Summary

Add a scoped ESLint no-restricted-syntax rule that rejects the Number(v) || N idiom inside onChange attributes in the settings and xray pages — the drift-prevention follow-up promised in #6127's review thread — and convert the one remaining match (the Telegram notify interval) onto the shared onNumber helper.

Why

#6127 centralized the null-safe handling, but as its review noted, nothing enforced the helper: the next numeric field pasted from an unconverted neighbor would reintroduce the cleared-port bug (#6121) silently. The rule makes that a lint error at the exact blast site:

A cleared InputNumber must not write a synthetic value; wrap the handler
with onNumber() from @/utils/onNumber (see #6127).

Scope is deliberate. The rule applies only to src/pages/settings/** and src/pages/xray/**, where onChange handlers write straight into persisted state. The clients/inbounds form modals stage values behind Zod validation, and several of their fields carry a real clear-means-zero semantic (totalGB 0 = unlimited, limitIp 0 = no limit) — converting those would break intended UX, so they are outside the rule's directories, with the reasoning recorded in a comment on the rule itself.

With the Telegram interval converted (its Math.max(1, …) floor is kept for typed values; clearing now keeps the stored count instead of writing 1), the rule lands with zero suppressions — no eslint-disable anywhere.

Type of change

  • Build / CI / tooling
  • Refactoring (one site converted; see behavior note)

Areas affected

  • Frontend (UI / panel pages)

How was this tested?

  • Verified the rule fires: reverting the Telegram site to the old idiom produces the lint error at the expected position (TelegramTab.tsx:127); the converted code lints clean.
  • npm run lint passes with no suppressions; full frontend suite (100 files / 913 tests), typecheck, build pass.

Screenshots / recordings

N/A — no visual change.

Breaking changes

None.

Behavior note: clearing the Telegram notify-interval count previously wrote 1; it now keeps the stored value (consistent with every other converted numeric field), and Math.max still floors typed values at 1.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (not applicable — the rule is its own guard; the helper's behavior is already pinned by the #6127 tests)
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed (not applicable)
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6129 **Author:** [@PathGao](https://github.com/PathGao) **Created:** 7/28/2026 **Status:** ✅ Merged **Merged:** 7/29/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `chore-guard-number-clamp` --- ### 📝 Commits (2) - [`02a7763`](https://github.com/MHSanaei/3x-ui/commit/02a7763b339acf62dee717ed0b90831b3d6fd25f) chore(lint): forbid the Number-or-clamp idiom in direct-write settings pages - [`1365a63`](https://github.com/MHSanaei/3x-ui/commit/1365a630b954177a52060f33e968705cddca414e) chore(lint): widen the numeric-clamp guard to the shapes that actually drift ### 📊 Changes **3 files changed** (+40 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `frontend/eslint.config.js` (+33 -0) 📝 `frontend/src/pages/settings/TelegramTab.tsx` (+3 -1) 📝 `frontend/src/pages/xray/basics/BasicsTab.tsx` (+4 -3) </details> ### 📄 Description ## Summary Add a scoped ESLint `no-restricted-syntax` rule that rejects the `Number(v) || N` idiom inside `onChange` attributes in the settings and xray pages — the drift-prevention follow-up promised in #6127's review thread — and convert the one remaining match (the Telegram notify interval) onto the shared `onNumber` helper. ## Why #6127 centralized the null-safe handling, but as its review noted, nothing *enforced* the helper: the next numeric field pasted from an unconverted neighbor would reintroduce the cleared-port bug (#6121) silently. The rule makes that a lint error at the exact blast site: ``` A cleared InputNumber must not write a synthetic value; wrap the handler with onNumber() from @/utils/onNumber (see #6127). ``` **Scope is deliberate.** The rule applies only to `src/pages/settings/**` and `src/pages/xray/**`, where onChange handlers write straight into persisted state. The clients/inbounds form modals stage values behind Zod validation, and several of their fields carry a real clear-means-zero semantic (`totalGB` 0 = unlimited, `limitIp` 0 = no limit) — converting those would break intended UX, so they are outside the rule's directories, with the reasoning recorded in a comment on the rule itself. With the Telegram interval converted (its `Math.max(1, …)` floor is kept for typed values; clearing now keeps the stored count instead of writing 1), the rule lands with **zero suppressions** — no `eslint-disable` anywhere. ## Type of change - [x] Build / CI / tooling - [x] Refactoring (one site converted; see behavior note) ## Areas affected - [x] Frontend (UI / panel pages) ## How was this tested? - Verified the rule fires: reverting the Telegram site to the old idiom produces the lint error at the expected position (`TelegramTab.tsx:127`); the converted code lints clean. - `npm run lint` passes with no suppressions; full frontend suite (100 files / 913 tests), `typecheck`, `build` pass. ## Screenshots / recordings N/A — no visual change. ## Breaking changes None. Behavior note: clearing the Telegram notify-interval count previously wrote `1`; it now keeps the stored value (consistent with every other converted numeric field), and `Math.max` still floors typed values at 1. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (not applicable — the rule is its own guard; the helper's behavior is already pinned by the #6127 tests) - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed (not applicable) - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:18 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6092
No description provided.