question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-octal rule on NonOctalDecimalIntegerLiterals

See original GitHub issue

Tell us about your environment

  • ESLint Version: 5.16.0
  • Node Version: 10.16.0
  • npm Version: 6.9.0

What parser (default, Babel-ESLint, etc.) are you using? default Please show your full configuration:

Configuration
module.exports = {
  parserOptions: {
    ecmaVersion: 2018,
  },
  rules: {
    'no-octal': 'error',
  },
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

let x;
x = 018;
x = 081;
x = 018.2;
x = 081.2;
x = 018e2;
x = 081e2;
eslint index.js

What did you expect to happen? By the specification both 018 and 081 are NonOctalDecimalIntegerLiteral, not LegacyOctalIntegerLiteral.

If the no-octal rule is supposed to catch these literals (which look like octal literals but are actually evaluated as decimal literals), then it should report all 6 as errors.

Otherwise, if the rule is supposed to catch only octal literals, then it should report zero errors, and perhaps a new rule could be added.

What actually happened? Please include the actual, raw output from ESLint. Only 018, 018.2 and 018e2 are reported as errors:

2:5 error Octal literals should not be used no-octal 4:5 error Octal literals should not be used no-octal 6:5 error Octal literals should not be used no-octal

✖ 3 problems (3 errors, 0 warnings)

Are you willing to submit a pull request to fix this bug? yes

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, May 31, 2019

You’re right, I think this is just a bug in the rule. It doesn’t make sense that 018 would be reported while 081 would not.

1reaction
mdjermanoviccommented, Jun 1, 2019

It most likely wasn’t a bug when /^0[0-7]/ commit was made, at least by the then actual specifications. There is nothing that could match 018 or 081 in 5.1 spec, its annex or any older specs, so these literals were probably expected to be caught by the parser as invalid.

However, browsers did support them as decimal integers. There were attempts to remove this support, but some important sites/apps were broken, so they are eventually included in ES6 as NonOctalDecimalIntegerLiteral and /^0[0-7]/ became a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integer literals - IBM
Integer literals are numbers that do not have a decimal point or an exponential part. They can be represented as: Decimal integer literals;...
Read more >
Why is 08 not a valid integer literal in Java? - Stack Overflow
Any number prefixed with a 0 is considered octal. Octal numbers can only use digits 0-7, just like ...
Read more >
Integer literal - cppreference.com
1) Decimal integer literal (base 10) · 2) Octal integer literal (base 8) · 3) Hexadecimal integer literal (base 16, the letters 'a'...
Read more >
C static code analysis: Octal values should not be used
Integer literals starting with a zero are octal rather than decimal values. While using octal values is fully supported, most developers do not...
Read more >
Oo... adding a coherent character sequence to start octal-literals
The syntax rule to interpret integer literals starting with a zero as octal-literals probably dates back from the time people were still tinkering...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found