Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-undef] False positive with default argument in a class method #2956

Closed
3 tasks done
sk- opened this issue Jan 21, 2021 · 1 comment
Closed
3 tasks done

[no-undef] False positive with default argument in a class method #2956

sk- opened this issue Jan 21, 2021 · 1 comment
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@sk-
Copy link

sk- commented Jan 21, 2021

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "root": true,
  "parserOptions": {
    "ecmaVersion": 2018,
    "project": "./tsconfig.json"
  },
  "env": {
    "node": true,
    "es6": true
  },
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "rules": {
    "@typescript-eslint/await-thenable": "error",
    //"@typescript-eslint/no-floating-promises": "error",
    "@typescript-eslint/no-misused-promises": "error",
    //"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
    //"@typescript-eslint/no-unnecessary-condition": "error",
    "@typescript-eslint/prefer-includes": "error",
    "@typescript-eslint/prefer-string-starts-ends-with": "error",
    "@typescript-eslint/switch-exhaustiveness-check": "error"
  }
}
class A {
    /**
     * @param {Date} [date] If not specified, will use the current time
     * @return {Date}
     */
    test(date = new Date(Date.now())) {
        return date;
    }
}
{
  "compilerOptions": {
    "noEmit": true,
    "module": "commonjs",
    "target": "es2019",
    "lib": ["es2020"],
    "allowJs": true,
    "checkJs": true,
    "strict": true,
    "resolveJsonModule": true,
    // Reenable
    "noImplicitAny": false,
  },
  "include": [
    "**/*.js",
    "**/*.ts",
  ]
}

Expected Result

No no-undef error should be thrown.

Actual Result

functions/test.js
   6:31  error  'now' is not defined               no-undef

Additional Info

The check no-undef only triggers the error in class methods with default arguments. If I move the test function out of the class, then no exception is reported.

Versions

package version
@typescript-eslint/eslint-plugin 4.14.0
@typescript-eslint/parser 4.14.0
TypeScript 4.0.5
ESLint 7.18.0
node 14.13.1
@sk- sk- added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jan 21, 2021
@bradzacher
Copy link
Member

Same as #2941, #2942, #2945, #2947, #2950

Please use the search

@bradzacher bradzacher added duplicate This issue or pull request already exists and removed triage Waiting for maintainers to take a look labels Jan 21, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants