Skip to content

Commit

Permalink
Bugfix/number literal format fix (palantir#4856)
Browse files Browse the repository at this point in the history
* Add failing test case.

* Preserve significant zeros in fix.
  • Loading branch information
rgant authored and Josh Goldberg committed Sep 12, 2019
1 parent 98edf1a commit 5cf6e65
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/numberLiteralFormatRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function walk(ctx: Lint.WalkContext): void {

const [num, exp = ""] = text.split(/e/i);
const [integer, float = ""] = num.split(".");
const matchedNumeric = /(\.)([1-9]*)(0+)/.exec(num);
const matchedNumeric = /(\.)(\d*?)(0+)$/.exec(num);
const [dot = "", numbers = "", zeroes = ""] = Array.isArray(matchedNumeric)
? matchedNumeric.slice(1)
: [];
Expand Down
2 changes: 2 additions & 0 deletions test/rules/number-literal-format/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@

0xDEADBEEF;

0.0102;

3 changes: 3 additions & 0 deletions test/rules/number-literal-format/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
0xDEAdBEEF;
~~~~~~~~~~ [uppercase]

0.010200;
~~~~~~~~ [trailing-0]

[leading-0]: Number literal should not have a leading '0'.
[trailing-0]: Number literal should not have a trailing '0'.
[trailing-decimal]: Number literal should not end in '.'.
Expand Down

0 comments on commit 5cf6e65

Please sign in to comment.