Eslint简介
eslint是一个被广泛应用的javascript/jsx代码检查工具。
eslint配置文件可以使用js/yaml/json格式,或者在package.json中添加"eslintConfig"选项。.eslintrc已被废弃。js格式更为灵活,react项目用的是js后缀,即.eslintrc.js。
extends
extends 是指扩展eslint官方支持的lint规则
extends: 'fbjs',
fbjs 是eslint-config-fbjs 和简写,对应npm模块eslint-config-fbjs。从这个配置中,我们可以看到react没有使用eslint默认的解析器Espree ,而是选择了babel-eslint 。为什么呢?看babel-eslint 官方介绍,当且仅当你使用了强类型如(Flow)或者一些eslint不支持的仍处于实验阶段的js特性时,你才需要使用babel-eslint 。
You only need to use babel-eslint if you are using types (Flow) or experimental features not supported in ESLint itself yet. Otherwise try the default parser (you don't have to use it just because you are using Babel)
plugins
plugins 是指通过自定义插件,扩展可用的lint规则。比如eslint-react插件,就自定义了跟jsx语法相关的lint规则。
plugins: [
'react','react-internal',],
上面的react 是eslint-plugin-react 的简称。react-internal 是eslint-plugin-react-internal 的简称。
原文:https://github.com/liushuigs/react-source-learning/blob/master/root/what-is-eslint.md (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|