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

Converting type to VariableDeclaration causing issue with core indent rule #89

Closed
@JamesHenry

Description

@JamesHenry

Background

In 0.3.0 we added the conversion of type declarations, such as:

type Result<T> = Success<T> | Failure

...to VariableDeclaration ESTree nodes. The final ESTree nodes have an empty declarations: [] array property.

Issue

When using typescript-eslint-parser 0.3.0 with the core rule indent enabled, a runtime TypeError is thrown.

This is because the indent rule implementation does not check for a positive length of the declarations array before attempting to evaluate its final item.

From indent.js:

//...
VariableDeclaration(node) {
  if (node.declarations[node.declarations.length - 1].loc.start.line > node.declarations[0].loc.start.line) {
    checkIndentInVariableDeclarations(node);
  }
},
//...

Solution

IMHO, this is a bug in the core rule and it should be fixed there via a simple length check, but I wanted to report it here to get @nzakas thoughts before submitting a PR to ESLint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions