Create-React-App項目外使用它的eslint配置

來源:互聯網
上載者:User

標籤:bool   uri   class   不用   ocs   ext   報錯   uid   概述   

概述

使用Create-React-App腳手架感覺它的eslint配置有點好用,於是考慮不用Create-React-App腳手架該怎麼使用這些配置。

我於是eject了Create-React-App腳手架,查看它的詳細配置和官方文檔,總結了使用它的eslint配置的方法,記錄如下,供以後開發時參考,相信對其它人也有用。

配置

(1)首先安裝依賴:

npm install eslint --save-devnpm install babel-eslint --save-devnpm install eslint-plugin-flowtype --save-devnpm install eslint-plugin-jsx-a11y --save-dev

(2)然後配置package.json檔案。(不需要配置.eslintrc.js檔案,詳見Eslint Configuring文檔)

"eslintConfig": {  "parser": "babel-eslint",  "extends": [    "plugin:flowtype/recommended",    "plugin:jsx-a11y/recommended"  ],  "plugins": [    "flowtype",    "jsx-a11y"  ]}

(3)在主目錄下面輸入eslint + 檔案名稱即可。比如eslint test.js

測試是否生效

測試內容如下,如果有5個報錯,那麼證明是生效的。

type X = bool// Message: Use "boolean", not "bool"// Options: ["boolean"]type X = bool// Message: Use "boolean", not "bool"// Options: ["bool"]type X = boolean// Message: Use "bool", not "boolean"
感想

以前用eslint的時候感覺每次要配置.eslintrc.js檔案超級麻煩,現在才發現可以直接在package.json配置,真的很方便。

Create-React-App項目外使用它的eslint配置

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.