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.

The `no-magic-numbers` rule should ignore function calls

See original GitHub issue

Usually when one number is used with a function the intent is clear and I wouldn’t consider that a magic number. Currently this rule is unusable for me as it gives too many false positives.

In my tests I use a t.plan() method to plan how many assertion the test will have. I have a lot of the following, so my tests gets an endless amount of no-magic-number violations:

test('foo', function (t) {
  t.plan(2);
  ...
});

~/dev
❯ eslint --version
v1.7.3

~/dev
❯ echo 't.plan(2)' | eslint --stdin --rule='no-magic-numbers: [2, {ignore: []}]'

<text>
  1:8  error  No magic number: 2  no-magic-numbers

✖ 1 problem (1 error, 0 warnings)

The rule should either ignore function calls by default or have an option for doing so.

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Oct 23, 2015

Can you explain why you think function calls should be an exception?

0reactions
nzakascommented, Apr 21, 2016

Seems like we couldn’t resolve this, and no further interest or discussion occurred in the past few months, so closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-magic-numbers - ESLint - Pluggable JavaScript Linter
The no-magic-numbers rule aims to make code more readable and refactoring easier by ensuring that special numbers are declared as constants to make...
Read more >
Should linters no-magic-numbers rule used in testing?
Any linter rule anywhere should be disabled whenever it fails its purpose. The main arguments against magic numbers are that.
Read more >
What is a magic number, and why is it bad? - Stack Overflow
A principle that's related to magic numbers is that every fact your code deals with should be declared exactly once. If you use...
Read more >
no-magic-numbers - TypeScript ESLint
This rule extends the base eslint/no-magic-numbers rule. It adds support for: ... Note: you must disable the base rule as it can report...
Read more >
Java static code analysis: Magic numbers should not be used
Magic numbers should not be used · Noncompliant Code Example. public static void doSomething() { for(int i = 0; i < 4; i++){...
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