Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

no-undef: false flag on typeof argument types #557

Closed
balupton opened this issue Nov 21, 2018 · 3 comments
Closed

no-undef: false flag on typeof argument types #557

balupton opened this issue Nov 21, 2018 · 3 comments
Labels

Comments

@balupton
Copy link

What version of TypeScript are you using?
3.1.6

What version of typescript-eslint-parser are you using?
21.0.1

What code were you trying to parse?

interface IteratorCallback<Subject, Key, Value> {
	(this: Subject, value: Value, key: Key, subject: Subject): void | false
}
function eachr<Value>(subject: Array<Value>, callback: IteratorCallback<typeof subject, number, Value>): typeof subject;
function eachr<Key, Value>(subject: Map<Key, Value>, callback: IteratorCallback<typeof subject, Key, Value>): typeof subject;
function eachr<Object extends object, Key extends keyof Object>(subject: Object, callback: IteratorCallback<Object, Key, Object[Key]>): Object;
function eachr<Object extends object, Key, Value> (subject: Object | Array<Value> | Map<Key, Value>, callback: IteratorCallback<typeof subject, Key, Value>): typeof subject {
	return subject
}

export default eachr

What did you expect to happen?
Just get back:

  7:102  warning  'callback' is defined but never used  no-unused-vars

What happened?

Got back no-undef errors:

  4:80   error    'subject' is not defined              no-undef
  4:113  error    'subject' is not defined              no-undef
  5:88   error    'subject' is not defined              no-undef
  5:118  error    'subject' is not defined              no-undef
  7:102  warning  'callback' is defined but never used  no-unused-vars

Here is the .eslintrc:

{ extends: [ 'eslint:recommended' ],
  plugins: [ 'typescript', 'babel' ],
  parserOptions:
   { ecmaFeatures: { jsx: false },
     sourceType: 'module',
     ecmaVersion: 5 },
  env:
   { es6: false,
     node: true,
     browser: true,
     commonjs: true,
     'shared-node-browser': true },
  rules:
   { 'no-cond-assign': [ 2, 'always' ],
     'no-console': 1,
     'no-constant-condition': 1,
     'no-control-regex': 2,
     'no-debugger': 1,
     'no-dupe-args': 2,
     'no-dupe-keys': 2,
     'no-duplicate-case': 2,
     'no-empty': 0,
     'no-empty-character-class': 2,
     'no-ex-assign': 2,
     'no-extra-boolean-cast': 2,
     'no-extra-parens': 0,
     'no-extra-semi': 2,
     'no-func-assign': 2,
     'no-inner-declarations': 2,
     'no-invalid-regexp': 2,
     'no-irregular-whitespace': 2,
     'no-obj-calls': 2,
     'no-prototype-builtins': 0,
     'no-regex-spaces': 2,
     'no-sparse-arrays': 2,
     'no-template-curly-in-string': 1,
     'no-unexpected-multiline': 2,
     'no-unreachable': 2,
     'no-unsafe-finally': 2,
     'no-unsafe-negation': 2,
     'use-isnan': 2,
     'valid-jsdoc':
      [ 2,
        { requireParamDescription: false,
          requireReturnDescription: false } ],
     'valid-typeof': 2,
     'accessor-pairs': 0,
     'array-callback-return': 2,
     'block-scoped-var': 0,
     'class-methods-use-this': 1,
     complexity: 0,
     'consistent-return': 0,
     curly: [ 2, 'multi-line' ],
     'default-case': 2,
     'dot-location': [ 2, 'property' ],
     'dot-notation': 2,
     eqeqeq: [ 2, 'allow-null' ],
     'guard-for-in': 2,
     'no-alert': 1,
     'no-caller': 2,
     'no-case-declarations': 2,
     'no-div-regex': 2,
     'no-else-return': 0,
     'no-empty-function': 0,
     'no-empty-pattern': 2,
     'no-eq-null': 0,
     'no-eval': 2,
     'no-extend-native': 2,
     'no-extra-bind': 2,
     'no-extra-label': 2,
     'no-fallthrough': 2,
     'no-floating-decimal': 2,
     'no-global-assign': 2,
     'no-implicit-coercion': 2,
     'no-implicit-globals': 2,
     'no-implied-eval': 2,
     'no-invalid-this': 0,
     'no-iterator': 2,
     'no-labels': 2,
     'no-lone-blocks': 2,
     'no-loop-func': 2,
     'no-magic-numbers': 0,
     'no-multi-spaces': 0,
     'no-multi-str': 2,
     'no-new-func': 2,
     'no-new-wrappers': 2,
     'no-new': 2,
     'no-octal-escape': 2,
     'no-octal': 2,
     'no-param-reassign': 0,
     'no-proto': 2,
     'no-redeclare': 2,
     'no-restricted-properties': 0,
     'no-return-assign': 2,
     'no-script-url': 2,
     'no-self-assign': 2,
     'no-self-compare': 2,
     'no-sequences': 2,
     'no-throw-literal': 2,
     'no-unmodified-loop-condition': 1,
     'no-unused-expressions': 2,
     'no-unused-labels': 2,
     'no-useless-call': 2,
     'no-useless-concat': 2,
     'no-useless-escape': 2,
     'no-void': 2,
     'no-warning-comments': [ 1, { terms: [ 'todo', 'fixme' ], location: 'anywhere' } ],
     'no-with': 2,
     radix: 2,
     'vars-on-top': 0,
     'wrap-iife': 2,
     yoda: [ 2, 'never' ],
     strict: [ 2, 'global' ],
     'init-declarations': 0,
     'no-catch-shadow': 0,
     'no-delete-var': 2,
     'no-label-var': 2,
     'no-restricted-globals': 0,
     'no-shadow-restricted-names': 2,
     'no-shadow': 0,
     'no-undef-init': 2,
     'no-undef': 2,
     'no-undefined': 2,
     'no-unused-vars': 1,
     'no-use-before-define': 2,
     'callback-return': 0,
     'global-require': 0,
     'handle-callback-err': 2,
     'no-mixed-requires': 2,
     'no-new-require': 2,
     'no-path-concat': 2,
     'no-process-env': 0,
     'no-process-exit': 0,
     'no-restricted-modules': 0,
     'no-sync': 1,
     'array-bracket-spacing': [ 2, 'never' ],
     'block-spacing': [ 2, 'always' ],
     'brace-style': [ 2, 'stroustrup', { allowSingleLine: true } ],
     camelcase: 2,
     'comma-dangle': [ 2, 'never' ],
     'comma-spacing': [ 2, { before: false, after: true } ],
     'comma-style': [ 2, 'last' ],
     'computed-property-spacing': [ 2, 'never' ],
     'consistent-this': 0,
     'eol-last': 2,
     'func-call-spacing': [ 2, 'never' ],
     'func-name-matching': 0,
     'func-names': 0,
     'func-style': [ 1, 'declaration' ],
     'id-blacklist': 0,
     'id-length': 0,
     'id-match': 0,
     indent:
      [ 2,
        'tab',
        { SwitchCase: 1,
          VariableDeclarator: 0,
          outerIIFEBody: 1,
          MemberExpression: 1,
          FunctionDeclaration: { body: 1, parameters: 0 },
          FunctionExpression: { body: 1, parameters: 0 } } ],
     'jsx-quotes': [ 2, 'prefer-double' ],
     'key-spacing': [ 2, { beforeColon: false, afterColon: true } ],
     'keyword-spacing': [ 2 ],
     'line-comment-position': 0,
     'linebreak-style': [ 2, 'unix' ],
     'lines-around-comment': [ 2, { beforeBlockComment: true, allowBlockStart: true } ],
     'lines-around-directive': [ 2, { before: 'never', after: 'always' } ],
     'max-depth': 0,
     'max-len': 0,
     'max-lines': 0,
     'max-nested-callbacks': 0,
     'max-params': [ 1, 4 ],
     'max-statements-per-line': [ 1, { max: 1 } ],
     'max-statements': 0,
     'multiline-ternary': 0,
     'new-cap': 0,
     'new-parens': 2,
     'newline-after-var': 0,
     'newline-per-chained-call': 0,
     'no-array-constructor': 2,
     'no-bitwise': 2,
     'no-continue': 0,
     'no-inline-comments': 0,
     'no-lonely-if': 2,
     'no-mixed-operators': 2,
     'no-mixed-spaces-and-tabs': 2,
     'no-multiple-empty-lines': 0,
     'no-negated-condition': 0,
     'no-nested-ternary': 0,
     'no-new-object': 2,
     'no-plusplus': 0,
     'no-restricted-syntax': 0,
     'no-tabs': 0,
     'no-ternary': 0,
     'no-trailing-spaces': 2,
     'no-underscore-dangle': 0,
     'no-unneeded-ternary': 2,
     'no-whitespace-before-property': 2,
     'object-curly-newline': [ 0, { multiline: true } ],
     'object-curly-spacing': 0,
     'one-var': 0,
     'one-var-declaration-per-line': 0,
     'operator-assignment': [ 2, 'always' ],
     'operator-linebreak': 0,
     'padded-blocks': 0,
     'quote-props': [ 2, 'consistent-as-needed' ],
     quotes: [ 2, 'single', 'avoid-escape' ],
     'require-jsdoc': 0,
     'semi-spacing': [ 2, { before: false, after: true } ],
     semi: [ 2, 'never' ],
     'sort-keys': 0,
     'sort-vars': 0,
     'space-before-blocks': [ 2, 'always' ],
     'space-before-function-paren': [ 2, 'always' ],
     'space-in-parens': 0,
     'space-infix-ops': 2,
     'space-unary-ops': 2,
     'spaced-comment': 2,
     'unicode-bom': [ 2, 'never' ],
     'wrap-regex': 2,
     'arrow-body-style': [ 2, 'as-needed' ],
     'arrow-parens': [ 2, 'always' ],
     'arrow-spacing': 2,
     'constructor-super': 2,
     'generator-star-spacing': [ 2, 'before' ],
     'no-class-assign': 2,
     'no-confusing-arrow': 2,
     'no-const-assign': 2,
     'no-dupe-class-members': 2,
     'no-duplicate-imports': 1,
     'no-new-symbol': 2,
     'no-restricted-imports': 0,
     'no-this-before-super': 2,
     'no-useless-computed-key': 2,
     'no-useless-constructor': 2,
     'no-useless-rename': 2,
     'no-var': 0,
     'object-shorthand': [ 2, 'never' ],
     'prefer-arrow-callback': 0,
     'prefer-const': 0,
     'prefer-numeric-literals': 2,
     'prefer-reflect': 0,
     'prefer-rest-params': 0,
     'prefer-spread': 0,
     'prefer-template': 0,
     'require-yield': 2,
     'rest-spread-spacing': [ 2, 'never' ],
     'sort-imports': 0,
     'symbol-description': 2,
     'template-curly-spacing': [ 2, 'never' ],
     'yield-star-spacing': [ 2, 'both' ],
     'babel/new-cap': 2,
     'babel/object-curly-spacing': 0 },
  parser: 'typescript-eslint-parser' }

The dev deps:

  "devDependencies": {
    "@babel/cli": "^7.1.5",
    "@babel/core": "^7.1.6",
    "@babel/plugin-proposal-class-properties": "^7.1.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
    "@babel/preset-env": "^7.1.6",
    "@babel/preset-typescript": "^7.1.0",
    "eslint": "^5.9.0",
    "eslint-plugin-babel": "^5.3.0",
    "eslint-plugin-typescript": "^0.13.0",
    "typescript": "^3.1.6",
    "typescript-eslint-parser": "^21.0.1"
  },

And the eslint run:

npx eslint --fix './source/**
@mysticatea
Copy link
Member

Thank you for this report.

Looks like a bug about function declarations which don't have their body.
typescript-eslint-parser should make the function scope and parameter's variables even if the body is nothing, but not.

@bfmiv
Copy link

bfmiv commented Dec 21, 2018

FYI, this happens with index signatures in class properties as well:

export default class Foo {
    [key: string]: any;
}
2:6  error  'key' is not defined  no-undef

@JamesHenry
Copy link
Member

This issue has been migrated to the new project here: typescript-eslint/typescript-eslint#18

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants