tools icon indicating copy to clipboard operation
tools copied to clipboard

feat(rome_js_analyze): Implement prefer-numeric-literals lint

Open 95th opened this issue 3 years ago • 3 comments

Implements:

  • https://github.com/rome/tools/issues/3360

Summary

Support prefer-numeric-literals lint rule

Test Plan

added unit tests for lint.

95th avatar Nov 03 '22 20:11 95th

Deploy Preview for docs-rometools ready!

Built without sensitive environment variables

Name Link
Latest commit d302f510ce4ae8243c38b5bd54641f84c052537b
Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/637210d74d725200096bfbce
Deploy Preview https://deploy-preview-3558--docs-rometools.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Nov 03 '22 20:11 netlify[bot]

~~For some reason, the below case is not caught (perhaps due to another rule already being applied)~~

Number[`parseInt`]('12', 8);

nvm. It was bug in the logic.

95th avatar Nov 04 '22 09:11 95th

@MichaReiser I am getting the below error on the below test case. Can you please help?

Number.parseInt('17', 8)in foo

Error:

thread 'specs::style::prefer_numeric_literals_js' panicked at 'There should be no errors in the file "/Users/gurwindersi/tools/crates/rome_js_analyze/tests/specs/style/preferNumericLiterals.js" but the following errors where present:
/Users/gurwindersi/tools/crates/rome_js_analyze/tests/specs/style/preferNumericLiterals.js:63:1 parse ━━━━━━━━━━

  × expected a statement but instead found '0b11in foo
    Number.parseInt('17', 8)in foo
    parseInt('A', 16)in foo
    parseInt('11', 2) in foo
    Number.parseInt('17', 8)/**/in foo
    (parseInt('A', 16))in foo
    /* comment */Number.parseInt('11', 2)'

    61 │ Number.parseInt('17', 8)+5
    62 │ parseInt('A', 16)+5
  > 63 │ 0b11in foo
       │ ^^^^^^^^^^
  > 64 │ Number.parseInt('17', 8)in foo
        ...
  > 68 │ (parseInt('A', 16))in foo
  > 69 │ /* comment */Number.parseInt('11', 2);
       │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    70 │ Number/**/.parseInt('11', 2);

95th avatar Nov 05 '22 09:11 95th

Thank you so much @95th for this contribution. Looking all good. Can you rebase your changes to resolve the merge conflicts, and we're good to

MichaReiser avatar Nov 14 '22 08:11 MichaReiser