Skip to content

Bug: [no-new-func] no error with function () {}.constructor #19863

Closed as not planned
@regseb

Description

@regseb

Environment

ESLint Playground

What parser are you using?

Default (Espree)

What did you do?

Playground Code

const add = new Function("a", "b", "return a + b;");

const BypassFunction = function () {}.constructor;
const sub = new BypassFunction("a", "b", "return a - b;");

// https://developer.mozilla.org/Web/JavaScript/Reference/Global_Objects/AsyncFunction
const AsyncFunction = async function () {}.constructor;
const mul = new AsyncFunction("a", "b", "return a * b;");

ESLint Configuration

Tap to see full config
export default [
    {
        "rules": {
            "no-new-func": [
                "error"
            ]
        }
    }
];

ESLint Output

1:13 The Function constructor is eval. (no-new-func)

What did you expect to happen?

1:13 The Function constructor is eval. (no-new-func)
4:13 The Function constructor is eval. (no-new-func)
8:13 The AsyncFunction constructor is eval. (no-new-func)

What actually happened?

1:13 The Function constructor is eval. (no-new-func)

Link to Minimal Reproducible Example

https://eslint.org/play/#eyJ0ZXh0IjoiY29uc3QgYWRkID0gbmV3IEZ1bmN0aW9uKFwiYVwiLCBcImJcIiwgXCJyZXR1cm4gYSArIGI7XCIpO1xuXG5jb25zdCBCeXBhc3NGdW5jdGlvbiA9IGZ1bmN0aW9uICgpIHt9LmNvbnN0cnVjdG9yO1xuY29uc3Qgc3ViID0gbmV3IEJ5cGFzc0Z1bmN0aW9uKFwiYVwiLCBcImJcIiwgXCJyZXR1cm4gYSAtIGI7XCIpO1xuXG4vLyBodHRwczovL2RldmVsb3Blci5tb3ppbGxhLm9yZy9XZWIvSmF2YVNjcmlwdC9SZWZlcmVuY2UvR2xvYmFsX09iamVjdHMvQXN5bmNGdW5jdGlvblxuY29uc3QgQXN5bmNGdW5jdGlvbiA9IGFzeW5jIGZ1bmN0aW9uICgpIHt9LmNvbnN0cnVjdG9yO1xuY29uc3QgbXVsID0gbmV3IEFzeW5jRnVuY3Rpb24oXCJhXCIsIFwiYlwiLCBcInJldHVybiBhICogYjtcIik7XG4iLCJvcHRpb25zIjp7InJ1bGVzIjp7Im5vLW5ldy1mdW5jIjpbImVycm9yIl19LCJsYW5ndWFnZU9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hRmVhdHVyZXMiOnt9fX19fQ==

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugESLint is working incorrectlyrepro:neededThis issue should include a reproducible example

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy