From 8ddcc1b8694161e502354731a5f9c6b01e4be534 Mon Sep 17 00:00:00 2001 From: Steffen Rademacker Date: Wed, 4 Oct 2023 18:35:53 +0200 Subject: [PATCH] linting and formatters working --- install/3_neovim.sh | 2 +- nvim/init.lua | 13 +++++--- nvim/lua/plugins/conform.lua | 44 +++++++++++++++++++++++++ nvim/lua/plugins/lint.lua | 20 +++++------- nvim/lua/plugins/treesitter.lua | 28 +++++++++++++--- nvim/lua/plugins/which-key.lua | 57 +++++++++++++++------------------ zsh/exports.zsh | 2 +- 7 files changed, 110 insertions(+), 56 deletions(-) create mode 100644 nvim/lua/plugins/conform.lua diff --git a/install/3_neovim.sh b/install/3_neovim.sh index ef248ec5..11281a82 100755 --- a/install/3_neovim.sh +++ b/install/3_neovim.sh @@ -1,6 +1,7 @@ #!/usr/bin/env zsh brew install neovim +brew install jq gem install neovim pip install neovim @@ -8,7 +9,6 @@ pip install neovim ln -s ~/dotfiles/nvim ~/.config/nvim # additional language-servers for nvim-lspconfig -npm install -g fixjson npm install -g eslint_d npm install -g jsonlint npm install -g markdownlint-cli diff --git a/nvim/init.lua b/nvim/init.lua index 1197264d..b9105ff8 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -28,8 +28,9 @@ require('lazy').setup({ -- modern neovim with treesitter, lsp, cmp, vsnips and telescope { 'neovim/nvim-lspconfig', config = get_config('lspconfig') }, { 'nvim-treesitter/nvim-treesitter', config = get_config('treesitter'), build = ':TSUpdate' }, - { 'nvim-treesitter/nvim-treesitter-textobjects', dependencies = 'nvim-treesitter/nvim-treesitter' }, { 'nvim-treesitter/nvim-treesitter-refactor', dependencies = 'nvim-treesitter/nvim-treesitter' }, + { 'windwp/nvim-ts-autotag', dependencies = 'nvim-treesitter/nvim-treesitter' }, + { 'andymass/vim-matchup', dependencies = 'nvim-treesitter/nvim-treesitter' }, { 'nvim-telescope/telescope.nvim', dependencies = 'nvim-lua/plenary.nvim', config = get_config('telescope') }, { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' }, { 'hrsh7th/vim-vsnip', config = get_config('vsnip') }, @@ -60,14 +61,13 @@ require('lazy').setup({ { 'kylechui/nvim-surround', event = 'VeryLazy', config = true }, { 'numToStr/Comment.nvim', config = true }, { 'numToStr/Navigator.nvim', config = true }, - { 'tpope/vim-ragtag' }, -- TODO still needed?! - { 'tpope/vim-repeat' }, -- TODO still needed?! { 'windwp/nvim-autopairs', event = 'InsertEnter', config = true }, -- more plugins and integrations + { 'nvim-pack/nvim-spectre', dependencies = 'nvim-lua/plenary.nvim', config = true }, { 'voldikss/vim-floaterm', config = get_config('floaterm') }, { 'mfussenegger/nvim-lint', config = get_config('lint') }, - -- TODO formatter with eslint, stylelint, markdownlint and code_actions? + { 'stevearc/conform.nvim', event = { 'BufWritePre' }, config = get_config('conform') }, { 'nvim-neorg/neorg', build = ':Neorg sync-parsers', dependencies = 'nvim-lua/plenary.nvim', @@ -135,7 +135,10 @@ cmd 'colorscheme gruvbox-baby' cmd 'language en_US.UTF-8' -- autoresize windows/splits everytime we change to a buffer -createCmd({ 'BufEnter', 'BufWinEnter' }, { pattern = { '*' }, command = 'wincmd =' }) +createCmd({ 'VimResized', 'FocusGained' }, { + pattern = { '*' }, + command = 'wincmd =', +}) -- make dash-spearated-keywords in css and json a keyword createCmd({ 'BufEnter', 'BufWinEnter' }, { diff --git a/nvim/lua/plugins/conform.lua b/nvim/lua/plugins/conform.lua new file mode 100644 index 00000000..4890bad4 --- /dev/null +++ b/nvim/lua/plugins/conform.lua @@ -0,0 +1,44 @@ +require('conform').setup({ + formatters = { + localstylelint = { + stdin = true, + command = function() + local local_repo = vim.fn.system({ 'git', 'rev-parse', '--show-toplevel' }):gsub('%s+', '') + local local_stylelint = vim.fn.resolve(local_repo .. '/node_modules/.bin/stylelint') + if vim.fn.filereadable(local_stylelint) then + return local_stylelint + end + return 'stylelint' + end, + args = { + '--fix', + '--stdin', + '--stdin-filename', + vim.fn.expand('%:p'), + '--config-basedir', + vim.fn.system({ 'git', 'rev-parse', '--show-toplevel' }), + }, + }, + }, +}) + +vim.api.nvim_create_autocmd('BufWritePre', { + pattern = { '*.json' }, + callback = function(args) + require('conform').format({ formatters = { 'jq' }, quiet = true }) + end, +}) + +vim.api.nvim_create_autocmd('BufWritePre', { + pattern = { '*.css', '*.scss' }, + callback = function(args) + require('conform').format({ formatters = { 'localstylelint' }, quiet = true }) + end, +}) + +vim.api.nvim_create_autocmd('BufWritePre', { + pattern = { '*.js', '*.jsx', '*.ts', '*.tsx' }, + callback = function(args) + require('conform').format({ formatters = { 'eslint_d' }, quiet = true }) + end, +}) diff --git a/nvim/lua/plugins/lint.lua b/nvim/lua/plugins/lint.lua index 7173a58c..3f07a6e5 100644 --- a/nvim/lua/plugins/lint.lua +++ b/nvim/lua/plugins/lint.lua @@ -4,27 +4,23 @@ require('lint').linters_by_ft = { yaml = { 'yamllint' }, css = { 'stylelint' }, scss = { 'stylelint' }, - json = { 'fixjson' }, + json = { 'jsonlint' }, javascript = { 'eslint_d' }, javascriptreact = { 'eslint_d' }, - typescript = { 'tsc', 'eslint_d' }, - typescriptreact = { 'tsc', 'eslint_d' }, + typescript = { 'eslint_d' }, + typescriptreact = { 'eslint_d' }, } -- stylelint always relative to current git-dir local stylelint = require('lint').linters.stylelint -stylelint['stdin'] = false stylelint['args'] = { - '-f', + '--formatter', 'json', + "--stdin", + "--stdin-filename", + vim.fn.expand("%:p"), '--config-basedir', - function() - return vim.fn.system({ 'git', 'rev-parse', '--show-toplevel' }) - end, - '--stdin-filename', - function() - return vim.fn.expand('%:p') - end, + vim.fn.system({ 'git', 'rev-parse', '--show-toplevel' }), } require('lint').linters.stylelint = stylelint diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua index 74d452f5..df6e39e4 100644 --- a/nvim/lua/plugins/treesitter.lua +++ b/nvim/lua/plugins/treesitter.lua @@ -28,13 +28,31 @@ require('nvim-treesitter.configs').setup({ }, highlight = { enable = true }, indent = { enable = true }, - textobjects = { - select = { + autotag = { enable = true }, + matchup = { enable = true }, + refactor = { + highlight_definitions = { enable = true, - lookahead = true, - include_surrounding_whitespace = true, + clear_on_cursor_move = true, }, - } + navigation = { + enable = true, + keymaps = { + goto_definition = 'gd', + list_definitions = 'gl', + list_definitions_toc = false, + goto_next_usage = 'gn', + goto_previous_usage = 'gp', + }, + }, + smart_rename = { + enable = true, + keymaps = { + smart_rename = 'gr', + }, + }, + + }, }) vim.opt.foldexpr = 'nvim_treesitter#foldexpr()' diff --git a/nvim/lua/plugins/which-key.lua b/nvim/lua/plugins/which-key.lua index f5c12297..c6578c72 100644 --- a/nvim/lua/plugins/which-key.lua +++ b/nvim/lua/plugins/which-key.lua @@ -7,65 +7,61 @@ wk.register({ ['-'] = { 'FloatermNew nnn', 'invoke floaterm with nnn as file picker' }, [';'] = { ':', 'Colon with semicolon' }, [''] = { 'checktimeredraw!', 'redraw/reload with F5' }, - [''] = { 'bfirst', 'buffer navigation with arrow keys' }, - [''] = { 'bnext', 'buffer navigation with arrow keys' }, [''] = { 'blast', 'buffer navigation with arrow keys' }, [''] = { 'bprevious', 'buffer navigation with arrow keys' }, + [''] = { 'bnext', 'buffer navigation with arrow keys' }, + [''] = { 'bfirst', 'buffer navigation with arrow keys' }, + ['¬'] = { '>>', 'bubbling lines with alt-hjkl', noremap = false }, ['˙'] = { '<<', 'bubbling lines with alt-hjkl', noremap = false }, - ['∆'] = { ':move .+1', 'bubbling lines with alt-hjkl', noremap = false }, ['˚'] = { ':move .-2', 'bubbling lines with alt-hjkl', noremap = false }, - ['¬'] = { '>>', 'bubbling lines with alt-hjkl', noremap = false }, + ['∆'] = { ':move .+1', 'bubbling lines with alt-hjkl', noremap = false }, g = { name = 'code-related mappings', + -- for more code-mappings: see treesitter.lua + D = { 'lua vim.lsp.buf.declaration()', 'show/go to declaration' }, + I = { 'lua vim.lsp.buf.implementation()', 'show/go to implementation' }, + L = { 'lua vim.lsp.buf.references()', 'show/go to referennces' }, a = { 'lua vim.lsp.buf.code_action()', 'run code action' }, b = { 'Gitsigns blame_line', 'git blame line' }, - d = { 'lua vim.lsp.buf.definition()', 'show/go to definition' }, e = { 'lua vim.diagnostic.goto_next()', 'go to next error in file' }, - f = { 'lua vim.lsp.buf.formatting()', 'format file with LSP' }, + f = { 'lua vim.lsp.buf.format()', 'format file with LSP' }, h = { 'lua vim.lsp.buf.hover()', 'show hover info' }, - r = { 'lua vim.lsp.buf.rename()', 'lsp rename' }, x = { 'execute "/\\v^[<\\|=>]{7}/"', 'find git conflicts in file' }, - - D = { 'lua vim.lsp.buf.declaration()', 'show/go to declaration' }, - I = { 'lua vim.lsp.buf.implementation()', 'show/go to implementation' }, - R = { 'lua vim.lsp.buf.references()', 'show/go to referennces' }, }, + K = { '', 'K man-pages mapping removed' }, + N = { 'Nzzzv', 'kepping it centered with N' }, + Q = { '', 'Q ex-mode-mapping removed' }, + S = { function() require('flash').treesitter() end, 'flash treesitter select' }, j = { 'gj', 'j and k with wrapped lines' }, k = { 'gk', 'j and k with wrapped lines' }, n = { 'nzzzv', 'kepping it centered with n' }, s = { function() require('flash').jump() end, 'flash jump' }, v = { '', 'remapping visual/visual-block mode' }, - K = { '', 'K man-pages mapping removed' }, - N = { 'Nzzzv', 'kepping it centered with N' }, - Q = { '', 'Q ex-mode-mapping removed' }, - S = { function() require('flash').treesitter() end, 'flash treesitter select' }, - Y = { 'y$', 'yank till end of line with Y' }, - -- with as modifier [''] = { 'NavigatorLeft', 'move to the lefthand split' }, [''] = { 'NavigatorDown', 'move to the rigthand split' }, [''] = { 'NavigatorUp', 'move to the upper split' }, [''] = { 'NavigatorRight', 'move to the lower split' }, - [''] = { 'v', 'remapping visual/visual-block mode' }, }) -- all normal mode leader key mappings in one place wk.register({ - ['\\'] = { 'vl', 'Vertical split' }, - ['-'] = { 'sj', 'Horizontal split' }, [','] = { 'Telescope find_files', 'find files' }, + ['-'] = { 'sj', 'Horizontal split' }, ['.'] = { 'Telescope buffers', 'find buffers' }, - ['\''] = { 'Telescope git_files', 'find in git files' }, - [';'] = { 'Telescope command_history', 'find in command history' }, ['/'] = { 'Telescope search_history', 'find in search history' }, + [';'] = { 'Telescope command_history', 'find in command history' }, + ['\''] = { 'Telescope git_files', 'find in git files' }, + ['\\'] = { 'vl', 'Vertical split' }, [']'] = { 'Telescope current_buffer_fuzzy_find', 'find line in current buffer' }, a = { 'Telescope live_grep', 'live ripgrep' }, b = { 'Telescope git_branches', 'git branches' }, c = { 'Telescope git_bcommits', 'commits for buffer' }, + f = { 'Spectre', 'open spectre for search/replace' }, l = { 'FloatermNew lazygit', 'open lazygit' }, t = { 'FloatermNew', 'open new terminal' }, v = { @@ -79,20 +75,17 @@ wk.register({ -- visual-mode mappings wk.register({ [';'] = { ':', 'Colon with semicolon' }, + ['¬'] = { '>gv', 'bubbling lines with alt-hjkl', noremap = false }, ['˙'] = { '+1gv", 'bubbling lines with alt-hjkl', noremap = false }, ['˚'] = { ":move '<-2gv", 'bubbling lines with alt-hjkl', noremap = false }, - ['¬'] = { '>gv', 'bubbling lines with alt-hjkl', noremap = false }, - + ['∆'] = { ":move '>+1gv", 'bubbling lines with alt-hjkl', noremap = false }, v = { '', 'remapping visual/visual-block mode' }, - [''] = { 'v', 'remapping visual/visual-block mode' }, }, { mode = 'v' }) --- non-normal-mode mappings +-- insert-substitute-mode mappings for snippets +wk.register({ + [''] = { 'vsnip#available(1) ? "(vsnip-expand-or-jump)" : ""', 'snippet expansion' }, +}, { mode = 'i', expr = true, noremap = true }) wk.register({ [''] = { 'vsnip#available(-1) ? "(vsnip-jump-prev)" : ""', 'snippet expansion' }, -}, { - mode = 's', - expr = true, - noremap = true -}) +}, { mode = 's', expr = true, noremap = true }) diff --git a/zsh/exports.zsh b/zsh/exports.zsh index 8080b9cd..6a8327b9 100644 --- a/zsh/exports.zsh +++ b/zsh/exports.zsh @@ -28,7 +28,7 @@ export HOMEBREW_NO_ENV_HINTS=true # nnn export NNN_OPTS='deHR' -export NNN_BMS='a:~/Sites/ag;d:~/Dotfiles;s:~/Sites;l:~/Downloads;h:~/' +export NNN_BMS='a:~/Sites;s:~/Dotfiles;d:~/Downloads;h:~/' export NNN_FCOLORS='c1e26c2e006033f5c6d6abc4' export NNN_PLUG='p:preview-tui;j:autojump' export NNN_FIFO='/tmp/nnn.fifo'