Skip to content

Latest commit

 

History

History
80 lines (63 loc) · 2.34 KB

CONTRIBUTING.md

File metadata and controls

80 lines (63 loc) · 2.34 KB

Contribute

Default configurations

All default configurations are placed in the default configurations per formatter, default configurations per filetype, and default configurations for any filetype. You should use the util module which has various functions that help with creating default configurations.

The default configurations per formatter return functions which create a formatter configuration. For example, the prettier default configuration function takes in a parser argument:

local util = require "formatter.util"

return function(parser)
  if not parser then
    return {
      exe = "prettier",
      args = {
        "--stdin-filepath",
        util.escape_path(util.get_current_buffer_file_path()),
      },
      stdin = true,
      try_node_modules = true,
    }
  end

  return {
    exe = "prettier",
    args = {
      "--stdin-filepath",
      util.escape_path(util.get_current_buffer_file_path()),
      "--parser",
      parser,
    },
    stdin = true,
    try_node_modules = true,
  }
end

Default configurations per formatter are used to create default configurations per filetype, and default configurations for any filetype.

For example, the default formatter configuration for prettier for the typescript filetype uses the default formatter configuration function for prettier:

local M = {}

local defaults = require "formatter.defaults"
local util = require "formatter.util"

-- other formatters...

-- "util.withl" here returns a function that executes the defaults.prettier
-- function with "typescript" as the first argument for the parser
M.prettier = util.withl(defaults.prettier, "typescript")

-- other formatters...

return M

The default configurations for any filetype are in exactly the same format as default configurations per filetype. It is just important to note that this file is special because all formatter default configurations that can be applied to any filetype go here.