# Anyone have a successful lint setup for js/ts?

**URL:** <https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409>\
**Category:** Help\
**Tags:** lint\
**Created:** [March 27, 2019, 2:04am UTC](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409 "2019-03-27T02:04:37Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [May 2, 2020, 4:34pm UTC](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409/21 "2020-05-02T16:34:17Z")

</div>

this will create file without name clash at the same location: `file=$(mktemp "$kak_buffile.XXXXXXXXX")`, and the name will be stored in `file`, you then can format, pipe back, and delete it in single shell call.

---

<div class="post-metadata">

**Author:** ![schemar](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/schemar/32/502_2.png) [@schemar](https://discuss.kakoune.com/u/schemar)\
**Post date:** [May 2, 2020, 7:44pm UTC](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409/22 "2020-05-02T19:44:06Z")

</div>

I made it work without writing a temp file.

The eslint formatter `json` includes the fixed file in its output if `--fix-dry-run` is set. I then use `jq` to parse the JSON output:

```auto
define-command -hidden eslint-format %{
    evaluate-commands -draft -no-hooks -save-regs '|' %{
        # Select all to format
        execute-keys '%'

        # eslint does a fix-dry-run with a json formatter which results in a JSON output to stdout that includes the fixed file.
        # jq then extracts the fixed file output from the JSON. -j returns the raw output without any escaping.
        set-register '|' %{
            %sh{
                echo "$kak_selection" | \
                npx eslint --format json \
                           --fix-dry-run \
                           --stdin \
                           --stdin-filename "$kak_buffile" | \
                jq -j ".[].output"
            }
        }

        # Replace all with content from register:
        execute-keys '|<ret>'
    }
}

```

How can I restore the cursor position after formatting (a simple mark? somehow `execute-keys 'Z'` leaves me with an empty `^` so that `execute-keys z` afterwards returns an error)

I added this as an alternative to the Wiki: [https://github.com/mawww/kakoune/wiki/Lint#javascript-eslint](https://github.com/mawww/kakoune/wiki/Lint#javascript-eslint)

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [May 3, 2020, 3:16pm UTC](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409/23 "2020-05-03T15:16:39Z")

</div>

I think you can make it into a package

---

<div class="post-metadata">

**Author:** ![schemar](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/schemar/32/502_2.png) [@schemar](https://discuss.kakoune.com/u/schemar)\
**Post date:** [May 7, 2020, 7:59pm UTC](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409/24 "2020-05-07T19:59:49Z")

</div>

It is done, a **successful lint/format setup for js/ts:**

> **[GitHub - schemar/kak-jsts: JavaScript / TypeScript extension for the Kakoune...](https://github.com/schemar/kak-jsts)**
>
> JavaScript / TypeScript extension for the Kakoune editor. - GitHub - schemar/kak-jsts: JavaScript / TypeScript extension for the Kakoune editor.

@jssee do you still need this? 😉

I want to add it to the Wiki, but I am not sure where. Under [Languages](https://github.com/mawww/kakoune/wiki/Languages)? The currently linked TypeScript repo doesn’t work with the latest Kakoune anyways, I could replace it. Kakoune has built-in support for TypeScript syntax highlighting by now anyways, if I see that correctly.

By the way, I have on issue that I cannot fix. The lint command requires the path to the globally installed `node_modules`. I cannot set it as an option with `$kak_opt_...` as it seems that won’t be available due to how [`lint.kak`](https://github.com/mawww/kakoune/blob/master/rc/tools/lint.kak) is implemented. Any way how that could be done better than asking users of the plugin to replace the whole `lintcmd` in case it isn’t the default path for them?

Maybe @robertmeta or @alexherbo2 have an idea? 🤔

Anyways, I hope this will help others 😊

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [May 8, 2020, 6:01am UTC](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409/25 "2020-05-08T06:01:26Z")

</div>

I don’t think this should go to that wiki page, as it is about builtin language support (Unless you wish to contribute your work to Kakoune directly 🙂) . I think you should add tags to the repo so it could be visible on plugin page at [Kakoune - Plugins](https://kakoune.org/plugins.html)

---

<div class="post-metadata">

**Author:** ![schemar](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/schemar/32/502_2.png) [@schemar](https://discuss.kakoune.com/u/schemar)\
**Post date:** [May 8, 2020, 5:56pm UTC](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409/26 "2020-05-08T17:56:57Z")

</div>

Ok, it is done and working. `npm list` to the rescue. Unfortunately it is very slow, but now it should work on most systems and linting runs asynchronously anyways.

```auto
set window lintcmd 'run() { cat "$1" | npx eslint --format "$(npm list -g --depth=0 | head -1)/node_modules/eslint-formatter-kakoune/index.js" --stdin --stdin-filename "${kak_buffile}";} && run '

```

I am really happy with how this worked out in the end. Linting and formatting works very well now. Was not super straight-forward to set up 😅

If anyone comes here looking for a working integration with `eslint`, please try the kak-jsts project I linked above 🙂

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [May 8, 2020, 6:41pm UTC](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409/27 "2020-05-08T18:41:26Z")

</div>

I have done shockingly little to get my TS setup working well (linting, prettier, autocomplete, etc). Thanks to kak-lsp!

---

<div class="post-metadata">

**Author:** ![schemar](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/schemar/32/502_2.png) [@schemar](https://discuss.kakoune.com/u/schemar)\
**Post date:** [May 9, 2020, 8:41am UTC](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409/28 "2020-05-09T08:41:11Z")

</div>

That sounds great. Did you integrate eslint with lsp-kak formatting and diagnostics?

---

<div class="post-metadata">

**Author:** ![jssee](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jssee/32/108_2.png) [@jssee](https://discuss.kakoune.com/u/jssee)\
**Post date:** [May 18, 2020, 4:47am UTC](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409/29 "2020-05-18T04:47:57Z")

</div>

This is great, thanks so much for putting it together

[Previous page](https://discuss.kakoune.com/t/anyone-have-a-successful-lint-setup-for-js-ts/409.md?page=1)
