Git Product home page Git Product logo

mason-conform's Introduction

mason-conform

mason-conform is a Neovim plugin used as a bridging handler between mason.nvim and conform.nvim. It allows automatic checking and installation of formatters in the mason.nvim registry and conform.nvim configuration.

Requirements

Install

{
    "williamboman/mason.nvim",
    "stevearc/conform.nvim",
    "LittleEndianRoot/mason-conform",
}
use {
    "williamboman/mason.nvim",
    "stevearc/conform.nvim",
    "LittleEndianRoot/mason-conform",
}

Load order

It's crucial to setup plugins in the following order:

  1. mason.nvim
  2. conform.nvim
  3. mason-conform

Otherwise mason-conform will not have enough information about configured formatters and access to the mason registry.

To learn about the available settings and configurations, please refer the Configuration section.

Configuration

You can configure the behaviour of mason-conform by passing the configuration to 'setup()'. All available settings are provided in default configuration section.

Example:

require("mason-conform").setup()

Default configuration

local DEFAULT_SETTINGS = {
    -- a list of formatters to automatically install if they're not already installed. example: { "asmfmt", "ast-grep" }
    -- this setting has no relation with the `automatic_installation` setting.
    -- names of formatters should be taken from mason's registry.
    ---@type string[]
    ensure_installed = {},

    -- whether formatters are set up (via conform) should be automatically installed if they're not installed already.
    -- it tries to find the specified formatters in mason's registry to proceed with installation.
    -- this setting has no relation with `ensure_installed` setting.
    ---@type boolean
  automatic_installation = true,

    -- disables warning notifications about misconfiguration such as invalid formatter entries and incorrect plugin load order.
    quiet_mode = false,
}

Basic Customisation

Using this configuration, only formatters specified in ensure_installed will be installed. Ones specified in conform.nvim will be ignored. NOTE: The formatters in ensure_installed should be written in the format of mason's registry (https://mason-registry.dev/).

require('mason-conform').setup({
    ensure_installed = { "black", "prettier" },
})

Alternative Customisation

Simple alternative configuration can that can be used as a stand alone file to be called in your NeoVim init.lua #NOTE: make sure to call setup after mason.nvim and conform.nvim have been loaded see load orderOr see below example to use it as part of your mason.nvim lua file.

local M = {
    "williamboman/mason.nvim",
    event = {}, -- optinal events
    dependencies = {
        { "williamboman/mason-lspconfig.nvim", event = {} },
        { "stevearc/conform.nvim", event = {} },
        { "LittleEndianRoot/mason-conform", event = {} },
    },
}

--[[
    list whatever mason registry formatter below
]]--
M.formatters = {
    "black",
    "prettier",
}

function M.config()
    --[[
        other mason setup code
    ]]--
    local m_conform = require("mason-conform")

    m_conform.setup({
        ensure_installed = M.formatters,
        automatic_installation = false,
        quiet_mode = false,
    })
end

return M

Mason formatters registry

You can find a list of mason registry packages at mason registry

Since LSP servers, linters, DAPs and Formatters are all grouped together in the packages directory in the link above. Here is a list of just Formatters from the Mason registry:

  asmfmt
  ast-grep
  autoflake
  autopep8
  beautysh
  bibtex-tidy
  biome
  black
  blade-formatter
  blue
  buf
  buildifier
  cbfmt
  clang_format
  cmake_format
  codespell
  csharpier
  darker
  deno_fmt
  djlint
  dprint
  easy-coding-standard
  elm_format
  eslint_d
  fantomas
  fixjson
  fourmolu
  gci
  gdformat
  gersemi
  gofumpt
  goimports-reviser
  goimports
  golines
  google-java-format
  htmlbeautifier
  isort
  joker
  jq
  jsonnetfmt
  ktlint
  latexindent
  markdown-toc
  markdownlint-cli2
  markdownlint
  mdformat
  mdslw
  nixpkgs_fmt
  ocamlformat
  php_cs_fixer
  phpcbf
  pint
  prettier
  prettierd
  pretty-php
  reorder-python-imports
  rubocop
  rubyfmt
  ruff_fix
  ruff_format
  rufo
  rustfmt
  rustywind
  shellcheck
  shellharden
  shfmt
  sql_formatter
  sqlfluff
  sqlfmt
  standardjs
  standardrb
  stylelint
  stylua
  taplo
  templ
  tlint
  typos
  usort
  xmlformat
  yamlfix
  yamlfmt
  yapf
  yq
  zprint

Copyright

I needed a working helper to installed mason formatters automatically without manual intervention (after initial configuration). So it is no surprise that mason-conform is a copy of another great plugin with the same functionality only for linters called mason-nvim-lint mason-nvim-lint is in itself inspired from mason-lspconfig.nvim

mason-conform's People

Contributors

littleendianroot avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.