The Function constructor is not recognized as eval or implied-eval
See original GitHub issueTell us about your environment
- ESLint Version: 4.8.0
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
eslint --rule 'no-implied-eval: 2' --rule 'no-eval: 2' file.js
What did you do? Please include the actual source code causing the issue.
eval(`console.log("${location.hash}")`)
setTimeout(`console.log("${location.hash}")`)
Function(`console.log("${location.hash}")`)()
What did you expect to happen?
Function(str)
should be an error
1:1 error eval can be harmful no-eval
2:1 error Implied eval. Consider passing a function instead of a string no-implied-eval
3:1 error Implied eval. Consider passing a function instead of a string no-implied-eval
✖ 3 problems (3 errors, 0 warnings)
What actually happened? Please include the actual, raw output from ESLint.
Function(str)
is not an error
1:1 error eval can be harmful no-eval
2:1 error Implied eval. Consider passing a function instead of a string no-implied-eval
✖ 2 problems (2 errors, 0 warnings)
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
The Function constructor is eval - JSLint Error Explanations
This error is raised to highlight a bad practice. By passing a string to the Function constructor you are requiring the engine to...
Read more >no-implied-eval - Pluggable JavaScript Linter - ESLint
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Disallow Use of Function Constructor (no-new-func)
Prevents the creation of new functions using the Function() constructor. This is a non-standard, ... Disallow Implied Use of eval() (no-implied-eval).
Read more >Why new Function not work as eval? - Stack Overflow
The important part is working with the arguments object and access your desired return value. old answer with eval: const myFunc = evalStr...
Read more >List of available rules - ESLint - Pluggable JavaScript linter
disallow variable or function declarations in nested blocks ... disallow invalid regular expression strings in RegExp constructors ... no-implied-eval.
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 Free
Top 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
(Marking this issue as “works as intended” because the behavior described in the original issue is working as designed.)
I think we might want to reconsider our standards for adding rules to
eslint:recommended
in general. There was some discussion aboutno-console
in https://github.com/eslint/eslint/issues/8544, and it seems like the consensus is to leave it ineslint:recommended
because usingconsole
is undesirable in most applications. But it seems like we’re holding other rules to a much stricter standard. For example, we rejected addingno-template-curly-in-string
toeslint:recommended
for 4.0 because a deprecated jQuery plugin uses similar template syntax. It seems like it’s much more common to need to useconsole
than to need to use that specific template syntax, so maybe we should reconsider the rules ineslint:recommended
and try to apply a consistent standard to them.Thanks for the issue link. I personally think eslint:recommended should include rules that are solid practices in the vast, vast majority of situations. Code generation is not a common use case, in my view. I’ll reply on that issue later.
On Oct 11, 2017 10:04 AM, “薛定谔的猫” notifications@github.com wrote: