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配置,真的很方便。

原文地址:https://www.cnblogs.com/yangzhou33/p/8526098.html

时间: 2024-08-30 14:34:39

Create-React-App项目外使用它的eslint配置的相关文章

React漫漫学习路之 利用Create React App命令创建一个React应用

所谓万事开头难,本文旨在为初探React的同学,建立第一个最基本的react应用. Create React App是Facebook官方的一个快速构建新的 React 单页面应用的脚手架工具,它可以帮你配置开发环境,以便你可以使用最新的 JavaScript 特性,还能提供很棒的开发体验,并为生产环境优化你的应用.(如果你使用过vue-cli构建vue应用,那么此处可类比) 话不多说,直接开始. 安装 全局安装create-react-app npm install -g create-rea

[React] {svg, css module, sass} support in Create React App 2.0

create-react-app version 2.0 added a lot of new features. One of the new features is added the svgr webpack loader to wrap SVGs in React components as a named export. This let’s you either grab the filename from the default export or grab a wrapped S

create react app遇到的问题

我现在想的是吧 static 资源和动态 api 来分开处理, static 资源开启 nginx 服务器,api 请求由 express 完成, 现在的问题是开发的时候 proxy 设定将所有的请求都代理到了 express 的端口,甚至于 <a></a> 元素的链接也被代理到 express 的端口了,在这个页面根本获取不到 nginx 提供的资源.

引用项目外dll时不显示注释的解决方案

在引用项目外的dll时,显示类库中的注释可按以下步骤: 方法或变量用summary添加注释,如: /// <summary>发送post请求 /// </summary>        /// <param name="url">请求的url</param>        /// <param name="postString">发送到数据 例如:"name=xhan&password=1

[React] Create &amp; Deploy a Universal React App using Zeit Next

In this lesson, we'll use next to create a universal React application with no configuration. We'll create page components that will render on the server if accessed directly, but function as you would expect in the client. We'll use the routing capa

在使用安卓模拟器调试react native项

在使用安卓模拟器调试react native项目时报错 "xxx keeps stopping" (xxx,项目名). 起因是代码里有一个地方属性值写错了,应该是"space-around",导致项目运行错误,这种情况下,就算改正了,再刷新也还是会报错. 解决办法,找到bug并修复这是必须的,然后,你需要重新执行react-native run-android  (必要时在模拟器里卸载app再执行react-native run-android). http://p

用weex create 创建app项目 报 ERROR in index.web.js from UglifyJs 错误!

用weex create创建一个APP项目,安装依赖后运行报 这个是package.json index.web.js 在dist目录下是build时生成的. 上面的答案没有给大家细节,不好意思致歉下面进行补充: 卸载 npm uninstall weex-toolkit -g // 卸载后一定用weex -v看下卸载了没!!! 到你node 安装的目录下的nodejs下node_modules看weex-toolkit 还在没!!!(windows)如果在删除之后再次重复上面的命令 删除 .x

把自己的电脑做服务器发布tomcat的项目外网访问

1.首先你要确定你有一个外网ip地址.如果你分配到的是一个局域网IP地址需要经过一系列的转换为外网ip地址,然后继续下面操作. 2.拿到外网IP地址,进行tomcat的server.xml文件的配置.主要进行下面三个地方的配置(本次配置采用的tomcat版本号是7.0.30) 1)<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort=&

yii2:引用项目外的文件或类

以项目:frontend为例,文件目录如下: frontend/    frontend/controllers    frontend/views    frontend/runtime    ...... other/    other/phpexcel/ ...... 在frontend/controllers/IndexController.php方法中:actionIndex中,引用 PHPExcel类: $excelpath = dirname(Yii::$app->basePath