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

TypeError: Cannot read property 'param' of undefined #4326

Closed
its-jman opened this issue Nov 28, 2018 · 6 comments · Fixed by #4895
Closed

TypeError: Cannot read property 'param' of undefined #4326

its-jman opened this issue Nov 28, 2018 · 6 comments · Fixed by #4895

Comments

@its-jman
Copy link

its-jman commented Nov 28, 2018

Bug Report

  • TSLint version: 5.11.0
  • TypeScript version: 3.1.6
  • Running TSLint via: CLI

TypeScript code being linted

The error is thrown in each file which contains a jsdoc. Removing the jsdoc clears the error that was thrown.

// Snippet who's existence introduces the error.
/**
 *
 * @returns {Promise<Object>}
 */
export const handler = async () => { ... }
// Snippet where no error occurs (But completed-docs correctly gives an error on the lack of jsdoc).
export const handler = async () => { ... }

with tslint.json configuration:

"completed-docs": [
      true,
      { 
        "variables": { 
          "visibilities": ["exported"], 
          "tags": { "existence": [""] } 
        } 
      }
    ]
Full config:
{
  "extends": ["tslint:all", "tslint-eslint-rules", "tslint-config-prettier"],
  "defaultSeverity": "error",
  "jsRules": {
    "prefer-for-of": true,
    "completed-docs": [
      true,
      { "variables": { "visibilities": ["exported"], "tags": { "existence": ["ap"] } } }
    ],
    "valid-jsdoc": [
      true,
      {
        "prefer": {
          "return": "returns"
        },
        "requireReturn": false,
        "requireParamDescription": false,
        "requireReturnDescription": false
      }
    ],
    "no-null-keyword": false,
    "comment-format": false,
    "object-literal-sort-keys": false,
    "ordered-imports": false,
    "newline-before-return": false,
    "object-literal-shorthand": false,
    "no-submodule-imports": false,
    "arrow-return-shorthand": false,
    "radix": false,
    "no-empty": false,
    "no-console": false,
    "no-import-side-effect": false,
    "no-magic-numbers": false,
    "curly": false,
    "forin": false,
    "no-trailing-whitespace": false
  }
}

Actual behavior

The error is thrown in each file which contains a jsdoc. Removing the jsdoc clears the error that was thrown (but introduces a proper error for a missing jsdoc.) This invalid behavior only occurs when "tags": { "existence": [""] } is present in the config.

The 'completed-docs' rule threw an error in '/home/test/repos/api/src/utils.js':
TypeError: Cannot read property 'param' of undefined
    at TagExclusion.excludes (/home/test/repos/api/node_modules/tslint/lib/rules/completed-docs/tagExclusion.js:42:47)
    at checkNode (/home/test/repos/api/node_modules/tslint/lib/rules/completedDocsRule.js:306:27)
    at cb (/home/test/repos/api/node_modules/tslint/lib/rules/completedDocsRule.js:282:29)
    at visitNodes (/home/test/repos/api/node_modules/typescript/lib/typescript.js:15788:30)
    at Object.forEachChild (/home/test/repos/api/node_modules/typescript/lib/typescript.js:16016:24)
    at walk (/home/test/repos/api/node_modules/tslint/lib/rules/completedDocsRule.js:239:15)
    at Rule.AbstractRule.applyWithFunction (/home/test/repos/api/node_modules/tslint/lib/language/rule/abstractRule.js:39:9)
    at Rule.applyWithProgram (/home/test/repos/api/node_modules/tslint/lib/rules/completedDocsRule.js:59:21)
    at Linter.applyRule (/home/test/repos/api/node_modules/tslint/lib/linter.js:194:29)
    at /home/test/repos/api/node_modules/tslint/lib/linter.js:139:85

Expected behavior

I would expect for this this configuration to give proper "Documentation must exist..." errors for any exported variable that doesn't have a jsdoc. An empty jsdoc should give no errors (as I am doing validation with a separate rule). Disabling other rules does not change the error.

Correction: "Documentation must exist..." error is still thrown on a completely empty /** ... */, the TypeError occurs once JSDoc rules are added in such as @returns or @param

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Dec 3, 2018

This might be fixed already by #3557 (or by one of the completed-docs fixers already merged into master)... marking this as a bug & accepting PRs in case someone can give a quick little fix not already implemented!

@its-jman
Copy link
Author

its-jman commented Dec 3, 2018

It's still an issue building from master, but I wasn't able to test from that PR.

@JoshuaKGoldberg
Copy link
Contributor

Awesome, thanks for checking!

@christophercr
Copy link

christophercr commented Apr 17, 2019

Any news about this issue? In my case I have the error when I use @internal in the JSDoc:

The 'completed-docs' rule threw an error in 'C:/LocalData/DEV/WORKSPACE/stark-monorepo-master/packages/stark-ui/src/modules/progress-indicator/entities/progress-indicator-full-config.entity.intf.ts':
TypeError: Cannot read property 'internal' of undefined
    at TagExclusion.excludes (C:\LocalData\DEV\WORKSPACE\stark-monorepo-master\node_modules\tslint\lib\rules\completed-docs\tagExclusion.js:40:47)
    at nodeIsExcluded (C:\LocalData\DEV\WORKSPACE\stark-monorepo-master\node_modules\tslint\lib\rules\completedDocsRule.js:319:29)
    at checkNode (C:\LocalData\DEV\WORKSPACE\stark-monorepo-master\node_modules\tslint\lib\rules\completedDocsRule.js:295:14)
    at cb (C:\LocalData\DEV\WORKSPACE\stark-monorepo-master\node_modules\tslint\lib\rules\completedDocsRule.js:250:17)
    at visitNodes (C:\LocalData\DEV\WORKSPACE\stark-monorepo-master\node_modules\typescript\lib\typescript.js:16144:30)
    at Object.forEachChild (C:\LocalData\DEV\WORKSPACE\stark-monorepo-master\node_modules\typescript\lib\typescript.js:16372:24)
    at walk (C:\LocalData\DEV\WORKSPACE\stark-monorepo-master\node_modules\tslint\lib\rules\completedDocsRule.js:231:15)
    at Rule.AbstractRule.applyWithFunction (C:\LocalData\DEV\WORKSPACE\stark-monorepo-master\node_modules\tslint\lib\language\rule\abstractRule.js:39:9)
    at Rule.apply (C:\LocalData\DEV\WORKSPACE\stark-monorepo-master\node_modules\tslint\lib\rules\completedDocsRule.js:59:21)
    at Linter.applyRule (C:\LocalData\DEV\WORKSPACE\stark-monorepo-master\node_modules\tslint\lib\linter.js:214:29)

However the error is thrown only if the @internal is on the JSDoc of an interface... it works fine on classes.

@ChaiWithJai
Copy link
Contributor

grabbing this @JoshuaKGoldberg

@ChaiWithJai
Copy link
Contributor

@JoshuaKGoldberg @adidahiya submitted a PR for this. #4895

I may be failing on Circle because of it says I need to write documentation for test/rules/completed-docs/defaults/edge-case/test.ts.lint

` export const handler = async () => { ... }

  •          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Documentation must exist for exported variables.]`
    

JoshuaKGoldberg pushed a commit that referenced this issue Dec 8, 2019
* creating rule

* rule written

* rule replicated

* isolated rule

* added test files back in

* captured case of this.contentTags being undefined

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

Successfully merging a pull request may close this issue.

4 participants