sublimetext3是一款跨平臺代碼編輯器軟件,sublimetext3既可以編寫代碼還可以編輯文本,是程序員必不可少的工具。下面由sublime使用教程欄目為大家介紹關于sublimetext3配置react語法校驗,希望對需要的朋友有所幫助!
1. 安裝nodejs
2. 打開終端,安裝eslint校驗包和react校驗插件包:
npm?install?-g?eslint npm?install?-g?eslint-plugin-react
3. 在Sublime中安裝插件:
SublimeLinter SublimeLinter-contrib-eslint
4. 運行eslint –init
根據提示配置初始化文件,生成.json格式的
5. 配置.eslintrc
.eslintrc.json
{ ????????"plugins":?[ ????????????????//?"react", ????????????????"html" ????????], ????????"env":?{ ????????????????"node":?true, ????????????????"jquery":?true, ????????????????"es6":?true, ????????????????"browser":?true ????????}, ????????"globals":?{ ????????????????"angular":?false ????????}, ????????"parser":?"babel-eslint", ????????"rules":?{ ????????????????//官方文檔?http://eslint.org/docs/rules/ ????????????????//參數:0?關閉,1?警告,2?錯誤 ????????????????//?"quotes":?[0,?"single"],??????????????????//建議使用單引號 ????????????????//?"no-inner-declarations":?[0,?"both"],?????//不建議在{}代碼塊內部聲明變量或函數 ????????????????"no-extra-boolean-cast":?1,?//多余的感嘆號轉布爾型 ????????????????"no-extra-semi":?1,?//多余的分號 ????????????????"no-extra-parens":?0,?//多余的括號 ????????????????"no-empty":?1,?//空代碼塊 ? ????????????????//使用前未定義 ????????????????"no-use-before-define":?[ ????????????????????????0, ????????????????????????"nofunc" ????????????????], ? ????????????????"complexity":?[0,?10],?//圈復雜度大于* ? ????????????????//定義數組或對象最后多余的逗號 ????????????????"comma-dangle":?[ ????????????????????????0, ????????????????????????"never" ????????????????], ? ????????????????//?不允許對全局變量賦值,如?window?=?'abc' ????????????????"no-global-assign":?["error",?{ ????????????????????????//?定義例外 ????????????????????????//?"exceptions":?["Object"] ????????????????}], ????????????????"no-var":?0,?//用let或const替代var ????????????????"no-const-assign":?2,?//不允許const重新賦值 ????????????????"no-class-assign":?2,?//不允許對class重新賦值 ????????????????"no-debugger":?1,?//debugger?調試代碼未刪除 ????????????????"no-console":?0,?//console?未刪除 ????????????????"no-constant-condition":?2,?//常量作為條件 ????????????????"no-dupe-args":?2,?//參數重復 ????????????????"no-dupe-keys":?2,?//對象屬性重復 ????????????????"no-duplicate-case":?2,?//case重復 ????????????????"no-empty-character-class":?2,?//正則無法匹配任何值 ????????????????"no-invalid-regexp":?2,?//無效的正則 ????????????????"no-func-assign":?2,?//函數被賦值 ????????????????"valid-typeof":?1,?//無效的類型判斷 ????????????????"no-unreachable":?2,?//不可能執行到的代碼 ????????????????"no-unexpected-multiline":?2,?//行尾缺少分號可能導致一些意外情況 ????????????????"no-sparse-arrays":?1,?//數組中多出逗號 ????????????????"no-shadow-restricted-names":?2,?//關鍵詞與命名沖突 ????????????????"no-undef":?1,?//變量未定義 ????????????????"no-unused-vars":?1,?//變量定義后未使用 ????????????????"no-cond-assign":?2,?//條件語句中禁止賦值操作 ????????????????"no-native-reassign":?2,?//禁止覆蓋原生對象 ????????????????"no-mixed-spaces-and-tabs":?0, ? ? ? ????????????????//代碼風格優化?-------------------------------------- ????????????????"no-irregular-whitespace":?0, ????????????????"no-else-return":?0,?//在else代碼塊中return,else是多余的 ????????????????"no-multi-spaces":?0,?//不允許多個空格 ? ????????????????//object直接量建議寫法?:?后一個空格前面不留空格 ????????????????"key-spacing":?[ ????????????????????????0, ????????????????????????{ ????????????????????????????????"beforeColon":?false, ????????????????????????????????"afterColon":?true ????????????????????????} ????????????????], ? ????????????????"block-scoped-var":?1,?//變量應在外部上下文中聲明,不應在{}代碼塊中 ????????????????"consistent-return":?1,?//函數返回值可能是不同類型 ????????????????"accessor-pairs":?1,?//object?getter/setter方法需要成對出現 ? ????????????????//換行調用對象方法??點操作符應寫在行首 ????????????????"dot-location":?[ ????????????????????????1, ????????????????????????"property" ????????????????], ????????????????"no-lone-blocks":?1,?//多余的{}嵌套 ????????????????"no-labels":?1,?//無用的標記 ????????????????"no-extend-native":?1,?//禁止擴展原生對象 ????????????????"no-floating-decimal":?1,?//浮點型需要寫全?禁止.1?或?2.寫法 ????????????????"no-loop-func":?1,?//禁止在循環體中定義函數 ????????????????"no-new-func":?1,?//禁止new?Function(...)?寫法 ????????????????"no-self-compare":?1,?//不允與自己比較作為條件 ????????????????"no-sequences":?1,?//禁止可能導致結果不明確的逗號操作符 ????????????????"no-throw-literal":?1,?//禁止拋出一個直接量?應是Error對象 ? ????????????????//不允return時有賦值操作 ????????????????"no-return-assign":?[ ????????????????????????1, ????????????????????????"always" ????????????????], ? ????????????????//不允許重復聲明 ????????????????"no-redeclare":?[ ????????????????????????1, ????????????????????????{ ????????????????????????????????"builtinGlobals":?true ????????????????????????} ????????????????], ? ????????????????//不執行的表達式 ????????????????"no-unused-expressions":?[ ????????????????????????0, ????????????????????????{ ????????????????????????????????"allowShortCircuit":?true, ????????????????????????????????"allowTernary":?true ????????????????????????} ????????????????], ????????????????"no-useless-call":?1,?//無意義的函數call或apply ????????????????"no-useless-concat":?1,?//無意義的string?concat ????????????????"no-void":?1,?//禁用void ????????????????"no-with":?1,?//禁用with ????????????????"space-infix-ops":?0,?//操作符前后空格 ? ????????????????//jsdoc ????????????????"valid-jsdoc":?[ ????????????????????????0, ????????????????????????{ ????????????????????????????????"requireParamDescription":?true, ????????????????????????????????"requireReturnDescription":?true ????????????????????????} ????????????????], ? ????????????????//標記未寫注釋 ????????????????"no-warning-comments":?[ ????????????????????????1, ????????????????????????{ ????????????????????????????????"terms":?[ ????????????????????????????????????????"todo", ????????????????????????????????????????"fixme", ????????????????????????????????????????"any?other?term" ????????????????????????????????], ????????????????????????????????"location":?"anywhere" ????????????????????????} ????????????????], ????????????????"curly":?0?//if、else、while、for代碼塊用{}包圍 ????????} }
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END