-1

I'm using NuxtJS CLI, which comes together with Prettier and ESLint.

I have problems with hexadecimal numbers:

0xffffff

ESLint doesn't like it and throws this error:

Invalid number literal casing unicorn/number-literal-case

I found this solution, but it didn't work for some reason.

Now I want to disable this rule at all to move forward with my project.

I tried this rule into .eslintsrc.js:

'prefer-numeric-literals': 'off',

That solved 50% of errors, but some ESLint "unicorn" is still causing the error. I tried to uninstall this dependency - but it won't go away.

I also tried to write hexadecimal numbers in uppercase, but prettier transforms it to lowercase on save.

The single option is to write code in this way:

/* eslint-disable */
object.material.color.set(Math.random() * 0xffffff)
/* eslint-enable */

But this is not convenient...

Is there a way to fix it?

  • Prettier version: 2.4.0
  • ESLint version: 7.3.2
MAZ
  • 643
  • 5
  • 18
  • 1
    You've linked to the wrong plugin entirely, that error's from: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/number-literal-case.md. If you want to know how to configure ESLint, [read the docs](https://eslint.org/docs/user-guide/configuring/). – jonrsharpe Jun 07 '22 at 08:40

1 Answers1

1

The purpose of the rule is to have consistent casing, it wants you to write 0xFFFFFF (so all uppercase with lowercase x). If you don't want that you can disable it in the config with

'unicorn/number-literal-case': 'off',
lusc
  • 1,206
  • 1
  • 10
  • 19
  • I totally understand and support the purpose, but as I wrote above for some reason prettier auto-formats values to lowercase ¯\_(ツ)_/¯ – MAZ Jun 07 '22 at 19:19
  • Now I got it. The name of the rule was inside the error text. – MAZ Jun 07 '22 at 19:24
  • @MAZ "*for some reason prettier auto-formats values to lowercase*" then adjust Prettier or turn it off. Or adjust this rule or turn it off. Right now, the two are at odds. – VLAZ Jun 09 '22 at 06:20
  • @vlaz I don't want to turn off the prettier, it makes my code more readable. And I have no idea how to set rules for pretties, when for ESLin I already know how to do this – MAZ Jun 10 '22 at 10:01
  • @MAZ are you aware that ESLint also has an autofix functionality? – VLAZ Jun 10 '22 at 10:04
  • @VLAZ yea, but it's not automatical as I know – MAZ Jun 10 '22 at 13:18
  • @MAZ neither is Prettier. In both cases it has to be setup. But for ESLint it's just running with the `--fix` option. Or you can set your editor to run autofix based on the ESLint rules. It's basically the same with Prettier. It's not magic. They both work in essentially the same way - scan the code, run it against a list of rules, if there is a rule breach issue a warning or error. And potentially offer an autofix. ESLint has rules that aren't autofixable because they aren't stylistic in nature but does have it for the stylistic problems. Prettier only watches for stylistic problems. – VLAZ Jun 10 '22 at 13:25
  • @VLAZ I understand this but, the funniest thing that prettier and eslint had different rules for the same case. It's like to install two anti-viruses on one computer and watch which one wins :) – MAZ Jun 10 '22 at 14:23
  • @MAZ that's not funny, that's sad. And it's why I told you that ESLint can also format - if you have a single source of truth for how the code should be handled, then there would be no conflicts. And no need to maintain two sets of rules and make sure they align properly. – VLAZ Jun 10 '22 at 14:26