zoukankan      html  css  js  c++  java
  • Create-React-App项目外使用它的eslint配置

    概述

    使用Create-React-App脚手架感觉它的eslint配置有点好用,于是考虑不用Create-React-App脚手架该怎么使用这些配置。

    我于是eject了Create-React-App脚手架,查看它的详细配置和官方文档,总结了使用它的eslint配置的方法,记录如下,供以后开发时参考,相信对其它人也有用。

    配置

    (1)首先安装依赖:

    npm install eslint --save-dev
    npm install babel-eslint --save-dev
    npm install eslint-plugin-flowtype --save-dev
    npm 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配置,真的很方便。

  • 相关阅读:
    tensor张量
    Image Stride(内存图像行跨度)
    Batch Normalization
    论文阅读
    codeforces 520B
    codeforces 467B
    C语言位运算
    codeforces 474D
    codeforces 545c
    codeforces 698A
  • 原文地址:https://www.cnblogs.com/yangzhou33/p/8526098.html
Copyright © 2011-2022 走看看