-
-
Save kreedz/d883d8cce52a6e0c0a73901d4c7bb62b to your computer and use it in GitHub Desktop.
JS support in Emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part of package.json with eslint configuration I use. | |
// You'll need eslint-plugin-prettier in your dev dependencies | |
// and probably a bunch of other things. Eslint will complain. | |
// Just install what it asks for. | |
"eslintConfig": { | |
"extends": "react-app", | |
"plugins": [ | |
"prettier" | |
], | |
"rules": { | |
"prettier/prettier": [ | |
"error" | |
] | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; JSON tree viewer | |
(use-package | |
json-navigator) | |
;; Smaller fixes to the js2-mode to make it work fine with tide-mode. | |
(use-package | |
js2-mode | |
:delight "JS" | |
:init | |
(setq js2-mode-show-strict-warnings nil) | |
(setq js2-mode-show-parse-errors nil) | |
:config (add-to-list 'auto-mode-alist '("\\.js\\'" . | |
js2-mode))) | |
;; A very fast JS linter and fixer. | |
;; npm install -g eslint_d | |
(use-package eslintd-fix | |
:hook | |
(tide-mode . eslintd-fix-mode)) | |
;; Autofix missing imports. | |
(use-package import-js) | |
;; React | |
(use-package | |
rjsx-mode | |
:delight "JSX" | |
:diminish js2-mode | |
:config | |
;; Try to detect React files by react and recompose imports. | |
(add-to-list 'magic-mode-alist '("\\'recompose" . rjsx-mode)) | |
(add-to-list 'magic-mode-alist '("\\'react" . rjsx-mode)) | |
;; Detect React files by extension. | |
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . rjsx-mode))) | |
;; Hide unneeded mode icon | |
(use-package js | |
:diminish) | |
;; Setup Tide mode for JS and Typescript. | |
;; To make it work you'll need jsconfig.js or tsconfig.js | |
;; in your project's root folder. | |
;; Includes: | |
;; - types and structures inference | |
;; - jump to (M-.) and back (M-,) | |
;; - show references (M-x tide-references) | |
;; And a lot of other goodies https://github.com/ananthakumaran/tide | |
(use-package tide | |
:ensure t | |
:after (typescript-mode company) | |
:hook ((typescript-mode . tide-setup) | |
(typescript-mode . tide-hl-identifier-mode) | |
(js2-mode . tide-setup) | |
(rjsx-mode . tide-setup))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "es2017", | |
"allowSyntheticDefaultImports": true, | |
"noEmit": true, | |
"checkJs": true, | |
"jsx": "react", | |
"lib": [ "dom", "es2017" ] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment