Skip to content

An opinionated πŸ¦„ .http and .rest 🐼 files linter πŸ’„ and formatter ⚑.

License

Notifications You must be signed in to change notification settings

mistweaverco/kulala-fmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Kulala-fmt Logo

kulala-fmt

NPM TypeScript Rollup GitHub release (latest by date) Discord

Install β€’ Usage

An opinionated πŸ¦„ .http and .rest 🐼 files linter πŸ’„ and formatter ⚑.

Install

Via npm:

npm install -g @mistweaverco/kulala-fmt

Usage

kulala-fmt can format and check .http and .rest files.

It can also convert OpenAPI .yaml, .yml or .json files to .http files.

Format

Format all .http and .rest files in the current directory and its subdirectories:

kulala-fmt format

Format specific .http and .rest files.

kulala-fmt format file1.http file2.rest http/*.http

Check

Check if all .http and .rest files in the current directory and its subdirectories are formatted:

kulala-fmt check

Check if specific .http and .rest files are formatted:

kulala-fmt check file1.http file2.rest http/*.http

Check if all .http and .rest files in the current directory and its subdirectories are formatted and prints the desired output to the console:

kulala-fmt check --verbose

Check if specific .http and .rest files are formatted and prints the desired output to the console:

kulala-fmt check --verbose file1.http file2.rest http/*.http

Convert

OpenAPI to .http

Convert OpenAPI .yaml, .yml or .json files to .http files:

kulala-fmt convert --from openapi openapi.yaml

Postman collection to .http

Convert Postman collection .json files to .http files:

kulala-fmt convert --from postman postman.json

Bruno to .http

Convert Bruno collections to .http files:

kulala-fmt convert --from bruno path/to/bruno/collection

What does it do?

  • Checks if the file is formatted and valid
  • Removes extraneous newlines
  • Makes sure document variables are at the top of the file
  • Lowercases all headers (when HTTP/2 or HTTP/3) else it will uppercase the first letter
  • Puts all metadata right before the request line
  • Ensures all comments are at the top of the request

So a perfect request would look like this:

@variables1 = value1


# This is a comment
# This is another comment
# @someother metatag
# @name REQUEST_NAME_ONE
GET http://localhost:8080/api/v1/health HTTP/1.1
Content-Type: application/json

{
  "key": "value"
}

###

or this:

@variables1=value1


# This is a comment
# This is another comment
# @someother metatag
# @name REQUEST_NAME_ONE
GET http://localhost:8080/api/v1/health HTTP/2
content-type: application/json

{
  "key": "value"
}

Use it with conform.nvim

return {
  "stevearc/conform.nvim",
  config = function()
    require("conform").setup({
      formatters = {
        kulala = {
          command = "kulala-fmt",
          args = { "format", "$FILENAME" },
          stdin = false,
        },
      },
      formatters_by_ft = {
        http = { "kulala" },
      },
      format_on_save = true,
    })
  end,
}