palantir / tslint-react

:orange_book: Lint rules related to React & JSX for TSLint.
Apache License 2.0
749 stars 76 forks source link

bug: jsx-key rule issues #114

Closed Hotell closed 5 years ago

Hotell commented 7 years ago

packages:

Tslint will pass without errors, but console get's lots of TypeError messages.

This is mitigated by turning jsx-key off, "jsx-key": true, , but I wanna use that rule 👍

command:

tslint --project tsconfig.json --format codeFrame

console output:

TypeError: Cannot read property 'map' of undefined
    at hasKeyProp (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:96:9)
    at checkIteratorElement (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:87:42)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:68:21)
    at visitNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14197:20)
    at Object.forEachChild (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14333:24)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:83:19)
    at visitNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14197:20)
    at Object.forEachChild (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14544:21)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:83:19)
    at visitEachNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14209:30)
TypeError: Cannot read property 'map' of undefined
    at hasKeyProp (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:96:9)
    at checkIteratorElement (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:87:42)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:74:29)
    at visitNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14197:20)
    at Object.forEachChild (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14333:24)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:83:19)
    at visitNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14197:20)
    at Object.forEachChild (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14544:21)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:83:19)
    at visitEachNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14209:30)
TypeError: Cannot read property 'map' of undefined
    at hasKeyProp (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:96:9)
    at checkIteratorElement (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:87:42)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:68:21)
    at visitNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14197:20)
    at Object.forEachChild (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14333:24)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:83:19)
    at visitNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14197:20)
    at Object.forEachChild (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14419:24)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:83:19)
    at visitEachNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14209:30)
TypeError: Cannot read property 'map' of undefined
    at hasKeyProp (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:96:9)
    at checkIteratorElement (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:87:42)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:68:21)
    at visitNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14197:20)
    at Object.forEachChild (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14333:24)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:83:19)
    at visitNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14197:20)
    at Object.forEachChild (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14373:21)
    at cb (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/tslint-react/rules/jsxKeyRule.js:83:19)
    at visitNode (/mnt/c/Users/hoche/Documents/Devel/embedit/lossevents-ui/node_modules/typescript/lib/typescript.js:14197:20)

tslint.json:

{
  "extends": [
    "tslint-react"
  ],
  "jsRules": {},
  "rulesDirectory": [],
  "rules": {
    // override tslint-react rules
    "jsx-boolean-value": [
      true,
      "never"
    ],
    "jsx-key": true,
    // this should be in tslint-prettier
    "jsx-equals-spacing": false,
    // override tsling-config-standard
    "no-use-before-declare": false,
    // our core ts-lint rules
    "prefer-template": true,
    "forin": true,
    "no-bitwise": true,
    "no-console": [
      true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-construct": true,
    "no-debugger": true,
    "no-shadowed-variable": true,
    "no-string-literal": true,
    "no-unnecessary-initializer": true,
    "no-magic-numbers": true,
    "no-require-imports": true,
    "no-duplicate-super": true,
    "no-boolean-literal-compare": true,
    "no-invalid-this": [
      true,
      "check-function-in-method"
    ],
    "no-duplicate-imports": true,
    "ordered-imports": [
      true
    ],
    "newline-before-return": true,
    "object-literal-shorthand": true,
    "typeof-compare": true,
    "arrow-return-shorthand": [
      true
    ],
    "prefer-object-spread": true,
    "prefer-for-of": true,
    "prefer-const": true,
    "prefer-method-signature": true,
    // TS specific types rules
    "no-inferrable-types": [
      true
    ],
    "callable-types": true,
    "no-namespace": [
      true,
      "allow-declarations"
    ],
    "interface-name": [
      false
    ],
    "ban-types": [
      true,
      [
        "Object",
        "Avoid using the `Object` type. Did you mean `object`?"
      ],
      [
        "Function",
        "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."
      ],
      [
        "Boolean",
        "Avoid using the `Boolean` type. Did you mean `boolean`?"
      ],
      [
        "Number",
        "Avoid using the `Number` type. Did you mean `number`?"
      ],
      [
        "String",
        "Avoid using the `String` type. Did you mean `string`?"
      ],
      [
        "Symbol",
        "Avoid using the `Symbol` type. Did you mean `symbol`?"
      ],
      [
        "Array",
        "Avoid using the `Array<T>` type. Use 'type[]' instead."
      ]
    ]
  }
}

tsconfig:

{
  "compilerOptions": {
    "module": "es2015",
    "target": "es5",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "noImplicitThis": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "sourceMap": true,
    "importHelpers": true,
    "noEmitHelpers": true,
    "experimentalDecorators": true,
    "jsx": "react",
    "allowJs": true,
    "jsxFactory": "h",
    "pretty": true,
    "skipLibCheck": true,
    "baseUrl": ".",
    "rootDir": "./",
    "outDir": "ts-output",
    "typeRoots": [
      "node_modules/@types",
      "manual_typings"
    ],
    "paths": {
      "custom_modules/*": [
        "src/custom_modules/*"
      ],
      "preact": [
        "manual_typings/preact"
      ],
      "react": [
        "manual_typings/preact"
      ],
      "react-redux": [
        "manual_typings/react-redux"
      ],
      "react-i18next": [
        "manual_typings/react-i18next"
      ]
    },
    "lib": [
      "dom",
      "es5",
      "es2015",
      "es2016.array.include"
    ]
  },
  "include": [
    "manual_typings",
    "src"
  ],
  "exclude": [
    "node_modules"
  ]
}
jkillian commented 6 years ago

@Hotell is this still an issue for you? If so, can you give an example of a file that makes this happen?

adidahiya commented 5 years ago

closing as stale