Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: prevent space-before-function-paren from checking type annotations #8349

Merged
merged 2 commits into from Mar 31, 2017

Conversation

not-an-aardvark
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[x] Bug fix

Tell us about your environment

  • ESLint Version: master
  • Node Version: 7.7.4
  • npm Version: 4.1.2

What parser (default, Babel-ESLint, etc.) are you using?

babel-eslint

Please show your full configuration:

parser: babel-eslint
rules:
  space-before-function-paren: error

What did you do? Please include the actual source code causing the issue.

type TransformFunction = (el: ASTElement, code: string) => string;

What did you expect to happen?

I expected ESLint to not crash.

What actually happened? Please include the actual, raw output from ESLint.

ESLint crashed.

TypeError: Cannot read property 'range' of null
    at TokenStore.getTokenBefore (/path/to/eslint-canary/.downloaded-projects/vue/node_modules/eslint/lib/token-store/index.js:318:17)
    at EventEmitter.:function (/path/to/eslint-canary/.downloaded-projects/vue/node_modules/eslint/lib/rules/space-before-function-paren.js:116:46)
    at emitOne (events.js:96:13)
    at EventEmitter.emit (events.js:191:7)
    at NodeEventGenerator.applySelector (/path/to/eslint-canary/.downloaded-projects/vue/node_modules/eslint/lib/util/node-event-generator.js:265:26)
    at NodeEventGenerator.applySelectors (/path/to/eslint-canary/.downloaded-projects/vue/node_modules/eslint/lib/util/node-event-generator.js:292:22)
    at NodeEventGenerator.enterNode (/path/to/eslint-canary/.downloaded-projects/vue/node_modules/eslint/lib/util/node-event-generator.js:308:14)
    at CodePathAnalyzer.enterNode (/path/to/eslint-canary/.downloaded-projects/vue/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:602:23)
    at CommentEventGenerator.enterNode (/path/to/eslint-canary/.downloaded-projects/vue/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
    at Traverser.enter (/path/to/eslint-canary/.downloaded-projects/vue/node_modules/eslint/lib/eslint.js:929:36)

This was working in 3.18.0, but it broke due to 9b509ce.

What changes did you make? (Give an overview)

Previously, the space-before-function-paren rule's listener would be triggered for custom nodes such as FunctionTypeAnnotation, and would throw an error. This broke the regression build. This commit updates the rule to only listen for known function nodes.

Is there anything you'd like reviewers to focus on?

Nothing in particular

Previously, the space-before-function-paren rule's listener would be triggered for custom nodes such as `FunctionTypeAnnotation`, and would throw an error. This broke the regression build. This commit updates the rule to only listen for known function nodes.
@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules labels Mar 29, 2017
@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @btmills, @nzakas and @alberto to be potential reviewers.

@eslintbot
Copy link

LGTM

@ilyavolodin
Copy link
Member

I think at some point we need to figure out a better way to test those changes. Those fixtures are huge.

@not-an-aardvark
Copy link
Member Author

We could add babel-eslint as a devDependency for testing and have it handle the parsing on its own.

@@ -0,0 +1,525 @@
"use strict";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but would it make sense to name the folder tests/fixtures/parsers/babel/ instead? Or maybe we could clean up/re-organize the fixtures/parsers/ folder in a separate PR. I think it's a bit confusing now where to put parser fixtures.. related: https://github.com/eslint/eslint/pull/8297/files#diff-824f19921586246afb6f381021c34222

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I moved the fixture. I agree with reorganizing the folder in a separate PR.

@eslintbot
Copy link

LGTM

@not-an-aardvark not-an-aardvark merged commit 35c93e6 into master Mar 31, 2017
@not-an-aardvark not-an-aardvark deleted the space-before-function-paren-annotations branch March 31, 2017 18:43
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants