Skip to content

Commit

Permalink
fix: Don't overwrite parser if provided by user
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bradzacher authored and zimme committed Jun 15, 2019
1 parent 65ddb3d commit deb9d48
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -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"
);
}
Expand Down

0 comments on commit deb9d48

Please sign in to comment.