no-fn-reference-in-iterator: Ignore locally declared functions?
See original GitHub issueI would like the following to be ignored by no-fn-reference-in-iterator
:
const fn = item => {
// do stuff with iterator items
};
iter1.forEach(fn);
iter2.forEach(fn);
iter3.forEach(fn);
Since fn
is locally declared and defined the purpose of no-fn-reference-in-iterator
does not apply. I see value in the following situations being reported:
const mapper = require('unicorn-mapper');
function doStuff(iter, fn) {
iter.forEach(fn); // error on `fn` provided by argument
}
[2, 3, 4].forEach(mapper); // error as `mapper` is from a `require`
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
git - ignore some files in locally without change gitignore project
There is no way in Git to ignore changes to tracked files. From the git update-index documentation:.
Read more >Ignoring files - GitHub Docs
gitignore file to share with others, you can create rules that are not committed with the repository. You can use this technique for...
Read more >Git Ignore Locally: Ignore Files in Local Copy
It gives you three Git shortcuts ignore (to locally ignore some files), unignore (to stop the local ignore on specific files), and ignored...
Read more >gitignore Documentation - Git
DESCRIPTION. A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES ......
Read more >.gitignore file - ignoring files in Git | Atlassian Git Tutorial
Git ignore patterns are used to exclude certain files in your working directory from your Git history. They can be local, global, or...
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
I’ve been disabling this rule as I go.
I get that it tries to prevent future breakage, but this exclusively depends on the function signature:
fn
accept multiple arguments? Report it.That’s it.
Only
node_modules
introduce uncertainty because a futurenpm install
might change the signature offn
after the lint, unless…fn
won’t just change under your feet.This means that single-parameter local functions (same file or other file) should not be reported by this check. If a local
fn
is changed to a multi-parameter, the lint will likely be run after this change and report it.If lockfile detection can be part of a rule,
node_modules
can also follow the same logic.Changed my mind on this specific point:
The problem is that (regardless of types) the linter does not know what the expected input of the function is. The second parameter could match the exact type and pass everywhere, yet still fall into the trap that this rule is meant to prevent.
If you follow this rule, you’d have written the loop this way and that diff wouldn’t have caused the issue: