Skip to content

Instantly share code, notes, and snippets.

@guahsu
Last active February 3, 2019 15:25
Show Gist options
  • Save guahsu/1e0f636b912c72c0da8803c108681cac to your computer and use it in GitHub Desktop.
Save guahsu/1e0f636b912c72c0da8803c108681cac to your computer and use it in GitHub Desktop.
Create-react-app 加入 StandardJS

Create-react-app 加入 StandardJS

1. 執行npm run eject

2. 安裝 eslint & standard

npm install --save-dev eslint standard eslint-config-standard eslint-config-standard-react eslint-plugin-promise eslint-plugin-react eslint-plugin-standard

3. 建立 .eslintrc 到根目錄(與package.json同層)

{
  "parser": "babel-eslint", // 使eslint支援新語法
  "extends": ["standard", "standard-react"],
  "rules": {
    // 如果有使用prop-types, 所有class都會要求使用, 可用這設定忽略檢查
    "react/prop-types": [
      "enabled",
      { "ignore": "ignore", "customValidators": "customValidator" }
    ]
  }
}

4. 執行standard —fix

檢查並修正所有js的格式,要注意,任何window物件都要加上window。
例如 serviceWorker裡面的fetch要改成window.fetch

其他

開發時需要使用debudder時,需繞過檢查改使用:debugger // eslint-disable-line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment