Skip to content

Feat: Add step property for number rule - #362

Merged
icebob-ai merged 5 commits into
icebob:masterfrom
E1ecti:master
Apr 9, 2026
Merged

Feat: Add step property for number rule#362
icebob-ai merged 5 commits into
icebob:masterfrom
E1ecti:master

Conversation

@E1ecti

@E1ecti E1ecti commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Implementing step property maintains consistency with the HTML5 range and number input types, which utilize the step attribute.

@icebob-ai icebob-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the well-structured PR — all the pieces are there (rule, messages, types, tests, README). Nice work!

However, there's a floating point precision bug with the modulo approach:

0.3 % 0.1  // → 0.09999999999999998 (not 0!)
1.2 % 0.4  // → 0.3999999999999999

So { type: "number", step: 0.1 } would incorrectly reject 0.3. The current tests only use integer steps (step: 10), which hides this issue.

Please fix:

  1. Handle floating point precision — e.g. using a tolerance check like Math.abs(Math.round(value / step) - value / step) > 1e-10 or a similar approach
  2. Add test cases with float steps (e.g. step: 0.1 with values like 0.3, 0.7, 1.2)
  3. Consider validating that step is a positive number (what should step: -5 or step: 0 do?)

Small effort, but it'll make this feature solid. Thanks!

@E1ecti
E1ecti requested a review from icebob-ai April 7, 2026 10:22
@E1ecti

E1ecti commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback!

I've implemented the suggested tolerance check to handle floating-point precision issues. Regarding the step schema validation: while negative values don't technically break the logic, I've added a check to ensure it's a positive number.

I also updated the test suite to cover floating-point scenarios and invalid schema configurations.

@E1ecti

E1ecti commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

Previous tolerance-based approach allowed certain invalid values to pass, which was incorrect behavior for the validator.

Current implementation eliminates false positives for floating-point numbers exceeding the old 1e-10 precision limit (such as 1.00000000001).

@icebob-ai icebob-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great now! The floating point handling with the integer multiplication approach is solid, schema validation catches invalid steps at compile time, and the test coverage is thorough (including float edge cases).

Minor nit: there are a few unrelated whitespace changes (double-space → single-space in makeError calls) — ideally those would be in a separate commit, but it's not a blocker.

Thanks for the quick turnaround and the quality work — merging! 🎉

@icebob-ai
icebob-ai merged commit bd415af into icebob:master Apr 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants