Skip to content

Commit

Permalink
feat(emacs): support TypeScript in Flymake plugin
Browse files Browse the repository at this point in the history
Use --language=experimental-default in the Flymake plugin so
quick-lint-js parses .ts files as TypeScript files. To make this work
with --stdin, use --stdin-path as well.
  • Loading branch information
strager committed Oct 19, 2023
1 parent bf0541d commit 8139e0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Semantic Versioning.
* TypeScript support (still experimental):
* CLI: The new `--language=experimental-default` option auto-detects the
language based on the file's extension (`.ts`, `.tsx`, `.d.ts`, or `.js`).
* Emacs: Flymake plugin users can now opt into TypeScript support. See the
[Flymake configuration instructions][emacs-configure-flymake].
* Class method overload signatures are now parsed.
* [E0398][] is now reported when using both `abstract` and `static` on a
single class property.
Expand Down Expand Up @@ -1066,6 +1068,7 @@ Beta release.
[coc.nvim]: https://github.com/neoclide/coc.nvim
[config-global-groups]: https://quick-lint-js.com/config/#global-groups
[cross-compiling-quick-lint-js]: https://quick-lint-js.com/contribute/build-from-source/cross-compiling/
[emacs-configure-flymake]: https://quick-lint-js.com/install/emacs/configure/#flymake
[install-powershell-completions]: https://github.com/quick-lint/quick-lint-js/blob/master/completions/README.md#powershell

[AidenThing]: https://github.com/AidenThing
Expand Down
10 changes: 9 additions & 1 deletion plugin/emacs/flymake-quicklintjs.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
:group 'flymake-quicklintjs
:type '(repeat string))

(defcustom flymake-quicklintjs-experimental-typescript nil
"Enable experimental TypeScript support (EXPERIMENTAL; subject to change in future versions of quick-lint-js)."
:group 'flymake-quicklintjs
:type '(boolean))

(defvar-local flymake-quicklintjs--proc nil
"Internal variable for `flymake-quicklintjs'")

Expand Down Expand Up @@ -74,8 +79,11 @@ REPORT-FN is Flymake's callback."
:command `(,flymake-quicklintjs-program
,@(let ((file (buffer-file-name)))
(if file
`("--path-for-config-search" ,file)
`("--stdin-path" ,file)
()))
,@(if flymake-quicklintjs-experimental-typescript
`("--language=experimental-default")
())
"--stdin" "--output-format=emacs-lisp"
,@flymake-quicklintjs-args)
:sentinel
Expand Down
10 changes: 9 additions & 1 deletion website/public/install/emacs/configure/index.ejs.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,15 @@ <h2 id="flymake">Flymake</h2>
;; Optional: Remove the time to wait after last change before automatically
;; checking buffer. The default is 0.5 (500ms)
(setq-local flymake-no-changes-timeout 0))
(add-hook 'js-mode-hook #'my-flymake-quicklintjs-setup)</code></pre>
(add-hook 'js-mode-hook #'my-flymake-quicklintjs-setup)

;; Optional: Enable TypeScript support. Requires quick-lint-js version
;; 2.17.0 or newer.
;; EXPERIMENTAL. Subject to change in future versions of
;; quick-lint-js.
(add-hook 'typescript-mode-hook #'my-flymake-quicklintjs-setup)
(setq flymake-quicklintjs-experimental-typescript t)
</code></pre>

<h2 id="lsp-mode">LSP Mode</h2>
<p>
Expand Down

0 comments on commit 8139e0a

Please sign in to comment.