Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/platypew/format-installer.nvim
Neovim plugin for managing formatters/linters
https://github.com/platypew/format-installer.nvim
formatter install installer linter neovim null-ls nvim plugin
Last synced: 7 days ago
JSON representation
Neovim plugin for managing formatters/linters
- Host: GitHub
- URL: https://github.com/platypew/format-installer.nvim
- Owner: PlatyPew
- License: mit
- Created: 2022-01-06T14:02:25.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-05T02:47:53.000Z (over 2 years ago)
- Last Synced: 2024-08-03T13:06:08.029Z (4 months ago)
- Topics: formatter, install, installer, linter, neovim, null-ls, nvim, plugin
- Language: Lua
- Homepage:
- Size: 57.6 KB
- Stars: 32
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# About
### Caution: Development may terminate at any moment without prior warning, feel free to fork :)
A lightweight installer plugin written for [null-ls](https://github.com/jose-elias-alvarez/null-ls.nvim) used to manage formatters
Formatters are installed locally into `vim.fn.stdpath("data") .. "/formatters"` (it's usually located at `~/.local/share/nvim/formatters`)
Created because I couldn't find anyone else who has done it yet. Feel free to send issues, pull requests. All help will be greatly appreciated!
Also, there's no Windows support, but I am open to pull requests
# Installation
Via packer
```lua
use({
"jose-elias-alvarez/null-ls.nvim",
requires = "PlatyPew/format-installer.nvim",
after = "nvim-lspconfig", -- To prevent null-ls from failing to read buffer
})
```Setup (Unnecessary if you don't want to change the installation path)
```lua
-- defaults
require("format-installer").setup({
-- change path to suit your needs
installation_path = vim.fn.stdpath('data') .. '/formatters/',
})
```# Usage
`:FInstall ` to install formatters
`:FUninstall ` to uninstall formatters
`:FList` to list installed formatters
_You will need to restart Neovim for the formatters to take effect._
# Configuration with null-ls
This should be used in tandem with null-ls
```lua
local null_ls = require'null-ls'
local formatter_install = require'format-installer'local sources = {}
for _, formatter in ipairs(formatter_install.get_installed_formatters()) do
local config = { command = formatter.cmd }
table.insert(sources, null_ls.builtins.formatting[formatter.name].with(config))
endnull_ls.setup({
sources = sources,
})
```What if I want to customise the args?
```lua
-- Custom configs to pass
local custom_configs = {
clang_format = {
extra_args = {
"--style",
"{IndentWidth: 4, PointerAlignment: Left, ColumnLimit: 100, AllowShortFunctionsOnASingleLine: Empty}",
},
},
prettier = {
extra_args = {
"--tab-width=4",
"--print-width=100",
},
},
stylua = {
extra_args = {
"--column-width=100",
"--indent-type=Spaces",
},
},
yapf = {
extra_args = {
"--style",
"{column_limit:100}",
},
},
}local sources = {}
for _, formatter in ipairs(formatter_install.get_installed_formatters()) do
local config = { command = formatter.cmd }
if custom_configs[formatter.name] ~= nil then
config.extra_args = custom_configs[formatter.name].extra_args
end
table.insert(sources, null_ls.builtins.formatting[formatter.name].with(config))
end-- Optional: Additional formatters/diagnostics that are not included
-- This just uses the null-ls defaults
table.insert(
sources,
null_ls.builtins.code_actions.gitsigns,
)
```# Formatters available
| Formatter | Dependencies | Version |
| ---------------------- | ------------ | ------- |
| asmfmt | curl, tar | 1.3.2 |
| autopep8 | virtualenv |
| black | virtualenv |
| clang_format | llvm |
| cmake_format | virtualenv |
| codespell | virtualenv |
| djhtml | virtualenv |
| eslint | npm |
| eslint_d | npm |
| fixjson | npm |
| fprettify | virtualenv |
| google_java_format | curl, java | 1.15.0 |
| isort | virtualenv |
| markdownlint | npm |
| mypy | virtualenv |
| nginx_beautifier | npm |
| prettier | npm |
| prettier_d_slim | npm |
| prettier_standard | npm |
| prettierd | npm |
| reorder_python_imports | virtualenv |
| rustfmt | curl, tar | 1.5.1 |
| shfmt | curl | 3.5.1 |
| stylelint | npm |
| stylua | curl, unzip | 0.14.2 |
| trim_newlines | awk |
| yapf | virtualenv |# Lua API
- `require'format-installer'.setup()` - Setups the installation path
- `require'format-installer'.install_formatter()` - Installs formatter
- `require'format-installer'.uninstall_formatter()` - Uninstalls formatter
- `require'format-installer'.get_installed_formatters()` - Returns a table of installed formatters
- `require'format-installer'.exists()` - Returns boolean if formatter exists
- `require'format-installer'.is_installed()` - Returns boolean if formatter is installed