### Setup null-ls with Built-in Sources Source: https://github.com/nvimtools/none-ls.nvim/blob/main/README.md This snippet shows how to set up null-ls and register built-in sources for formatting and completion, along with an example for diagnostics from none-ls-extras.nvim. ```lua local null_ls = require("null-ls") null_ls.setup({ sources = { null_ls.builtins.formatting.stylua, null_ls.builtins.completion.spell, require("none-ls.diagnostics.eslint"), -- requires none-ls-extras.nvim }, }) ``` -------------------------------- ### Registering Sources with Setup and Register Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/MAIN.md Demonstrates two methods for registering sources: `setup` for user configuration and `register` for integrations. Both accept single sources, lists, or tables with shared configurations. ```lua local null_ls = require("null-ls") -- using setup method ull_ls.setup({ sources = my_sources }) -- using register method ull_ls.register({ my_sources }) ``` -------------------------------- ### PMD Wrapper Script Example Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example bash script to create an executable wrapper for PMD, recommended for integration. ```bash #!/usr/bin/env bash path/to/pmd/bin/run.sh pmd "$@" ``` -------------------------------- ### Install null-ls with packer.nvim Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/CONFIG.md Install null-ls and its dependency, plenary.nvim, using the packer.nvim package manager. Ensure both plugins are listed in your configuration. ```lua use({ "nvimtools/none-ls.nvim", config = function() require("null-ls").setup() end, requires = { "nvim-lua/plenary.nvim" }, }) ``` -------------------------------- ### Add rego Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the rego formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.rego } ``` -------------------------------- ### Add pyink Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the pyink formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.pyink } ``` -------------------------------- ### CMake Format Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to integrate the cmake-format tool for CMake listfiles. ```lua local sources = { null_ls.builtins.formatting.cmake_format } ``` -------------------------------- ### Clang Format Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to integrate clang-format for C/C++ and other supported languages. ```lua local sources = { null_ls.builtins.formatting.clang_format } ``` -------------------------------- ### Add rubocop Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the rubocop formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.rubocop } ``` -------------------------------- ### Add qmlformat Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the qmlformat formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.qmlformat } ``` -------------------------------- ### Buf Formatter Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to integrate the buf formatter for Protocol Buffers. ```lua local sources = { null_ls.builtins.formatting.buf } ``` -------------------------------- ### Add rustywind Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the rustywind formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.rustywind } ``` -------------------------------- ### Buildifier Formatter Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to use the buildifier tool for Bazel files. ```lua local sources = { null_ls.builtins.formatting.buildifier } ``` -------------------------------- ### Add rescript Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the rescript formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.rescript } ``` -------------------------------- ### Add rufo Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the rufo formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.rufo } ``` -------------------------------- ### Add rubyfmt Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the rubyfmt formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.rubyfmt } ``` -------------------------------- ### BSfmt Formatter Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the BSfmt formatter for BrightScript and BrighterScript files. ```lua local sources = { null_ls.builtins.formatting.bsfmt } ``` -------------------------------- ### Basic null-ls Configuration Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/CONFIG.md Configure null-ls with a basic setup, including formatting, diagnostics, and completion sources. Refer to BUILTINS.md for a list of available sources. ```lua local null_ls = require("null-ls") null_ls.setup({ sources = { null_ls.builtins.formatting.stylua, null_ls.builtins.diagnostics.eslint, null_ls.builtins.completion.spell, }, }) ``` -------------------------------- ### Registering Multiple Built-in Sources Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md Register a list of built-in sources by passing them to the null-ls setup function. Ensure the required external commands are available in your system's PATH. ```lua local null_ls = require("null-ls") -- register any number of sources simultaneously local sources = { null_ls.builtins.formatting.prettier, null_ls.builtins.diagnostics.write_good, null_ls.builtins.code_actions.gitsigns, } null_ls.setup({ sources = sources }) ``` -------------------------------- ### Lua: Use buf diagnostics builtin Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the 'buf' diagnostics builtin source for Protocol Buffers files. ```lua local sources = { null_ls.builtins.diagnostics.buf } ``` -------------------------------- ### Crystal Format Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to use the crystal tool for formatting Crystal code. ```lua local sources = { null_ls.builtins.formatting.crystal_format } ``` -------------------------------- ### Blade Formatter Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the Blade formatter as a source for null-ls.nvim. ```lua local sources = { null_ls.builtins.formatting.blade_formatter } ``` -------------------------------- ### Add scalafmt Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the scalafmt formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.scalafmt } ``` -------------------------------- ### Add shellharden Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the shellharden formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.shellharden } ``` -------------------------------- ### Lua: Use buildifier diagnostics builtin Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the 'buildifier' diagnostics builtin source for Bazel BUILD, WORKSPACE, and .bzl files. ```lua local sources = { null_ls.builtins.diagnostics.buildifier } ``` -------------------------------- ### Configure vint Diagnostic Source Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates vint for linting Vimscript files. Requires vint to be installed. ```lua local sources = { null_ls.builtins.diagnostics.vint } ``` -------------------------------- ### CSharpier Formatter Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to integrate CSharpier for formatting C# code. ```lua local sources = { null_ls.builtins.formatting.csharpier } ``` -------------------------------- ### Default null-ls Options Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/CONFIG.md View the default configuration options for null-ls. These can be customized during the setup process. ```lua local defaults = { border = nil, cmd = { "nvim" }, debounce = 250, debug = false, default_timeout = 5000, diagnostic_config = {}, diagnostics_format = "#{m}", fallback_severity = vim.diagnostic.severity.ERROR, log_level = "warn", notify_format = "[null-ls] %s", on_attach = nil, on_init = nil, on_exit = nil, root_dir = require("null-ls.utils").root_pattern(".null-ls-root", "Makefile", ".git"), root_dir_async = nil, should_attach = nil, sources = nil, temp_dir = nil, update_in_insert = false, } ``` -------------------------------- ### Add raco_fmt Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the raco_fmt formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.raco_fmt } ``` -------------------------------- ### Add remark Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the remark formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.remark } ``` -------------------------------- ### Clojure Formatter (cljstyle) Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to use the cljstyle tool for formatting Clojure code. ```lua local sources = { null_ls.builtins.formatting.cljstyle } ``` -------------------------------- ### Add racket_fixw Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the racket_fixw formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.racket_fixw } ``` -------------------------------- ### Clojure Formatter (cljfmt) Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to use the cljfmt tool for formatting Clojure code. ```lua local sources = { null_ls.builtins.formatting.cljfmt } ``` -------------------------------- ### Lua: Use checkmake diagnostics builtin Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the 'checkmake' diagnostics builtin source for linting Makefiles. ```lua local sources = { null_ls.builtins.diagnostics.checkmake } ``` -------------------------------- ### Lua: Use bslint diagnostics builtin Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the 'bslint' diagnostics builtin source for linting BrighterScript code. ```lua local sources = { null_ls.builtins.diagnostics.bslint } ``` -------------------------------- ### Add Saltlint to Diagnostics Sources Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate saltlint for checking SaltStack best practices in your null-ls setup. ```lua local sources = { null_ls.builtins.diagnostics.saltlint } ``` -------------------------------- ### Lua: Use actionlint diagnostics builtin Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the 'actionlint' diagnostics builtin source for checking GitHub Actions workflow files. ```lua local sources = { null_ls.builtins.diagnostics.actionlint } ``` -------------------------------- ### Configure write-good Diagnostic Source Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates write-good for linting English prose in Markdown files. Requires write-good to be installed. ```lua local sources = { null_ls.builtins.diagnostics.write_good } ``` -------------------------------- ### Example Diagnostics Format Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/CONFIG.md Sets the default format for diagnostics. Special components like #{m}, #{s}, and #{c} are replaced with relevant diagnostic information. ```lua diagnostics_format = "[#{c}] #{m} (#{s})" ``` -------------------------------- ### Example Registered Source Structure Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/SOURCES.md Illustrates the internal structure of a source object after it has been registered with null-ls. This includes its name, supported filetypes, methods, generator, and a unique ID. ```lua local example_source = { name = "example_source", filetypes = { ["lua"] = true }, methods = { [require("null-ls").methods.FORMATTING] = true }, generator = { fn = function() return "I am a source!" end, }, id = 1, } ``` -------------------------------- ### Configure gn_format for GN formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate gn_format for formatting GN code. Requires google depot_tools to be installed. It reads from stdin and is configured for the 'gn' filetype. ```lua local sources = { null_ls.builtins.formatting.gn_format } ``` -------------------------------- ### Lua: Use vsnip completion builtin Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the 'vsnip' completion builtin source. Requires vim-vsnip for snippet expansion. ```lua local sources = { null_ls.builtins.completion.vsnip } ``` -------------------------------- ### Configure yamlfmt for Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Use yamlfmt as a formatting source for YAML files. Ensure yamlfmt is installed and accessible. ```lua local sources = { null_ls.builtins.formatting.yamlfmt } ``` -------------------------------- ### Lua: Use ansiblelint diagnostics builtin Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the 'ansiblelint' diagnostics builtin source for linting Ansible files. ```lua local sources = { null_ls.builtins.diagnostics.ansiblelint } ``` -------------------------------- ### Configure verilator Diagnostic Source Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates Verilator for linting Verilog and SystemVerilog files. Requires Verilator to be installed. ```lua local sources = { null_ls.builtins.diagnostics.verilator } ``` -------------------------------- ### Configure textlint Diagnostic Source Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates textlint for linting text and Markdown files. Requires textlint to be installed. ```lua local sources = { null_ls.builtins.diagnostics.textlint } ``` -------------------------------- ### Configure yamllint Diagnostic Source Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates yamllint for linting YAML files. Requires yamllint to be installed. ```lua local sources = { null_ls.builtins.diagnostics.yamllint } ``` -------------------------------- ### Configure nimpretty for Nim Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Employ nimpretty to format Nim source code according to the official style guide. ```lua local sources = { null_ls.builtins.formatting.nimpretty } ``` -------------------------------- ### Conditional Buffer Attachment Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/CONFIG.md Configures a function to control whether null-ls should attach to a given buffer. This example prevents attachment to buffers with names starting with 'git://'. ```lua require("null-ls.nvim").setup({ should_attach = function(bufnr) return not vim.api.nvim_buf_get_name(bufnr):match("^git://") end, }) ``` -------------------------------- ### Lua: Use bean_check diagnostics builtin Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the 'bean_check' diagnostics builtin source for Beancount files. ```lua local sources = { null_ls.builtins.diagnostics.bean_check } ``` -------------------------------- ### Lua: Configure checkstyle diagnostics with extra arguments Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to configure the 'checkstyle' diagnostics builtin source with custom arguments, such as specifying a Google checks XML file. ```lua local sources = { null_ls.builtins.diagnostics.checkstyle.with({ extra_args = { "-c", "/google_checks.xml" }, -- or "/sun_checks.xml" or path to self written rules }), } ``` -------------------------------- ### Lua: Use alex diagnostics builtin Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the 'alex' diagnostics builtin source for catching insensitive writing in Markdown files. ```lua local sources = { null_ls.builtins.diagnostics.alex } ``` -------------------------------- ### Add Solhint to Diagnostics Sources Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Include solhint for linting Solidity code, covering security and style guides, in your null-ls configuration. ```lua local sources = { null_ls.builtins.diagnostics.solhint } ``` -------------------------------- ### Configure Built-in Source with Custom Options Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md Configure specific options for a built-in source using the `config` key. This example filters out 'blame' actions for the `gitsigns` code action source. ```lua local gitsigns = null_ls.builtins.code_actions.gitsigns.with({ config = { filter_actions = function(title) return title:lower():match("blame") == nil -- filter out blame actions end, }, }) ``` -------------------------------- ### Configure vacuum Diagnostic Source Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates vacuum, an OpenAPI linter, for validating YAML and JSON files. Requires vacuum to be installed. ```lua local sources = { null_ls.builtins.diagnostics.vacuum } ``` -------------------------------- ### Configure Puppet Lint Diagnostics Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates puppet-lint for checking Puppet manifest style guide conformance. Uses diagnostics method with puppet-lint command. ```lua local sources = { null_ls.builtins.diagnostics.puppet_lint } ``` -------------------------------- ### Configure opentofu_fmt for OpenTofu Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Apply canonical formatting and style to OpenTofu configuration files using the 'tofu fmt' command. ```lua local sources = { null_ls.builtins.formatting.opentofu_fmt } ``` -------------------------------- ### Configure nixpkgs_fmt for Nixpkgs Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate nixpkgs-fmt for formatting Nix code specifically within the nixpkgs ecosystem. ```lua local sources = { null_ls.builtins.formatting.nixpkgs_fmt } ``` -------------------------------- ### Registering Single and Multiple Sources Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/MAIN.md Shows how to register a single source, a list of sources with independent configurations, and multiple sources with shared configuration using the `register` method. ```lua local null_ls = require("null-ls") -- single source ull_ls.register({ my_source }) -- list of sources with independent configuration ull_ls.register({ my_source, my_other_source }) -- more than one source with shared configuration ull_ls.register({ name = "my-sources", filetypes = { "lua" }, sources = { my_source, my_other_source } }) ``` -------------------------------- ### Enable Debug Mode in null-ls Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/null-ls.txt This snippet demonstrates how to enable debug mode for null-ls by setting the 'debug' flag to true in the setup configuration. Debug mode is useful for troubleshooting issues. ```lua require("null-ls").setup({ debug = true, }) ``` -------------------------------- ### Custom Diagnostic Source: Parse CLI Output with markdownlint Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/null-ls.txt Integrate a CLI program like markdownlint as a diagnostic source. This example shows how to pipe buffer content to the CLI via stdin and convert its stderr output into LSP diagnostics using null-ls helpers. ```lua local null_ls = require("null-ls") local helpers = require("null-ls.helpers") local markdownlint = { method = null_ls.methods.DIAGNOSTICS, ``` -------------------------------- ### Add purs-tidy Formatter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to add the purs-tidy formatter to your null-ls sources. ```lua local sources = { null_ls.builtins.formatting.purs_tidy } ``` -------------------------------- ### Configure SQLFluff Linter with Dialect Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate SQLFluff for SQL linting. Specify the SQL dialect using `extra_args` or a `.sqlfluff` file. ```lua local sources = { null_ls.builtins.diagnostics.sqlfluff.with({ extra_args = { "--dialect", "postgres" }, -- change to your dialect }), } ``` -------------------------------- ### Configure sqlfmt for SQL and Jinja Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate sqlfmt for formatting SQL and Jinja files. It accepts input via stdin. ```lua local sources = { null_ls.builtins.formatting.sqlfmt } ``` -------------------------------- ### Configure cue_fmt Diagnostics Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Sets up cue_fmt to report formatting errors in .cue language files. It validates the current filename. ```lua local sources = { null_ls.builtins.diagnostics.cue_fmt } ``` -------------------------------- ### Configure meson_format for Meson Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate Meson's built-in formatter to maintain consistent style in Meson build files. ```lua local sources = { null_ls.builtins.formatting.meson_format } ``` -------------------------------- ### Configure nixfmt for Nix Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Use nixfmt to apply a uniform style to Nix code. ```lua local sources = { null_ls.builtins.formatting.nixfmt } ``` -------------------------------- ### Codespell Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to use codespell to fix common misspellings in text files. ```lua local sources = { null_ls.builtins.formatting.codespell } ``` -------------------------------- ### Add Revive to Diagnostics Sources Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate revive, a linter for Go, into your null-ls configuration. ```lua local sources = { null_ls.builtins.diagnostics.revive } ``` -------------------------------- ### Configure nix_flake_fmt for Nix Flake Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Use the generic 'nix fmt' command for reformatting Nix code, distinct from nixfmt. ```lua local sources = { null_ls.builtins.formatting.nix_flake_fmt } ``` -------------------------------- ### Add Rstcheck to Diagnostics Sources Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate rstcheck for checking reStructuredText syntax in your null-ls setup. ```lua local sources = { null_ls.builtins.diagnostics.rstcheck } ``` -------------------------------- ### Register a diagnostic source from CLI program output Source: https://github.com/nvimtools/none-ls.nvim/blob/main/README.md This snippet demonstrates how to create a diagnostic source by spawning a CLI program (`markdownlint`), passing buffer content via stdin, and parsing its stderr output into LSP diagnostics. It uses null-ls helpers for output parsing. ```lua local null_ls = require("null-ls") local helpers = require("null-ls.helpers") local markdownlint = { method = null_ls.methods.DIAGNOSTICS, filetypes = { "markdown" }, -- null_ls.generator creates an async source -- that spawns the command with the given arguments and options generator = null_ls.generator({ command = "markdownlint", args = { "--stdin" }, to_stdin = true, from_stderr = true, -- choose an output format (raw, json, or line) format = "line", check_exit_code = function(code, stderr) local success = code <= 1 if not success then -- can be noisy for things that run often (e.g. diagnostics), but can -- be useful for things that run on demand (e.g. formatting) print(stderr) end return success end, -- use helpers to parse the output from string matchers, -- or parse it manually with a function on_output = helpers.diagnostics.from_patterns({ { pattern = [[:(%d+):(%d+) [%w-/]+ (.*)]], groups = { "row", "col", "message" }, }, { pattern = [[:(%d+) [%w-/]+ (.*)]], groups = { "row", "message" }, }, }), }), } null_ls.register(markdownlint) ``` -------------------------------- ### Add Reek to Diagnostics Sources Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate reek for Ruby code smell detection into your null-ls setup. ```lua local sources = { null_ls.builtins.diagnostics.reek } ``` -------------------------------- ### CBFmt Formatter Usage Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to use the cbfmt tool for formatting code within Markdown and Org documents. ```lua local sources = { null_ls.builtins.formatting.cbfmt } ``` -------------------------------- ### Configure twigcs Diagnostic Source Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates twigcs for running checks against Twig files. Requires twigcs to be installed. ```lua local sources = { null_ls.builtins.diagnostics.twigcs } ``` -------------------------------- ### Configure tfsec Diagnostic Source Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates tfsec for security scanning of Terraform code. Requires tfsec to be installed. ```lua local sources = { null_ls.builtins.diagnostics.tfsec } ``` -------------------------------- ### Swift Format Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates the Swift formatter from Apple. Requires building from source. ```lua local sources = { null_ls.builtins.formatting.swift_format } ``` -------------------------------- ### Configure opacheck Diagnostics Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates opacheck for checking Rego source files for errors. Uses diagnostics_on_save method. ```lua local sources = { null_ls.builtins.diagnostics.opacheck } ``` -------------------------------- ### Add Semgrep to Diagnostics Sources Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate semgrep, a static analysis tool, for various languages in your null-ls setup. ```lua local sources = { null_ls.builtins.diagnostics.semgrep } ``` -------------------------------- ### Configure Protolint Diagnostics Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates Protolint for enforcing Protocol Buffer style and conventions. Uses diagnostics method with protolint command. ```lua local sources = { null_ls.builtins.diagnostics.protolint } ``` -------------------------------- ### Use Blackd Server Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates blackd, an HTTP server for Black, to avoid repeated process startup costs. Configuration is done via provided options, not config files. ```lua local sources = { null_ls.builtins.formatting.blackd } ``` -------------------------------- ### Importing Built-in Source Groups Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md Import the different categories of built-in sources available in null-ls. This is the first step before registering any sources. ```lua local null_ls = require("null-ls") -- code action sources local code_actions = null_ls.builtins.code_actions -- diagnostic sources local diagnostics = null_ls.builtins.diagnostics -- formatting sources local formatting = null_ls.builtins.formatting -- hover sources local hover = null_ls.builtins.hover -- completion sources local completion = null_ls.builtins.completion ``` -------------------------------- ### generator_factory Options Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/HELPERS.md Illustrates the available options for the `generator_factory` helper, which spawns a command and processes its output. All options are required unless otherwise specified. ```lua local helpers = require("null-ls.helpers") helpers.generator_factory({ args, -- function or table (optional) check_exit_code, -- function or table of numbers (optional) command, -- string or function cwd, -- function (optional) dynamic_command, -- function (optional) env, -- function or table (optional) format, -- "raw", "line", "json", or "json_raw" (optional) from_stderr, -- boolean (optional) from_temp_file, -- boolean (optional) ignore_stderr, -- boolean (optional) multiple_files, -- boolean (optional) on_output, -- function runtime_condition, -- function (optional) timeout, -- number (optional) to_stdin, -- boolean (optional) to_temp_file, -- boolean (optional) use_cache, -- boolean (optional) prepend_extra_args, -- boolean (optional) }) ``` -------------------------------- ### Configure markdownlint-cli2 Diagnostics Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates markdownlint-cli2 for linting Markdown files. Uses diagnostics_on_save method. Requires configuration file. ```lua local sources = { null_ls.builtins.diagnostics.markdownlint_cli2 } ``` -------------------------------- ### Configure sqlformat for SQL Reformatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Use sqlformat for reformatting SQL files according to specified options. It reads from stdin. ```lua local sources = { null_ls.builtins.formatting.sqlformat } ``` -------------------------------- ### Configure protolint for Protocol Buffer formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate protolint for Protocol Buffer files, enabling linting and fixing to enforce style conventions. It uses '--fix' and the filename. ```lua local sources = { null_ls.builtins.formatting.protolint } ``` -------------------------------- ### Customize Diagnostics Format Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md Change the format of diagnostic messages using `diagnostics_format`. This example includes the diagnostic code and source name in the message. ```lua local sources = { -- will show code and source name null_ls.builtins.diagnostics.shellcheck.with({ diagnostics_format = "[#{c}] #{m} (#{s})", }), } ``` -------------------------------- ### Defining a Synchronous Generator Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/MAIN.md An example of a synchronous generator for null-ls. The `fn` callback is schedule-wrapped for safety and error handling, returning diagnostic information. ```lua local my_source = {} my_source.generator = { fn = function(params) return { { col = 1, row = 1, message = "There is something wrong with this file!", severity = 1, source = "my-source", }, } end, } ``` -------------------------------- ### Configure sqlfluff for SQL Formatting with Dialect Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Use sqlfluff for SQL linting and formatting. It requires a --dialect argument, which can be specified via extra_args. ```lua local sources = { null_ls.builtins.formatting.sqlfluff.with({ extra_args = { "--dialect", "postgres" }, -- change to your dialect }), } ``` -------------------------------- ### Configure pint for PHP formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Use pint for PHP code formatting, with options for non-interactive and quiet execution, and passing the filename. ```lua local sources = { null_ls.builtins.formatting.pint } ``` -------------------------------- ### Configure mix for Elixir Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Utilize the 'mix format' command for Elixir projects to ensure code adheres to the official style guide. ```lua local sources = { null_ls.builtins.formatting.mix } ``` -------------------------------- ### Configure Asynchronous Formatting on Save Source: https://github.com/nvimtools/none-ls.nvim/wiki/Formatting-on-save Set up asynchronous formatting on save using a null-ls configuration. This method allows interaction while waiting for results but has caveats like not formatting on :wq. ```lua local async_formatting = function(bufnr) bufnr = bufnr or vim.api.nvim_get_current_buf() vim.lsp.buf_request( bufnr, "textDocument/formatting", vim.lsp.util.make_formatting_params({}), function(err, res, ctx) if err then local err_msg = type(err) == "string" and err or err.message -- you can modify the log message / level (or ignore it completely) vim.notify("formatting: " .. err_msg, vim.log.levels.WARN) return end -- don't apply results if buffer is unloaded or has been modified if not vim.api.nvim_buf_is_loaded(bufnr) or vim.api.nvim_buf_get_option(bufnr, "modified") then return end if res then local client = vim.lsp.get_client_by_id(ctx.client_id) vim.lsp.util.apply_text_edits(res, bufnr, client and client.offset_encoding or "utf-16") vim.api.nvim_buf_call(bufnr, function() vim.cmd("silent noautocmd update") end) end end ) end local null_ls = require("null-ls") local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) null_ls.setup({ -- add your sources / config options here sources = ..., debug = false, on_attach = function(client, bufnr) if client.supports_method("textDocument/formatting") then vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) vim.api.nvim_create_autocmd("BufWritePost", { group = augroup, buffer = bufnr, callback = function() async_formatting(bufnr) end, }) end end, }) ``` -------------------------------- ### Configure Markdownlint Source Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/null-ls.txt This snippet shows how to configure null-ls to use markdownlint as a source for diagnostics. It specifies the command, arguments, input/output formats, and custom logic for checking exit codes and parsing output. ```lua filetypes = {"markdown"}, -- null_ls.generator creates an async source -- that spawns the command with the given arguments and options generator = null_ls.generator({ command = "markdownlint", args = {"--stdin"}, to_stdin = true, from_stderr = true, -- choose an output format (raw, json, or line) format = "line", check_exit_code = function(code, stderr) local success = code <= 1 if not success then -- can be noisy for things that run often (e.g. diagnostics), but can -- be useful for things that run on demand (e.g. formatting) print(stderr) end return success end, -- use helpers to parse the output from string matchers, -- or parse it manually with a function on_output = helpers.diagnostics.from_patterns({ { pattern = [":(%d+):(%d+) [%w-/]+ (.*)"], groups = {"row", "col", "message"}, }, { pattern = [":(%d+) [%w-/]+ (.*)"], groups = {"row", "message"}, }, }), }), } null_ls.register(markdownlint) ``` -------------------------------- ### Source Methods for LSP Requests Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/MAIN.md Demonstrates how to define a source's method to trigger on different LSP requests like code actions, diagnostics, formatting, hover, or completion. Use the `null_ls.methods` object for safe referencing. ```lua local null_ls = require("null-ls") local my_source = {} -- source will run on LSP code action request my_source.method = null_ls.methods.CODE_ACTION -- source will run on LSP diagnostics request my_source.method = null_ls.methods.DIAGNOSTICS -- source will run on LSP formatting request my_source.method = null_ls.methods.FORMATTING -- source will run on LSP hover request my_source.method = null_ls.methods.HOVER -- source will run on LSP completion request my_source.method = null_ls.methods.COMPLETION ``` -------------------------------- ### Configure sql_formatter for SQL Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate sql-formatter for whitespace formatting of SQL queries. ```lua local sources = { null_ls.builtins.formatting.sql_formatter } ``` -------------------------------- ### Configure puppet-lint for Puppet manifest formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Employ puppet-lint to check and fix Puppet manifests according to style guides. It accepts '--fix' and the filename. ```lua local sources = { null_ls.builtins.formatting.puppet_lint } ``` -------------------------------- ### Get All Registered Sources Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/SOURCES.md Retrieves a list of all sources currently registered with null-ls. The returned table is a direct reference, so modifying it will affect null-ls's operation. ```lua require("null-ls").get_sources() ``` -------------------------------- ### Configure forge_fmt for Solidity formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate forge_fmt for formatting Solidity source files. It uses the 'forge fmt' command and targets the 'solidity' filetype. ```lua local sources = { null_ls.builtins.formatting.forge_fmt } ``` -------------------------------- ### Lua: Use cfn_lint diagnostics builtin Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Example of how to include the 'cfn_lint' diagnostics builtin source for validating AWS CloudFormation templates. It includes notes on how the file type is determined. ```lua local sources = { null_ls.builtins.diagnostics.cfn_lint } ``` -------------------------------- ### Configure vale Diagnostic Source Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates vale, a prose linter, for Markdown, TeX, and Asciidoc files. Requires vale installation and styles. Command arguments are dynamically resolved. ```lua local sources = { null_ls.builtins.diagnostics.vale } ``` -------------------------------- ### Configure Sqruff Linter Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Use Sqruff, a fast Rust-based SQL linter. It uses GitHub annotation format for output. ```lua local sources = { null_ls.builtins.diagnostics.sqruff } ``` -------------------------------- ### Enable Debug Mode in None-ls.nvim Source: https://github.com/nvimtools/none-ls.nvim/blob/main/README.md Set the 'debug' flag to true in your null-ls setup to enable debug logging. Remember to disable it after collecting necessary information as it can impact performance. ```lua require("null-ls").setup({ debug = true, }) ``` -------------------------------- ### Set Custom Command Timeout Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md Specify a custom `timeout` in milliseconds for a command. A value less than zero will prevent the command from ever timing out. This example sets a timeout of 10000 milliseconds. ```lua local sources = { null_ls.builtins.formatting.prettier.with({ -- milliseconds timeout = 10000, }), } ``` -------------------------------- ### Configure SwiftLint Linter for Swift Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrate SwiftLint for enforcing Swift style and conventions. It uses JSON reporting and reads from stdin. ```lua local sources = { null_ls.builtins.diagnostics.swiftlint } ``` -------------------------------- ### Defining an Asynchronous Generator Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/MAIN.md An example of an asynchronous generator. Setting `async = true` provides a `done()` callback. Processing pauses until `done()` is called, allowing for asynchronous operations before returning results. ```lua local my_source = {} my_source.generator = { -- must be explicitly set async = true, fn = function(params, done) -- always return done() to prevent timeouts if not string.match(params.content, "something wrong") then return done() end -- return results as normal inside the done() callback my_async_function(params, function() return done({ { col = 1, row = 1, message = "There is something wrong with this file!", severity = 1, source = "my-source", }, }) end) end, } ``` -------------------------------- ### Format Elm code with elm-format Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Format Elm source code according to the official Elm Style Guide using elm-format. This tool ensures consistent and readable Elm code. ```lua local sources = { null_ls.builtins.formatting.elm_format, } ``` -------------------------------- ### Configure nginx_beautifier for Nginx Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Use nginx_beautifier to automatically format and beautify Nginx configuration files. ```lua local sources = { null_ls.builtins.formatting.nginx_beautifier } ``` -------------------------------- ### Configure commitlint Diagnostics Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Sets up commitlint to enforce conventional commit message formats. Requires specific npm packages and a JSON formatter. ```lua local sources = { null_ls.builtins.diagnostics.commitlint } ``` -------------------------------- ### Configure Diagnostic Display Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md Customize how Neovim displays source diagnostics using `diagnostic_config`. This example enables underlines and signs, disables virtual text, and sets update behavior and severity sorting. ```lua local sources = { null_ls.builtins.diagnostics.shellcheck.with({ diagnostic_config = { -- see :help vim.diagnostic.config() underline = true, virtual_text = false, signs = true, update_in_insert = false, severity_sort = true, }, }), } ``` -------------------------------- ### Filter Generator Results Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md Use the `filter` option to exclude specific diagnostic results. The function should return `true` to keep a result and `false` or `nil` to ignore it. This example ignores diagnostics with the code 'prettier/prettier'. ```lua local sources = { null_ls.builtins.diagnostics.eslint_d.with({ -- ignore prettier warnings from eslint-plugin-prettier filter = function(diagnostic) return diagnostic.code ~= "prettier/prettier" end, }), } ``` -------------------------------- ### Run Single-File Tests Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/TESTING.md To run tests from a specific file, use the 'make test-file' command with the FILE environment variable set to the desired test file path. For example, to run tests in 'test/spec/e2e_spec.lua'. ```sh FILE=test/spec/e2e_spec.lua make test-file ``` -------------------------------- ### Advanced Diagnostic Customization with Postprocess Hook Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md Use `diagnostics_postprocess` for advanced customization of diagnostics. This hook runs after the built-in's generator and can modify diagnostic data. This example adjusts the severity based on the message content. ```lua local sources = { null_ls.builtins.diagnostics.write_good.with({ diagnostics_postprocess = function(diagnostic) diagnostic.severity = diagnostic.message:find("really") and vim.diagnostic.severity["ERROR"] or vim.diagnostic.severity["WARN"] end, }), } ``` -------------------------------- ### Format Rust files with Dioxus CLI (dxfmt) Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Format Rust files using the Dioxus CLI's `fmt` command. This ensures Rust code adheres to standard formatting conventions. ```lua local sources = { null_ls.builtins.formatting.dxfmt, } ``` -------------------------------- ### Configure npm_groovy_lint for Groovy/Jenkinsfile/Gradle Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Employ npm-groovy-lint to lint, format, and auto-fix Groovy, Jenkinsfile, and Gradle files. ```lua local sources = { null_ls.builtins.formatting.npm_groovy_lint } ``` -------------------------------- ### Register a custom diagnostic source parsing buffer content Source: https://github.com/nvimtools/none-ls.nvim/blob/main/README.md This snippet registers a custom diagnostic source that parses the current buffer's content to identify and report specific patterns as warnings. It's useful for enforcing style guides or detecting common writing errors. ```lua local null_ls = require("null-ls") local no_really = { method = null_ls.methods.DIAGNOSTICS, filetypes = { "markdown", "text" }, generator = { fn = function(params) local diagnostics = {} -- sources have access to a params object -- containing info about the current file and editor state for i, line in ipairs(params.content) do local col, end_col = line:find("really") if col and end_col then -- null-ls fills in undefined positions -- and converts source diagnostics into the required format table.insert(diagnostics, { row = i, col = col, end_col = end_col + 1, source = "no-really", message = "Don't use 'really!'", severity = vim.diagnostic.severity.WARN, }) end end return diagnostics end, }, } null_ls.register(no_really) ``` -------------------------------- ### Use markdownlint for Markdown linting and formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Integrates markdownlint-cli for checking and linting Markdown files. It fixes issues directly in the file. ```lua local sources = { null_ls.builtins.formatting.markdownlint } ``` -------------------------------- ### Configure ocdc for Changelog Formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Utilize ocdc to format changelog files. ```lua local sources = { null_ls.builtins.formatting.ocdc } ``` -------------------------------- ### Dynamically Setting Arguments Based on LSP Options Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md Configure built-in sources to dynamically adjust their arguments based on LSP client options, such as `tabSize`. This is achieved by providing a function to `extra_args` that accesses `params.options`. ```lua local sources = { null_ls.builtins.formatting.prettier.with({ extra_args = function(params) return params.options and params.options.tabSize and { "--tab-width", params.options.tabSize, } end, }), } ``` -------------------------------- ### register(to_register) Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/SOURCES.md Registers one or more new sources with null-ls. Sources can be registered individually, as a list, or within a table that allows for shared configuration. ```APIDOC ## register(to_register) ### Description The main method for registering sources. `to_register` can have the following structures: ### Method ```lua require("null-ls").register(to_register) ``` ### Parameters #### to_register - `to_register` (source | table): Can be: - A single source object. - An array-like table of source objects. - A table with shared configuration: - `name` (string): Shared name for sources. - `filetypes` (table): Shared filetypes for sources. - `sources` (table): An array-like table of source objects to register with shared configuration. ``` -------------------------------- ### Configure gofmt for Go formatting Source: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md Use gofmt for formatting Go programs. It uses tabs for indentation and blanks for alignment, assuming a fixed-width font. ```lua local sources = { null_ls.builtins.formatting.gofmt } ```