From deb9d4852b0ff899b81874fefd1df9b564c8ce13 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Tue, 8 Jan 2019 21:24:56 -0800 Subject: [PATCH] fix: Don't overwrite parser if provided by user Bug Repro Gist: https://gist.github.com/bradzacher/07d98abce83ed5a4094ccbfacca8b82f prettier-eslint overrides the parser with its own parser if it detects it's running on a typescript file. This was generally okay, because there was very little difference between the parser versions (though there may have been subtle bugs that users didn't notice). I was testing a config with the current `1.0.0-rc.2` of `eslint-plugin-typescript`, and noticed that it wasn't fixing an error I know has a fixer. When I ran `eslint --fix` manually, it worked fine. After a lot of digging, I finally setup the repro case and noticed that the config passed into eslint included prettier-eslint's local dependency, instead of eslint-plugin-typescript's. This matters now for two reasons: 1) As of eslint-plugin-typescript 1.0.0 ([1.0.0 release notes](https://github.com/bradzacher/eslint-plugin-typescript/releases/tag/1.0.0-rc.0)), we've moved the parser internally so we can better manage the dependency (too many bugs reported from people using an unsupported version of the parser). 2) The parser recently released a number of very breaking changes (I think it was the v20 release). This change fixes this by allowing the user specified parser to be used. While I haven't tested, I suspect that prettier-eslint might break if used on typescript vue files (if it even works with it?? I don't use vue...) eslint-plugin-vue uses its own parser as well, which would be clobbered by this setting. --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7cc27ab..0ebb2d5 100644 --- a/src/index.js +++ b/src/index.js @@ -122,7 +122,7 @@ function format(options) { if ([".ts", ".tsx"].includes(fileExtension)) { // XXX: It seems babylon is getting a TypeScript plugin. // Should that be used instead? - formattingOptions.eslint.parser = require.resolve( + formattingOptions.eslint.parser = formattingOptions.eslint.parser || require.resolve( "typescript-eslint-parser" ); }