eslint-plugin-mocha icon indicating copy to clipboard operation
eslint-plugin-mocha copied to clipboard

no-mocha-arrows autofix with parsers

Open Hyzual opened this issue 4 years ago • 4 comments

Hi ! I wanted to use mocha/no-mocha-arrows for our Cypress test suite, but the autofix behaviour seems a bit odd in our case. I've built a reproduction case on runkit here: https://runkit.com/hyzual/mocha-no-mocha-arrows

It looks like when you combine "vue-eslint-parser" with "@typescript-eslint/parser", the autofix breaks down and adds multiple function() at the top of the file instead of replacing arrow functions below.

Other autofixes for different plugins work well even with the two parsers. Let me know if more info is needed.

Hyzual avatar Apr 16 '20 13:04 Hyzual

I have the same issue, but I don't use vue-eslint-parser.

I use

    "@typescript-eslint/eslint-plugin": "^2.28.0",
    "@typescript-eslint/parser": "^2.28.0",
    "eslint-config-airbnb-typescript": "^7.2.1",
    "eslint-config-prettier": "^6.10.1",
    "eslint-formatter-gitlab": "^1.1.0",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-mocha": "^6.3.0",
    "eslint-plugin-prettier": "^3.1.3",

Naktibalda avatar Apr 21 '20 05:04 Naktibalda

If this is only a problem with third-party parser but not the default parser I would think this is an issue in the parsers.

lo1tuma avatar Apr 23 '20 08:04 lo1tuma

Hi, I installed this plugin and it helps us to write healthy test code so much, thank you.

Talking about this issue, Vue.js is unrelated. I encountered same issue with pure TypeScript project.

I forked @Hyzual 's reproduction code and removed Vue.js related things: https://runkit.com/saiya-moebius/mocha-no-mocha-arrows-autofix

mocha/no-mocha-arrows breaks TypeScript code parsed with @typescript-eslint/parser. It inserts function() in the beginning of the file as shown in the reproduction code, this is what I see too.

If eslint-plugin-mocha's autofix works well with the @typescript-eslint/parser, it improves TypeScript w/mocha productivity a lot. Thank you for making this plugin.

saiya avatar May 02 '20 17:05 saiya

If someone provides an easy fix that doesn’t need to interact with @typescript-eslint/parser directly I’m happy to review and merge a PR.

lo1tuma avatar Jul 31 '20 13:07 lo1tuma