![](/img/trans.png)
[英]How to setup Atom editor to use only the react-native-community eslint-config?
[英]How to config ESLint for React on Atom Editor
在Atom Editor中,我安裝了以下插件
它們似乎無法識別JSX語法。
我讓它在命令行上工作,但不得不使用其他插件,如esprima-fb
和eslint-plugin-react
。 看起來Atom編輯器沒有這樣的插件,想知道你是否有人知道如何解決這個問題。
讓Eslint與React.js很好地配合:
npm install eslint-plugin-react
"plugins": ["react"]
到.eslintrc配置文件中 "ecmaFeatures": {"jsx": true}
到.eslintrc配置文件中 以下是.eslintrc
配置文件的示例:
{
"env": {
"browser": true,
"node": true
},
"globals": {
"React": true
},
"ecmaFeatures": {
"jsx": true
},
"plugins": [
"react"
]
}
我目前正在使用Eslint v1.1.0。
旁注 :我必須安裝eslint和eslint-plugin-react作為項目依賴項(例如, npm install eslint eslint-plugin-react --save-dev
)。 希望這會有所幫助。
2016年的更新答案:只需在Atom中安裝react
包,並在項目根目錄(或主目錄)中添加一個.eslintrc
文件,其中包含以下內容:
{
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"es6": true
}
}
並重新打開包含JSX的任何文件,它應該工作。
您需要編輯一個項目本地.eslintrc
文件,該文件將被ESLint選中。 如果你想用的Atom集成,您可以安裝插件棉短絨和棉短絨,eslint 。
要快速設置ESLint for React最佳實踐,當前最佳選擇是安裝npm包eslint-plugin-react
並擴展其recommended
配置,而不是手動切換許多規則:
{
"extends": [ "eslint:recommended", "plugin:react/recommended" ],
"plugins": [ "react" ]
}
這將啟用eslint-plugin-react
和React預設的eslint-plugin-react
和推薦規則。 最新的ESLint 用戶指南本身提供了更多有價值的信息。
以下是針對ES6和webpack優化的解析器選項示例:
{
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 6,
"ecmaFeatures": {
"impliedStrict": true,
"experimentalObjectRestSpread": true,
"jsx": true
}
}
}
我使用Atom,它工作得很好。 你只需要一個.eslintrc
項目中的根,它告訴您使用ESLint eslint-plugin-react
。
對於Mac用戶:轉到Atom - >首選項 - >安裝 - >搜索包linter-eslint - >單擊安裝
對於Ubuntu用戶:轉到編輯 - >首選項 - >安裝 - >搜索包linter-eslint - >單擊安裝
轉到命令行---> npm install --save-dev eslint-config-rallycoding
來源原子制作新文件.eslintrc並擴展拉力賽編碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.