Skip to content

TypeError Cannot read property 'type' of null at ReturnStatement no-async-in-computed-properties #817

Closed
@axit-joost

Description

@axit-joost

Tell us about your environment

  • ESLint version: 5.13.0
  • eslint-plugin-vue version: 5.2.0
  • Node version: 10.2

Please show your full configuration:

{
    "extends": [
        "airbnb-base",
        "plugin:vue/recommended",
        "plugin:prettier/recommended",
        "prettier/vue"
    ],
    "env": {
        "browser": true,
        "node": true,
        "jasmine": true
    },
    "rules": {
        "prettierOptions": {
            "printWidth": 120
        },
        "no-underscore-dangle": 0
    }
}

What did you do?

It happened in two separate occasions during work. I am using vscode by the way, with the eslint extension.

  1. While specifying a Prop Type and its default value while typing, the TypeError occurs when defining default() { return ... }

  2. It also happened while refactoring old legacy code that had a return without a return value.

methods: {
  foo() {
    if (this.data.prop === 'someValue') return;
  }
}

What did you expect to happen?
No TypeError and continue linting process.

What actually happened?
TypeError and linting processing stopped with a stack trace.

Here's the stacktrace from the ESLint output of the vscode extension:

[Error - 4:12:58 PM] TypeError: Cannot read property 'type' of null
    at ReturnStatement (/Users/joost/Code/some-project/node_modules/eslint-plugin-vue/lib/rules/no-async-in-computed-properties.js:141:31)
    at listeners.(anonymous function).forEach.listener (/Users/joost/Code/some-project/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/joost/Code/some-project/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/joost/Code/some-project/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/Users/joost/Code/some-project/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (/Users/joost/Code/some-project/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (/Users/joost/Code/some-project/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)
    at nodeQueue.forEach.traversalInfo (/Users/joost/Code/some-project/node_modules/eslint/lib/linter.js:750:28)
    at Array.forEach (<anonymous>)

The offending code in the rules' source:

        'ReturnStatement' (node) {
          if (
                node.argument.type === 'ObjectExpression' ||
                node.argument.type === 'ArrayExpression'
          ) {
            allowedScopes.push(node.argument)
          }
        }

So if I am reading this correctly, argument appears to be null, hence the error?

It is always that portion of no-async-in-computed-properties rule, which would suggest it being some sort of issue with the computed properties. I had to comment out portions of that ugly legacy Vue component to target the offending code, which was the return; without a value.

But throughout the day, I got the same stacktrace occurring while adding PropTypes and their default values (as is recommended by 'plugin:vue/recommended')

Any ideas or suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions