i had the same issue.
In your root workspace you have a .vscode folder with a settings.json.
Add the following:
{
"eslint.workingDirectories": [
"./{PATH_TO_CLIENT}" // replace {PATH_TO_CLIENT} with your own path
]
}
related issue: create-react-app subfolder projects do not lint
Answer from Julez on Stack Overflowi had the same issue.
In your root workspace you have a .vscode folder with a settings.json.
Add the following:
{
"eslint.workingDirectories": [
"./{PATH_TO_CLIENT}" // replace {PATH_TO_CLIENT} with your own path
]
}
related issue: create-react-app subfolder projects do not lint
VSCode/eslint will not pick newly installed npm packages in the node_modules directory. After running npm i eslint-plugin-prettier restart the VSCode workspace. Happens to me consistently, every time I setup a new Javascript/Node/React project and add eslint & prettier, using this guide in the order it suggests.
Videos
» npm install eslint-plugin-prettier
There is an incompatibility between prettier 3 and eslint-plugin-prettier 4.
You can fix this by using version 5 of eslint-plugin-prettier:
yarn add -D [email protected]
or
npm install --save-dev [email protected]
- Official issue: https://github.com/prettier/eslint-plugin-prettier/issues/562
- v5 release notes: https://github.com/prettier/eslint-plugin-prettier/releases/tag/v5.0.0
In my case, the issue was connected with pretty-quick tool I used for pre-commit formatting. Current version (pretty-quick v3.1.3) is not compatible with prettier v3, they have an issue in their repo (link). And sine the last update of pretty-quick was made 2 years ago, I decided to switch to lint-staged which is compatible with prettier v3 and seems to be more live/maintainable (the last release was made 1 week ago). The transition was super easy, just following the readme doc: https://github.com/okonet/lint-staged.
Prettier is a peer dependency of @vue/eslint-config-prettier so you need to add it to your own dependencies:
Copynpm install --save-dev prettier
if you're using yarn 3, and yarn add --dev prettier doesn't solve your problem, try this:
cmd+shift+p- in the dropdown, search for
preferences: open user settings (json) - add
"prettier.prettierPath": ".yarn/sdks/prettier/index.js"to your json file.
This tells your editor to find the module in the path you added.
NOTE: If there is not sdks directory in .yarn make sure to run the following command for the first time to generate the related directories.
The latest version and workflow is for Yarn 4.0.0-rc.48
Copyyarn dlx @yarnpkg/sdks base
You can read more about editor sdks in the doc
Hi,
I tried to post this in the weekly thread, but I get errors. (I assume it is due to comment length, but there is literally just an empty error)
EDIT: I have solved the issue and every time I try to post the solution (either by editing or adding a comment) I get that same empty error from reddit. for solution, see 2 comments below.
I have null-ls setup to run prettierd for html files. (that works like a charm)
Now I would like it to format html files with go templates and it does not seem pick up my prettierd config in the root of my project:
// <project_root>/.prettierrc
{
"plugins": ["prettier-plugin-go-template"],
"overrides": [
{
"files": ["*.html"],
"options": {
"parser": "go-template",
},
},
],
} NullLsInfo shows prettierd is active, but not the supported list is empty.
How do I make sure that the .prettierrc is used?
I used lazy.nvim to setup null-ls see setup below.
Any help would be appreciated
return {
"jose-elias-alvarez/null-ls.nvim", -- configure formatters & linters
event = { "BufReadPre", "BufNewFile" },
config = function()
-- import null-ls plugin
local null_ls = require("null-ls")
local null_ls_utils = require("null-ls.utils")
-- for conciseness
local formatting = null_ls.builtins.formatting -- to setup formatters
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
-- to setup format on save
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
-- configure null_ls
null_ls.setup({
-- add package.json as identifier for root (for typescript monorepos)
root_dir = null_ls_utils.root_pattern(".null-ls-root", "Makefile", ".git", "package.json"),
-- setup formatters & linters
sources = {
-- to disable file types use
-- "formatting.prettier.with({disabled_filetypes: {}})" (see null-ls docs)
--formatting.prettier.with({
-- extra_filetypes = { "svelte" },
--}), -- js/ts formatter
formatting.prettierd.with({
filetypes = {
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"css",
"scss",
"less",
"html",
"json",
"jsonc",
"yaml",
"markdown",
"markdown.mdx",
"graphql",
"handlebars",
"gotmpl",
},
}),
formatting.stylua, -- lua formatter
formatting.gofumpt, -- golang formatter
-- formatting.goimports, -- golang imports
diagnostics.eslint_d.with({ -- js/ts linter
condition = function(utils)
return utils.root_has_file({ ".eslintrc.js", ".eslintrc.cjs" }) -- only enable if root has .eslintrc.js or .eslintrc.cjs
end,
}),
},
-- configure format on save
on_attach = function(current_client, bufnr)
if current_client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({
filter = function(client)
-- only use null-ls for formatting instead of lsp server
return client.name == "null-ls"
end,
bufnr = bufnr,
})
end,
})
end
end,
})
end,
}