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

space-before-function-paren doesn't detect anonymously exported function correctly #3040

Closed
Ky6uk opened this issue Jul 13, 2017 · 6 comments · Fixed by #3053
Closed

space-before-function-paren doesn't detect anonymously exported function correctly #3040

Ky6uk opened this issue Jul 13, 2017 · 6 comments · Fixed by #3053

Comments

@Ky6uk
Copy link

Ky6uk commented Jul 13, 2017

Bug Report

  • TSLint version: v5.5.0
  • TypeScript version: v2.4.1
  • Running TSLint via: Atom / CLI

TypeScript code being linted

export default function () {
  return;
}

with tslint.json configuration:

{
  "extends": "tslint:latest",

  "rules": {
    "ordered-imports": false,
    "object-literal-sort-keys": false,
    "only-arrow-functions": false,

    "interface-name": [true, "never-prefix"],
    "quotemark": [true, "single", "jsx-double"],
    "trailing-comma": [true, "never"],

    "space-before-function-paren": [true, {
      "anonymous": "always",
      "asyncArrow": "always",
      "constructor": "never",
      "method": "never",
      "named": "never"
    }]
  }
}

Actual behavior

Got the error Spaces before function parens are disallowed.

Expected behavior

No error expected here.

@ajafff
Copy link
Contributor

ajafff commented Jul 14, 2017

exported function declarations cannot be anonymous, the grammar doesn't allow that. You should get an error from the typescript compiler. That's why tslint treats this function as "named".

@Ky6uk
Copy link
Author

Ky6uk commented Jul 14, 2017

@ajafff but this is correct TS code with some compiler flags. I think TSLint should handle that. Correct me if I am wrong.

@ajafff
Copy link
Contributor

ajafff commented Jul 14, 2017

What flag(s) do you mean? I haven't noticed anything like this before...

@Ky6uk
Copy link
Author

Ky6uk commented Jul 14, 2017

Sorry. That's working w/o any flags. I updated my first message.

https://www.typescriptlang.org/docs/handbook/modules.html

Classes and function declarations can be authored directly as default exports.
Default export class and function declaration names are optional.

@ajafff
Copy link
Contributor

ajafff commented Jul 14, 2017

Yeah, the default export makes sense. This is a bug. It should be handled like other anonymous functions.

@IllusionMH
Copy link
Contributor

Looks like I found fix, but can't run yarn test on Windows at this moment.
Will send PR in the evening.

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

Successfully merging a pull request may close this issue.

3 participants