mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6129] [MERGED] chore(lint): forbid the Number-or-clamp idiom in direct-write settings pages #6092
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6092
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
02a7763chore(lint): forbid the Number-or-clamp idiom in direct-write settings pages1365a63chore(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-syntaxrule that rejects theNumber(v) || Nidiom insideonChangeattributes 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 sharedonNumberhelper.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:
Scope is deliberate. The rule applies only to
src/pages/settings/**andsrc/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 (totalGB0 = unlimited,limitIp0 = 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 — noeslint-disableanywhere.Type of change
Areas affected
How was this tested?
TelegramTab.tsx:127); the converted code lints clean.npm run lintpasses with no suppressions; full frontend suite (100 files / 913 tests),typecheck,buildpass.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), andMath.maxstill floors typed values at 1.Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.