Skip to content

[no-implied-eval] False positive for ternary conditions like setTimeout(cond ? func1 : func2) #3099

Closed
@IceCreamYou

Description

@IceCreamYou
  • 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

module.exports = {
    "env": {
        "browser": true,
        "node": true,
    },
    "globals": {
        "name": "off",
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "tsconfigRootDir": __dirname,
        "project": "tsconfig.json",
    },
    "plugins": [
        "@typescript-eslint",
    ],
    "rules": {
        "@typescript-eslint/no-implied-eval": "error",
    },
};
setTimeout(Math.random() < 0.5 ? function a() { console.log('a'); } : function b() { console.log('b'); }, 0);
{
    "compilerOptions": {
        "target": "es6"
    },
    "include": [
        "index.ts"
    ]
}

Expected Result

The expression passed as the first parameter to setTimeout has the type () => void so I expected it to not raise an error from this linting rule that is supposed to detect strings.

Actual Result

.../eslint-eval-repro/index.ts
  1:12  error  Implied eval. Consider passing a function  @typescript-eslint/no-implied-eval

✖ 1 problem (1 error, 0 warnings)

Additional Info

  eslint:cli CLI args: [ '--debug', 'index.ts' ] +0ms
  eslint:cli Running on files +4ms
  eslintrc:config-array-factory Loading JSON config file: .../eslint-eval-repro/package.json +0ms
  eslintrc:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '.../eslint-eval-repro', loose: false } ] +0ms
  eslintrc:ignore-pattern   processed: { basePath: '.../eslint-eval-repro', patterns: [ '/**/node_modules/*' ] } +2ms
  eslintrc:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '.../eslint-eval-repro', loose: false } ] +1ms
  eslintrc:ignore-pattern   processed: { basePath: '.../eslint-eval-repro', patterns: [ '/**/node_modules/*' ] } +0ms
  eslint:file-enumerator Start to iterate files: [ 'index.ts' ] +0ms
  eslint:file-enumerator File: .../eslint-eval-repro/index.ts +1ms
  eslintrc:cascading-config-array-factory Load config files for .../eslint-eval-repro. +0ms
  eslintrc:cascading-config-array-factory No cache found: .../eslint-eval-repro. +0ms
  eslintrc:config-array-factory Loading JS config file: .../eslint-eval-repro/.eslintrc.js +6ms
  eslintrc:config-array-factory Config file found: .../eslint-eval-repro/.eslintrc.js +1ms
  eslintrc:config-array-factory Loading parser "@typescript-eslint/parser" from .../eslint-eval-repro/.eslintrc.js +0ms
  eslintrc:config-array-factory Loaded: @typescript-eslint/parser@4.15.2 (.../eslint-eval-repro/node_modules/@typescript-eslint/parser/dist/index.js) +1ms
  eslintrc:config-array-factory Loading plugin "@typescript-eslint" from .../eslint-eval-repro/.eslintrc.js +292ms
  eslintrc:config-array-factory Loaded: @typescript-eslint/eslint-plugin@4.15.2 (.../eslint-eval-repro/node_modules/@typescript-eslint/eslint-plugin/dist/index.js) +1ms
  eslintrc:config-array-factory Plugin .../eslint-eval-repro/node_modules/@typescript-eslint/eslint-plugin/dist/index.js loaded in: 189ms +189ms
  eslintrc:cascading-config-array-factory No cache found: .... +486ms
  eslintrc:config-array-factory Loading package.json config file: .../package.json +1ms
  eslintrc:config-array-factory Loading JSON config file: .../package.json +0ms
  eslintrc:config-array-factory Error reading package.json file: .../package.json +1ms
  eslintrc:config-array-factory Config file not found on ... +0ms
  eslintrc:cascading-config-array-factory No cache found: ... +1ms
  eslintrc:config-array-factory Config file not found on ... +0ms
  eslintrc:cascading-config-array-factory No cache found: ... +0ms
  eslintrc:cascading-config-array-factory Stop traversing because of considered root. +0ms
  eslintrc:cascading-config-array-factory Configuration was determined: ConfigArray(2) [ { type: 'config', name: 'DefaultIgnorePattern', filePath: '', criteria: null, env: undefined, globals: undefined, ignorePattern: IgnorePattern { patterns: [Array], basePath: '.../eslint-eval-repro', loose: false }, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { type: 'config', name: '.eslintrc.js', filePath: '.../eslint-eval-repro/.eslintrc.js', criteria: null, env: { browser: true, node: true }, globals: { name: 'off' }, ignorePattern: undefined, noInlineConfig: undefined, parser: { error: null, filePath: '.../eslint-eval-repro/node_modules/@typescript-eslint/parser/dist/index.js', id: '@typescript-eslint/parser', importerName: '.eslintrc.js', importerPath: '.../eslint-eval-repro/.eslintrc.js' }, parserOptions: { tsconfigRootDir: '.../eslint-eval-repro', project: 'tsconfig.json' }, plugins: { '@typescript-eslint': [Object] }, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: { '@typescript-eslint/no-implied-eval': 'error' }, settings: undefined } ] on .../eslint-eval-repro +2ms
  eslintrc:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '.../eslint-eval-repro', loose: false } ] +492ms
  eslintrc:ignore-pattern   processed: { basePath: '.../eslint-eval-repro', patterns: [ '/**/node_modules/*' ] } +1ms
  eslintrc:ignore-pattern Check {
  filePath: '.../eslint-eval-repro/index.ts',
  dot: false,
  relativePath: 'index.ts',
  result: false
} +0ms
  eslint:cli-engine Lint .../eslint-eval-repro/index.ts +0ms
  eslint:linter Linting code for .../eslint-eval-repro/index.ts (pass 1) +0ms
  eslint:linter Verify +0ms
  eslint:linter With ConfigArray: .../eslint-eval-repro/index.ts +0ms
  eslint:linter Generating fixed text for .../eslint-eval-repro/index.ts (pass 1) +706ms
  eslint:source-code-fixer Applying fixes +0ms
  eslint:source-code-fixer shouldFix parameter was false, not attempting fixes +0ms
  eslint:file-enumerator Complete iterating files: ["index.ts"] +1s
  eslint:cli-engine Linting complete in: 1201ms +707ms

Versions

package version
@typescript-eslint/eslint-plugin 4.15.2
@typescript-eslint/parser 4.15.2
TypeScript 4.1.5
ESLint 7.20.0
node 14.15.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions