schemar / kak-jsts

JavaScript / TypeScript extension for the Kakoune editor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kak-jsts

This project extends JavaScript and TypeScript support of Kakoune. It provides additional commands for linting and formatting of your files. All formatting and linting will be done according to your local project preferences, e.g. in .eslintrc.js.

It does not provide additional language features. For that, check the Kakoune Language Server Protocol Client instead.

Installation

Prerequisites

kak-jsts has two dependencies that must be available on your machine:

  1. eslint-formatter-kakoune:
    • npm i -g eslint-formatter-kakoune
  2. jq
    • Check installation instructions for your system (e.g. brew install jq).

eslint-formatter-kakoune is required to enable Kakoune to interpret eslint's output.

jq is required to parse eslint's output of the JSON formatter.

With plug.kak

Add this to your kakrc:

plug "schemar/kak-jsts"

Restart Kakoune or re-source your kakrc and call the plug-install command.

Without plugin manager

Clone this repository to your autoload directory, or source the rc/jsts.kak file from your kakrc.

Usage

Formatting:

kak-jsts provides three new commands:

  1. format-eslint
  2. format-prettier
  3. format-tslint

format-eslint and format-pretter will format your buffer without touching the disk. Due to a limitation in tslint, your buffer will be written, formatted on disk, and then reloaded.

All formatting will be done according to your local project preferences, e.g. in .eslintrc.js. Kakoune must run in the root of the project for that to work.

Other

kak-jsts provides implementations for common kakoune commands:

  1. alt
  2. lint

alt jumps to the alternate file (implementation ↔ test). Jumps between implementation und .test.(js|ts) or .spec.(js|ts) in the same directory. alt is an alias to jsts-alternative-file.

Kak-jsts sets Kakoune's lint command to use eslint for JavaScript and TypeScript files.

Linting will be done according to your local project preferences, e.g. in .eslintrc.js. Kakoune must run in the root of the project for that to work.

Configuration Examples

plug "schemar/kak-jsts" config %{
    hook global WinSetOption filetype=(javascript|typescript) %{
        map window user l -docstring 'lint' ': lint<ret>'
        map window user f -docstring 'format' ': format-eslint<ret>'
        
        # If you want to format before every write, you could do s.th. like this:
        hook window BufWritePre .* %{
            evaluate-commands -no-hooks %{
                format-eslint
            }
        }
    }
}

If you use different formatters in different projects, you can source a local kakrc where you overwrite the formatting command, for example to be format-prettier. See IDE on the Kakoune Wiki for more info about that.

About

JavaScript / TypeScript extension for the Kakoune editor.

License:The Unlicense