淺談atom中eslint的配置和使用方法

本篇文章給大家介紹一下eslint & atom 配合使用。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有所幫助。

淺談atom中eslint的配置和使用方法

【相關推薦:《atom》】

下載aotm插件 linter-eslinthttps://github.com/AtomLinter/linter-eslint

需要設置如下:

  • Install locally to your project eslint and the plugin
    • $ npm i –save-dev eslint [eslint-plugins]
  • Install globally eslint and plugins
    • $ npm i -g eslint [eslint-plugins]
    • Activate Use Global Eslint package option
    • (Optional) Set Global Node Path with $ npm config get prefix

提供了一些插件,可自行下載(ps: 版本差異會導致部分插件報錯)

  • eslint-config-airbnb
  • eslint-plugin-import
  • eslint-plugin-jsx-a11y
  • eslint-plugin-react
  • eslint-plugin-html (可解析html中的腳本, 最新的版本v4跟早期eslint有沖突)

然后在項目下
$ eslint –init


使用以下注釋,關閉提示。

/*?eslint-disable?*/

使用eslintignore 忽略特定的文件和目錄

創建一個 .eslintignore 文件,添加需要過濾的文件夾,或者文件

?build/* ?app/lib/*

命令行使用 –ignore-path:

$ eslint –ignore-path .eslintignore –fix app/*

路徑是相對于 .eslintignore 的位置或當前工作目錄

更多查看 http://eslint.cn/docs/user-guide/configuring

基礎配置:

module.exports?=?{ ????parser:?'babel-eslint',  ????"env":?{ ????????"browser":?true, ????????"commonjs":?true, ????????"es6":?true ????},  ????//?以當前目錄為根目錄,不再向上查找?.eslintrc.js ????root:?true,  ????//?禁止使用?空格?和?tab?混合縮進 ????"extends":?"eslint:recommended",  ????globals:?{ ????????//?這里填入你的項目需要的全局變量 ????????//?jQuery:?false, ????????$:?false, ????????wx:?false, ????}, ???? ????//?eslint-plugin-html?開啟 ????"plugins":?[ ????????"html" ????],  ????"parserOptions":?{ ????????"ecmaFeatures":?{ ????????????"jsx":?false ????????}, ????????"sourceType":?"module" ????},  ????"rules":?{ ????????"indent":?["error",?'tab'],  ????????"linebreak-style":?["error","unix"],  ????????"quotes":?["error","single"],  ????????"semi":?["error","always"],  ????????"semi":?["error","always"],  ????????"arrow-spacing":?["error",?{?"before":?true,?"after":?true?}],  ????????"no-unused-vars":?"off",?//禁止提示沒有使用的變量,或者函數  ????????"block-spacing":?"error",  ????????"no-console":?"off",?//可以使用console  ????????"keyword-spacing":?["error",?{?"before":?true?}]?//強制關鍵字周圍空格的一致性  ????} };

更多編程相關知識,請訪問:atom!!

? 版權聲明
THE END
喜歡就支持一下吧
點贊8 分享