Skip to content
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

Multiple formatters on same filetype don't applied alltogether on a single 'coc-format' call #2269

Closed
alex-popov-tech opened this issue Aug 21, 2020 · 3 comments

Comments

@alex-popov-tech
Copy link

Result from CocInfo

## versions

vim version: NVIM v0.5.0-593-g1ca67a73c
node version: v14.8.0
coc.nvim version: 0.0.78-bdd9a9e140
coc.nvim directory: /Users/alexanderpopov/.config/nvim/plugged/coc.nvim
term: screen-256color
platform: darwin

## Output channel: watchman

[Info  - 8:59:00 AM] watchman watching project: /Users/alexanderpopov/Work/backend-project-lvl4
[Info  - 8:59:00 AM] subscribing "**/.eslintr{c.js,c.yaml,c.yml,c,c.json}" in /Users/alexanderpopov/Work/backend-project-lvl4
[Info  - 8:59:00 AM] subscribing "**/.eslintignore" in /Users/alexanderpopov/Work/backend-project-lvl4
[Info  - 8:59:00 AM] subscribing "**/package.json" in /Users/alexanderpopov/Work/backend-project-lvl4
[Info  - 8:59:00 AM] subscribing "**/{.prettierrc,.prettierrc.json,.prettierrc.yaml,.prettierrc.yml,.prettierrc.js,package.json,prettier.config.js}" in /Users/alexanderpopov/Work/backend-project-lvl4

## Output channel: explorer


## Output channel: git

Looking for git in: git
> git rev-parse --show-toplevel
resolved root: /Users/alexanderpopov/Work/backend-project-lvl4
resolved root: /Users/alexanderpopov/Work/backend-project-lvl4
> git symbolic-ref --short HEAD
> git diff --name-status
> git diff --staged --name-status
> git ls-files --others --exclude-standard

## Output channel: prettier


## Output channel: snippets

[Info 8:59:00 AM] Using ultisnips directories: UltiSnips /Users/alexanderpopov/.config/coc/ultisnips
[Info 8:59:00 AM] Using ultisnips python command: pyx

Describe the bug

When i run coc-format (or save buffer with formatOnSave settings) and having 2 formatters to apply ( f.e. eslint + prettier ) they are not running together on a single coc-format call, i need to call coc-format twice, to format buffer with two different formatters

Reproduce the bug

vimrc chunk

let g:coc_global_extensions = [
           \ 'coc-actions',
           \ 'coc-tsserver',
           \ 'coc-vimlsp',
           \ 'coc-sql',
           \ 'coc-tabnine',
           \ 'coc-spell-checker',
           \ 'coc-cspell-dicts',
           \ 'coc-snippets',
           \ 'coc-json',
           \ 'coc-yaml',
           \ 'coc-eslint',
           \ 'coc-prettier',
           \ 'coc-yank',
           \ 'coc-tslint',
           \ 'coc-explorer',
           \ 'coc-git',
           \ 'coc-java',
           \ 'coc-post',
           \ 'coc-db',
           \ 'coc-marketplace'
           \]

coc-settings.json

  "eslint.filetypes": [
    "typescript",
    "javascript"
  ],
  "eslint.run": "onSave",
  "eslint.autoFixOnSave": true,
  "eslint.options": {
    "configFile": "/Users/alexanderpopov/.eslintrc.json"
  },
  "prettier.eslintIntegration": true,
  "coc.preferences.formatOnSaveFiletypes": [
    "javascript",
    "typescript"
  ],
  "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
  "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,

Screenshots (optional)

Video - https://share.getcloudapp.com/OAuqqdXZ

Note - I've created a ticket in coc-prettier here neoclide/coc-prettier#85 first, and @chemzqm said that could be potentially coc.nvim bug, so i'm posting it here too.

@utrumo
Copy link
Contributor

utrumo commented Oct 1, 2020

Some problem. I have conflict with coc-stylelintplus and coc-diagnostic.
If i enable for coc-stylelintplus this options:

  "stylelintplus.cssInJs": true,
  "stylelintplus.autoFixOnSave": true,

then coc-diagnostic autoformatting on saving stops working for js files when i use this config for eslint:
.vimrc

let g:coc_global_extensions = [
\  'coc-css',
\  'coc-stylelintplus',
\  'coc-diagnostic',
\ ]

coc-settings.json

{
  "diagnostic.signOffset": 9999999,
  "css.validate": false,
  "less.validate": false,
  "scss.validate": false,
  "wxss.validate": false,
  "stylelintplus.cssInJs": true,
  "stylelintplus.autoFixOnSave": true,
  "coc.preferences.formatOnSaveFiletypes": [
    "javascript",
    "javascript.tsx",
    "javascriptreact",
    "typescript",
    "typescript.tsx",
    "typescriptreact"
  ],
  "diagnostic-languageserver.linters": {
    "eslint_d": {
      "command": "eslint_d",
      "rootPatterns": [".git"],
      "debounce": 100,
      "args": [
        "--stdin",
        "--stdin-filename",
        "%filepath",
        "--format",
        "json",
        "--cache"
      ],
      "sourceName": "eslint",
      "parseJson": {
        "errorsRoot": "[0].messages",
        "line": "line",
        "column": "column",
        "endLine": "endLine",
        "endColumn": "endColumn",
        "message": "${message} [${ruleId}]",
        "security": "severity"
      },
      "securities": {
        "2": "error",
        "1": "warning"
      }
    }
  },
  "diagnostic-languageserver.formatters": {
    "eslint_d": {
      "command": "eslint_d",
      "rootPatterns": [".git"],
      "args": [
        "--stdin",
        "--stdin-filename",
        "%filepath",
        "--fix",
        "--fix-to-stdout"
      ],
      "isStderr": false,
      "isStdout": true
    }
  },
  "diagnostic-languageserver.filetypes": {
    "javascript": "eslint_d",
    "javascript.tsx": "eslint_d",
    "javascriptreact": "eslint_d",
    "typescript": "eslint_d",
    "typescript.tsx": "eslint_d",
    "typescriptreact": "eslint_d"
  },
  "diagnostic-languageserver.formatFiletypes": {
    "javascript": "eslint_d",
    "javascript.tsx": "eslint_d",
    "javascriptreact": "eslint_d",
    "typescript": "eslint_d",
    "typescript.tsx": "eslint_d",
    "typescriptreact": "eslint_d"
  }
}

@EdmundsEcho
Copy link

EdmundsEcho commented Nov 26, 2020

I came to this issue by way of trying to conclude whether coc-nvim "prettier.eslintIntegration": true is working as expected.

In my understanding, the issue of multiple formatters goes away when I extend eslint to process the prettier rules (... using eslint plugins).

What is confusing and what had me find this issue, is that given the eslint-integration I just described, why then do I need to consider integrating prettier with coc-nvim? For instance, if memory served, ALE did not need to know about prettier when already integrated with eslint.

Is the answer that to use prettier to reformat/fix a file, that we need a separate instance of the prettier module (separate from what eslint is using)? ... in which case, if we want prettier to format our code, we need coc-prettier (...and with a copy/paste .prettierrc version of the prettier configuration specified in .eslintrc)?

Thank you for clarifying!

-E

@chemzqm chemzqm removed the bug Something isn't working label Dec 17, 2020
@chemzqm
Copy link
Member

chemzqm commented Dec 17, 2020

Only one formatter is allowed to work on save, checkout #2704.

To run eslint autofix with format on save, use "eslint.autoFixOnSave": false in your coc-settings.json (should be default), and add autocmd BufWritePre *.js call CocAction('runCommand', 'eslint.executeAutofix') in your vimrc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants