Thanks to visit codestin.com
Credit goes to github.com

Skip to content

arrow-parens: false positive for generic arrow function #14

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

Closed
JamesHenry opened this issue Jan 15, 2019 · 8 comments · Fixed by #432 or #176
Closed

arrow-parens: false positive for generic arrow function #14

JamesHenry opened this issue Jan 15, 2019 · 8 comments · Fixed by #432 or #176
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@JamesHenry
Copy link
Member

This issue was initially reported here: eslint/typescript-eslint-parser#475


What version of TypeScript are you using?
2.8.3

What version of typescript-eslint-parser are you using?
15.0.0

What code were you trying to parse?

// Unexpected error: arrow-parens
const bar = <T>(t: T) => {};
// No error as expected
const bar2 = function <T>(t: T) {};
@JamesHenry JamesHenry added the package: parser Issues related to @typescript-eslint/parser label Jan 18, 2019
@bradzacher bradzacher added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin migration-test and removed package: parser Issues related to @typescript-eslint/parser labels Jan 18, 2019
@jhoch
Copy link

jhoch commented Feb 28, 2019

@JamesHenry @armano2 I'm still seeing this on version 1.4.2. I have a file in my repo called components/util/test.ts:

const foo = <T>(bar: any): void => {
  // Do nothing
}

which produces the following when I run eslint:

jasonhoch@hoch1:~/code/newfront-app
15:34:48$ yarn eslint components/util/test.ts
yarn run v1.13.0
$ /Users/jasonhoch/code/newfront-app/node_modules/.bin/eslint components/util/test.ts

/Users/jasonhoch/code/newfront-app/components/util/test.ts
  1:7   warning  'foo' is assigned a value but never used                                             @typescript-eslint/no-unused-vars
  1:13  error    Expected parentheses around arrow function argument having a body with curly braces  arrow-parens
  1:17  warning  'bar' is defined but never used                                                      @typescript-eslint/no-unused-vars
  1:22  warning  Unexpected any. Specify a different type                                             @typescript-eslint/no-explicit-any
  3:2   error    Missing semicolon                                                                    semi

✖ 5 problems (2 errors, 3 warnings)
  2 errors and 0 warnings potentially fixable with the `--fix` option.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

(See the error at 1:13). Here is my .eslintrc.js file:

module.exports = {
    'extends': [
      'airbnb',
      'plugin:@typescript-eslint/recommended',
    ],
    'env': {
      'jest': true,
    },
    'overrides': [{
      'files': ['*.ts', '*.tsx'],
      'rules': {
        'indent': 'off', // Conflicts
        'semi': ['error', 'always'], // Conflicts
      },
    }],
    'parser': '@typescript-eslint/parser',
    'parserOptions': {
      'project': './tsconfig.json',
    },
    'plugins': [
      '@typescript-eslint',
      'import',
    ],
    'rules': {
      'arrow-body-style': ['off'],
      'jsx-a11y/anchor-is-valid': ['error', {
        'components': ['Link'],
        'aspects': ['invalidHref', 'preferButton'],
      }],
      'jsx-quotes': ['warn', 'prefer-single'],
      'react/jsx-filename-extension': ['warn', { 'extensions': ['.js', '.jsx', '.tsx'] }],
      'react/jsx-closing-tag-location': ['off'],
      'react/jsx-curly-brace-presence': ['error', { 'props': 'never', 'children': 'ignore' } ],
      'react/jsx-one-expression-per-line': ['off'],
      'react/prop-types': ['off'],
      'semi': ['warn', 'never'],
      '@typescript-eslint/explicit-function-return-type': ['warn', { 'allowExpressions': true }],
      '@typescript-eslint/indent': ['error', 2],
    },
    'settings': {
      'import/resolver': {
        'typescript': {},
      },
    },
}

and the lines in my package.json:

"devDependencies": {
    ...
    "@typescript-eslint/eslint-plugin": "^1.4.2",
    "@typescript-eslint/parser": "^1.4.2",
    ...
}

We've had a smooth experience moving over from TSLint, with this one glitch. Looking at #176, it looks like you guys test for this case. Any idea what the problem could be? Let me know if I can help!

@armano2 armano2 reopened this Feb 28, 2019
bradzacher added a commit that referenced this issue Apr 15, 2019
Also fix up the regex for vscode launching eslint-plugin tests so it matches all tests
Closes #14
@jinasonlin
Copy link

jinasonlin commented May 10, 2019

I still get false positive.

@typescript-eslint/parser version

1.7.1-alpha-28

rule

"arrow-parens" : ["as-needed", { "requireForBlockBody": true }]

// Expected parentheses around arrow function argument having a body with curly braces.eslint(arrow-parens)
const foo = <T>(t: T): void => { console.info(t); }

// the following is correct
const foo = (t) => { console.info(t); }

@bradzacher bradzacher reopened this May 10, 2019
@bradzacher
Copy link
Member

You have the missing piece of the puzzle!
The config that causes it to fail!

@bradzacher bradzacher added the enhancement: new base rule extension New base rule extension required to handle a TS specific case label May 10, 2019
@tinymins
Copy link

I've the same problem, when will this problem get fixed and published?

@tinymins
Copy link

tinymins commented May 30, 2019

image

"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-import-resolver-webpack": "^0.11.1",
"eslint-loader": "^2.1.2",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-vue": "^5.2.2",

@oli-laban
Copy link

I'm also experiencing this with default airbnb arrow-parens config:

'arrow-parens': ['error', 'as-needed', {
  requireForBlockBody: true,
}],
// Expected parentheses around arrow function argument having a body with curly braces.
export const makeRequest = async <T>(
  method: RequestMethod,
  urlPath: string,
  body: {} = {},
  extraHeaders: RequestHeaders = {},
  throwGeneralError: boolean = true,
  suppressErrors: boolean = false,
): Promise<T | null> => {
  ...
};
"eslint": "^5.15.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",

@aldarund
Copy link

aldarund commented May 15, 2020

Still issue. It happens when { "requireForBlockBody": true } otherwise it don't happen.
Maybe it will be fixed one day :) Issue number 14. Is it oldest one not fixed i wonder
happens on latest eslint 7 and the fix action totally break code

@mdjermanovic
Copy link

This is fixed in eslint v7.4.0

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
9 participants