coc-prettier icon indicating copy to clipboard operation
coc-prettier copied to clipboard

prettier.ignorePath setting is not respected

Open kas opened this issue 4 years ago • 2 comments

Content of coc-settings.json file:

{
  "coc.preferences.formatOnSaveFiletypes": ["*"]
}

or

{
  "coc.preferences.formatOnSaveFiletypes": ["*"],
  "prettier.ignorePath": "./.prettierignore"
}

Repository folder structure:

repository-folder/ --.prettierignore --subfolder/ ----.prettierignore ----index.html

Content of repository-folder/.prettierignore file:

subfolder/

Content of repository-folder/subfolder/.prettierignore file:

(empty)

Repro steps:

  1. Run vim repository-folder/subfolder/index.html
  2. Modify the index.html to make Prettier attempt to format the file when the file is saved
  3. Save the file

Expected: 4. Prettier formats index.html

Actual: 4. Prettier does not format index.html

Issue: The Readme.md file describes:

prettier.ignorePath (default: .prettierignore)

Supply the path to an ignore file such as .gitignore or .prettierignore. Files which match will not be formatted. Set to null to not read ignore files. Restart required.

Setting the "prettier.ignorePath" setting to ".prettierignore" (default) or "./.prettierignore" should make Prettier use the .prettierignore file in the same directory as the file that is open.

Visual Studio Code does not have this issue when opening the subfolder folder.

kas avatar Jun 07 '20 19:06 kas

I'm only using the .prettierignore file in the repository-folder to make Prettier ignore the subfolder folders of my project. The goal is that using Prettier in the repository-folder folder will only run Prettier on files in that folder, and not subfolders. If anyone else is running into this issue, a mitigation is to modify the Prettier script in your package.json file:

{
  ...
  "scripts": {
    "prettier": "prettier --write . \"!subfolder-1/**\" \"!subfolder-2/**\" \"!subfolder-3/**\"",
  },
  ...
}

kas avatar Jun 07 '20 19:06 kas

Content of coc-settings.json file:

{
  "coc.preferences.formatOnSaveFiletypes": ["*"]
}

or

{
  "coc.preferences.formatOnSaveFiletypes": ["*"],
  "prettier.ignorePath": "./.prettierignore"
}

Repository folder structure:

repository-folder/ --.prettierignore --subfolder/ ----.prettierignore ----index.html

Content of repository-folder/.prettierignore file:

subfolder/

Content of repository-folder/subfolder/.prettierignore file:

(empty)

Repro steps:

  1. Run vim repository-folder/subfolder/index.html
  2. Modify the index.html to make Prettier attempt to format the file when the file is saved
  3. Save the file

Expected: 4. Prettier formats index.html

Actual: 4. Prettier does not format index.html

Issue: The Readme.md file describes:

prettier.ignorePath (default: .prettierignore)

Supply the path to an ignore file such as .gitignore or .prettierignore. Files which match will not be formatted. Set to null to not read ignore files. Restart required.

Setting the "prettier.ignorePath" setting to ".prettierignore" (default) or "./.prettierignore" should make Prettier use the .prettierignore file in the same directory as the file that is open.

Visual Studio Code does not have this issue when opening the subfolder folder.

if you are still having an issue drop log of :CocCommand prettier.openOutput, because I have been having this issue myself just to realise that I have been using prettier.forceFormatDocument on my binding, rather than just prettier.formatFile

el-og avatar Jun 09 '22 14:06 el-og