chore: improve Markdown and codeblock formatting
- Update `prettier.lua` to handle injected code blocks with correct `lang_to_ft` and `lang_to_ext` mappings - Remove deprecated `markdown_inline` filetype; rely on injected formatting instead - Update `linting.lua` to match new configuration - Remove unused formatting and linting tools
This commit is contained in:
@@ -6,20 +6,37 @@ return {
|
||||
local lint = require('lint')
|
||||
|
||||
lint.linters_by_ft = {
|
||||
-- markdown = { 'markdownlint' },
|
||||
-- html = { 'htmlhint' },
|
||||
-- json = { 'jsonlint' },
|
||||
-- sh = { 'shellharden', 'shellcheck' },
|
||||
-- bash = { 'shellharden', 'shellcheck' },
|
||||
-- javascript = { 'eslint_d', 'trivy' },
|
||||
-- typescript = { 'eslint_d' },
|
||||
-- python = { 'pylint', 'trivy' },
|
||||
-- ansible = { 'ansiblelint' },
|
||||
-- gitcommit = { 'gitlint' },
|
||||
-- docker = { 'trivy' },
|
||||
-- yaml = { 'trivy', 'yamllint' },
|
||||
-- editorconfig = { 'editorconfig-checker' },
|
||||
-- systemd = { 'systemdlint' },
|
||||
-- Lua
|
||||
lua = {},
|
||||
|
||||
-- Shell / Bash / Zsh
|
||||
sh = { 'shellcheck' },
|
||||
bash = { 'shellcheck' },
|
||||
|
||||
-- Markdown
|
||||
markdown = { 'markdownlint' },
|
||||
-- markdown_inline = { 'markdownlint' },
|
||||
|
||||
-- Web / Frontend
|
||||
html = { 'htmlhint' },
|
||||
css = { 'stylelint' },
|
||||
javascript = { 'eslint_d' },
|
||||
php = { 'trivy' },
|
||||
|
||||
-- YAML
|
||||
yaml = { 'yamllint' },
|
||||
|
||||
-- JSON
|
||||
json = { 'jsonlint', 'jq' },
|
||||
|
||||
-- Python
|
||||
python = { 'pylint' },
|
||||
|
||||
-- Git commit messages
|
||||
gitcommit = { 'gitlint' },
|
||||
|
||||
-- SQL
|
||||
sql = { 'sqlfluff' },
|
||||
}
|
||||
|
||||
local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true })
|
||||
|
||||
@@ -1,35 +1,109 @@
|
||||
--[[ vim.api.nvim_create_autocmd({ 'FocusLost', 'BufLeave' }, {
|
||||
pattern = '*',
|
||||
callback = function(args)
|
||||
local buf = args.buf or vim.api.nvim_get_current_buf()
|
||||
if vim.fn.mode() == 'n' then
|
||||
vim.defer_fn(function()
|
||||
if vim.api.nvim_buf_is_valid(buf) then require('conform').format({ bufnr = buf }) end
|
||||
end, 100)
|
||||
end
|
||||
end,
|
||||
}) ]]
|
||||
|
||||
return {
|
||||
'stevearc/conform.nvim',
|
||||
event = { 'BufReadPre', 'BufNewFile' },
|
||||
event = { 'BufWritePre' },
|
||||
opts = {
|
||||
formatters_by_ft = {
|
||||
sh = { 'beautysh', 'shellharden' },
|
||||
bash = { 'beautysh', 'shellharden' },
|
||||
zsh = { 'beautysh' },
|
||||
javascript = { 'prettier' },
|
||||
typescript = { 'prettier' },
|
||||
css = { 'prettier' },
|
||||
-- Lua
|
||||
lua = { 'lsp_format', 'stylua' },
|
||||
|
||||
-- Shell / Bash / Zsh
|
||||
sh = { 'beautysh' },
|
||||
bash = { 'beautysh' },
|
||||
-- zsh = { 'beautysh' }, -- beautysh pisses me off with zsh files
|
||||
|
||||
-- Markdown
|
||||
markdown = { 'prettier', 'injected' },
|
||||
-- markdown_inline = { 'prettier', 'injected' },
|
||||
|
||||
-- Web / Frontend
|
||||
html = { 'prettier' },
|
||||
json = { 'prettier' },
|
||||
yaml = { 'prettier' },
|
||||
markdown = { 'prettier', 'markdownlint' },
|
||||
graphql = { 'prettier' },
|
||||
liquid = { 'prettier' },
|
||||
lua = { 'stylua' },
|
||||
python = { 'black', 'sort' },
|
||||
},
|
||||
formatters = {
|
||||
--[[ shfmt = {
|
||||
prepend_args = { '-i', '6' },
|
||||
}, ]]
|
||||
css = { 'prettier', 'stylelint' },
|
||||
javascript = { 'prettier', 'eslint_d' },
|
||||
php = { 'phpcbf' },
|
||||
|
||||
-- YAML
|
||||
yaml = { 'prettier', 'yamlfmt' },
|
||||
|
||||
-- JSON / Config
|
||||
json = { 'prettier', 'fixjson' },
|
||||
|
||||
-- Python
|
||||
python = { 'black', 'isort' },
|
||||
|
||||
-- SQL
|
||||
sql = { 'sqlfluff' },
|
||||
},
|
||||
format_injected = true,
|
||||
default_format_opts = {
|
||||
lsp_format = 'fallback',
|
||||
},
|
||||
format_on_save = {
|
||||
format_after_save = {
|
||||
lsp_format = 'fallback',
|
||||
async = false,
|
||||
timeout_ms = 1000,
|
||||
},
|
||||
},
|
||||
|
||||
config = function(_, opts)
|
||||
local conform = require('conform')
|
||||
conform.setup(opts)
|
||||
|
||||
-- Configure injected formatter
|
||||
conform.formatters.injected = {
|
||||
options = {
|
||||
ignore_errors = false,
|
||||
lang_to_ft = {
|
||||
sh = 'sh',
|
||||
bash = 'sh',
|
||||
zsh = 'sh',
|
||||
lua = 'lua',
|
||||
javascript = 'javascript',
|
||||
json = 'json',
|
||||
yaml = 'yaml',
|
||||
markdown = 'markdown',
|
||||
python = 'python',
|
||||
html = 'html',
|
||||
css = 'css',
|
||||
toml = 'toml',
|
||||
sql = 'sql',
|
||||
php = 'php',
|
||||
},
|
||||
-- Map injected languages to the right formatter(s)
|
||||
lang_to_ext = {
|
||||
sh = 'sh',
|
||||
bash = 'sh',
|
||||
zsh = 'sh',
|
||||
javascript = 'js',
|
||||
markdown = 'md',
|
||||
json = 'json',
|
||||
yaml = 'yml',
|
||||
python = 'py',
|
||||
lua = 'lua',
|
||||
html = 'html',
|
||||
css = 'css',
|
||||
toml = 'toml',
|
||||
sql = 'sql',
|
||||
php = 'php',
|
||||
},
|
||||
|
||||
--[[ lang_to_formatters = {
|
||||
sh = { 'beautysh' },
|
||||
bash = { 'beautysh'},
|
||||
javascript = {'prettier'},
|
||||
json = {'prettier'},
|
||||
}, ]]
|
||||
},
|
||||
}
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user