From b677522f35499e97498ebe83ccdd6a7783f6a66d Mon Sep 17 00:00:00 2001 From: Mark Gladkikh <17348049+sockcrates@users.noreply.github.com> Date: Sun, 11 Feb 2024 15:39:19 -0500 Subject: [PATCH] Run eslint conditionally in ES files only --- lua/custom/plugins/init.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index 5685946a..7527fd1d 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -7,8 +7,21 @@ vim.opt.colorcolumn = '80,100' vim.opt.number = true vim.opt.relativenumber = true +local function lint_and_format() + local filetype = vim.bo.filetype + if + filetype == 'javascript' + or filetype == 'typescript' + or filetype == 'javascriptreact' + or filetype == 'typescriptreact' + then + vim.cmd('EslintFixAll') + end + vim.cmd('Neoformat') +end + require('which-key').register({ - f = { ':Neoformat:EslintFixAll', 'Prettier then eslint' } + f = { lint_and_format, 'Lint and format current buffer' } }, { prefix = 'c' }) return {}