neoclide / coc-prettier

Prettier extension for coc.nvim.
MIT License
546 stars 48 forks source link

Prettier failed on tsx files #130

Closed kozer closed 3 years ago

kozer commented 3 years ago

Having typescriptreact and typescript on my formatfilesOnSave make prettier failed with the following.

[Error - 6/17/2021, 10:05:21 PM:] Failed to load prettier-tslint from <my-home-path>/node_modules/coc-prettier

[Error - 6/17/2021, 10:05:21 PM:] Cannot read property 'format' of null

Notice that I have prettier installed locally in my project. If I install prettier-tslint locally as well everything works as expected.

The local installation of prettier doesn't seem to be the issue though as removing it makes the error message still appears. (At first I thought that the local version was creating an issue resolving the bundled prettier)

Also a strange thing is that I have those options in my coc-config

"prettier.tslintIntegration": "false",
"prettier.eslintIntegration": "false",
"prettier.stylelintIntegration": "false",

Seems that it tries to resolve prettier-tslint from my project and not using the bundled one.

Could you provide some help to solve this?

Thanks!

PS: Installed local typescript version: "typescript": "^4.2.3", PS2: Don't think that's relative but I don't have a coc-config json file. I use let g:coc_user_config in my vim config to provide coc nvim with my preferred options

chemzqm commented 3 years ago

Try :echo CocAction getConfig('prettier')

kozer commented 3 years ago

If I run this specific command I get E121: Undefined variable: CocAction. Is this correct?

Also, how this will solve the issue?

fannheyward commented 3 years ago

:echo CocAction('getConfig', 'prettier')

kozer commented 3 years ago

Thanks @fannheyward . Still no clue how this will solve the issue. I get the config back, so what?

cc: @chemzqm

{'trailingComma': 'es5', 'endOfLine': 'lf', 'tslintIntegration': 'false', 'disableLanguages': ['vue'], 'semi': v:true, 'tabWidth': 2, 'printWidth': 80, 'disableSuccessMessage': v:fal
se, 'proseWrap': 'preserve', 'arrowParens': 'always', 'htmlWhitespaceSensitivity': 'css', 'jsxBracketSameLine': v:false, 'useTabs': v:false, 'stylelintIntegration': 'false', 'jsxSing
leQuote': v:false, 'formatterPriority': '1', 'singleQuote': v:false, 'statusItemText': 'Prettier', 'onlyUseLocalVersion': v:false, 'parser': 'none', 'requireConfig': 'true', 'bracket
Spacing': v:true, 'eslintIntegration': 'false', 'ignorePath': '.prettierignore'}
fannheyward commented 3 years ago

It's "prettier.tslintIntegration": false, not "false", type is boolean https://github.com/neoclide/coc-prettier/blob/master/package.json#L47-L49.

chemzqm commented 3 years ago

Use https://github.com/neoclide/coc-json for json validation is recommended.