Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

use-before-declare: false positive in destructuring assignment #2551

Closed
tamird opened this issue Apr 11, 2017 · 11 comments
Closed

use-before-declare: false positive in destructuring assignment #2551

tamird opened this issue Apr 11, 2017 · 11 comments

Comments

@tamird
Copy link

tamird commented Apr 11, 2017

Bug Report

  • TSLint version:
yarn run tslint -- --version
yarn run v0.22.0
$ "/Users/tamird/src/go/src/github.com/cockroachdb/cockroach/pkg/ui/node_modules/.bin/tslint" --version
5.1.0
✨  Done in 0.44s.
  • TypeScript version:
yarn run tsc -- --version
yarn run v0.22.0
$ "/Users/tamird/src/go/src/github.com/cockroachdb/cockroach/pkg/ui/node_modules/.bin/tsc" --version
Version 2.3.0
✨  Done in 0.29s.
  • Running TSLint via: (pick one) CLI / Node.js API / VSCode / grunt-tslint / Atom / Visual Studio / etc
$ "/Users/tamird/src/go/src/github.com/cockroachdb/cockroach/pkg/ui/node_modules/.bin/tslint" -c tslint.json -p tsconfig.json --type-check

TypeScript code being linted

const { key: saveErrorKey, error: saveError } = (action as PayloadAction<KeyedError>).payload;

with tslint.json configuration:

{
  "rules": {
    "align": [
      true,
      "parameters",
      "arguments",
      "statements"
    ],
    "ban": false,
    "class-name": true,
    "comment-format": [
      true,
      "check-space"
    ],
    "curly": true,
    "eofline": true,
    "forin": true,
    "indent": [
      true,
      "spaces"
    ],
    "interface-name": false,
    "jsdoc-format": true,
    "label-position": true,
    "max-line-length": [
      false,
      140
    ],
    "member-ordering": [
      true,
      "public-before-private",
      "static-before-instance",
      "variables-before-functions"
    ],
    "no-any": false,
    "no-arg": true,
    "no-bitwise": true,
    "no-console": [
      true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-consecutive-blank-lines": true,
    "no-construct": true,
    "no-parameter-properties": false,
    "no-debugger": true,
    "no-duplicate-variable": true,
    "no-shadowed-variable": true,
    "no-empty": false,
    "no-eval": true,
    "no-require-imports": false,
    "no-string-literal": true,
    "no-switch-case-fall-through": true,
    "trailing-comma": [true, {
        "multiline": "always",
        "singleline": "never"
    }],
    "no-trailing-whitespace": true,
    "no-unused-expression": true,
    "no-use-before-declare": true,
    "no-var-keyword": true,
    "no-var-requires": true,
    "one-line": [
      true,
      "check-catch",
      "check-else",
      "check-open-brace",
      "check-whitespace"
    ],
    "quotemark": [
      true,
      "double"
    ],
    "radix": true,
    "semicolon": true,
    "switch-default": true,
    "triple-equals": [
      true,
      "allow-null-check"
    ],
    "typedef": [
      false,
      "call-signature",
      "parameter",
      "property-declaration"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      }
    ],
    "variable-name": [
      true,
      "allow-leading-underscore"
    ],
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ]
  }
}

Actual behavior

ERROR: /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/pkg/ui/src/redux/uiData.ts[92, 15]: variable 'key' used before declaration
ERROR: /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/pkg/ui/src/redux/uiData.ts[92, 34]: variable 'error' used before declaration
ERROR: /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/pkg/ui/src/redux/uiData.ts[109, 15]: variable 'key' used before declaration
ERROR: /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/pkg/ui/src/redux/uiData.ts[109, 34]: variable 'error' used before declaration

Expected behavior

Clean.

@ghost
Copy link

ghost commented Apr 28, 2017

I just ran into this as well.

@sberan
Copy link

sberan commented May 11, 2017

I have a minimal reproduction:

export function foo ({ param: p }: { param: any }) {
}

@sberan
Copy link

sberan commented May 11, 2017

Any aliasing of the destructured param seems to trigger the issue.

@kalahari
Copy link

Is "no-use-before-declare": false the best work-around? The documentation suggest it is only useful for var keyword variables anyway.

@mabdullahsari
Copy link

This issue is still present, happened to me just now. Good stuff!

@piotros
Copy link

piotros commented Jun 21, 2018

Problem still occurs.

@zheeeng
Copy link

zheeeng commented Jul 3, 2018

Still exists

@lselbeck
Copy link

Without typescript I have no errors:
const { email: user1Email, name: user1Name } = user1

With typescript, I get the false positive:
const { email: user1Email, name: user1Name }: { email: string, name: string } = user1

@Krumpet
Copy link

Krumpet commented Nov 11, 2018

Error still occurs, the 'variables' used before declaration in const { label: l, shortcut: s } are label and shortcut.

@JeanMeche
Copy link

Same problem !

@adidahiya
Copy link
Contributor

This rule is essentially deprecated... check out the documentation https://palantir.github.io/tslint/rules/no-use-before-declare/

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

No branches or pull requests

10 participants