The `no-magic-numbers` rule should ignore function calls
See original GitHub issueUsually 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:
- Created 8 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you explain why you think function calls should be an exception?
Seems like we couldn’t resolve this, and no further interest or discussion occurred in the past few months, so closing.