首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在js2-mode中使用flycheck进行缩进设置

在js2-mode中使用flycheck进行缩进设置
EN

Stack Overflow用户
提问于 2018-02-12 00:31:08
回答 1查看 362关注 0票数 3

我在Emacs25.2上启用了js2模式和flycheck/eslint。

当前按tab (或换行符)将按照js2-mode-js- indent -level进行缩进。

我希望它是动态的,以匹配flycheck/eslint设置

有没有办法做到这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-31 20:20:57

Emacs已经提供了解析配置(本例中为eslint配置)的工具。

解析配置并将缩进配置设置为js-indent-level

代码语言:javascript
复制
(defun js2-mode-use-eslint-indent ()
  (let ((json-object-type 'hash-table)
    (json-config (shell-command-to-string (format  "eslint --print-config %s"
                               (shell-quote-argument
                            (buffer-file-name))))))
    (ignore-errors
      (setq js-indent-level
        (aref (gethash "indent" (gethash  "rules" (json-read-from-string json-config))) 1)))))

(add-hook 'js2-mode-hook #'js2-mode-use-eslint-indent)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48733723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档