UNPKG

eslint-config-myplugin

Version:

myplugin eslint shareable configs

78 lines (61 loc) 4.96 kB
# eslint-config-sunlands ## 介绍 用于约束 js、es6 以及 vue 的代码风格及规范 ## 规则 1. 2 个空格改为 4 个空格 2. 结尾不需要加分号 3. JSX 能够写在 .js 文件中 4. no-static-element-interactions(warning) 5. JSX 及 JSX prop 缩进 4 个空格 6. 依赖类型安装错误,等级从 error 改为 warning 7. 对于function显示声明但是并没有用到的参数,从error降级到warn,参考issue [ "no-unused-vars": ["error", {"args": "none"}], ](http://172.16.117.224/fe/eslint-config-sunlands/issues/6) 8. label 不再强制指定for属性,参考issue [label-has-for](http://172.16.117.224/fe/eslint-config-sunlands/issues/3) 9. 可以在数组中使用数组索引作为react component的id,参考issue [Do not use Array index in keys](http://172.16.117.224/fe/eslint-config-sunlands/issues/1) 1. 允许对函数参数修改或重新赋值,从error降低到warn级别,参考issue [no-param-reassign](http://172.16.117.224/fe/eslint-config-sunlands/issues/5) 11. 允许传参时对参数进行换行,从error降低到warn级别,参考issue [function-paren-newline](http://172.16.117.224/fe/eslint-config-sunlands/issues/16) 12. 允许单个文件里声明多个component,参考issue [react/no-multi-comp](http://172.16.117.224/fe/eslint-config-sunlands/issues/13) 13. 允许陈列无用的参数,参考issue [no-unused-vars](http://172.16.117.224/fe/eslint-config-sunlands/issues/6) 14. 忽略了若干组件自动传入的props,这些props不再需要声明propTypes做类型检查。参考issue [初次会议讨论的一些规则改动](http://172.16.117.224/fe/eslint-config-sunlands/issues/2) [props validation 添加更多忽略字段](http://172.16.117.224/fe/eslint-config-sunlands/issues/11) 15. 去除Link元素对href属性的检查,参考issue [jsx-a11y/anchor-is-valid](http://172.16.117.224/fe/eslint-config-sunlands/issues/10) 16. 不强制给绑定了鼠标事件的元素添加键盘事件,参考issue [jsx-a11y/click-events-have-key-events](http://172.16.117.224/fe/eslint-config-sunlands/issues/14) 17. 鼠标事件不再强制绑定键盘事件了,参考issue [jsx-a11y/mouse-events-have-key-events](http://172.16.117.224/fe/eslint-config-sunlands/issues/22) 18. 不能互动的元素也可以绑定事件,参考issue [不能互动的元素不能绑定事件](http://172.16.117.224/fe/eslint-config-sunlands/issues/19) 19. 一个文件只有一个输出值的时候不强制用default输出,参考issue [import/prefer-default-export](http://172.16.117.224/fe/eslint-config-sunlands/issues/18) 20. 单行最大长度调整到180字符。 21. video等标签不强制添加字幕,参考issue [jsx-a11y/media-has-caption](http://172.16.117.224/fe/eslint-config-sunlands/issues/27) 22. case语句中允许声明变量,改为warn,参考issue [no-case-declarations](http://172.16.117.224/fe/eslint-config-sunlands/issues/26) 23. 允许带Script脚本的href属性,参考issue [no-script-url](http://172.16.117.224/fe/eslint-config-sunlands/issues/25) 24. 允许void语句,参考issue [no-void](http://172.16.117.224/fe/eslint-config-sunlands/issues/24) 25. 禁用规则 class-methods-use-this,参考issue[禁用规则 class-methods-use-this](http://172.16.117.224/fe/eslint-config-sunlands/issues/28) 26. 禁用规则 no-continue,参考issue[no-continue](http://172.16.117.224/fe/eslint-config-sunlands/issues/30) 27. 禁用规则 jsx-a11y/media-has-caption,参考issue[jsx-a11y/media-has-caption](http://172.16.117.224/fe/eslint-config-sunlands/issues/27) 28. 规则react/prop-types 增加字段route、match,参考issue[react/prop-types](http://172.16.117.224/fe/eslint-config-sunlands/issues/31) 29. 禁用规则no-script-url,参考issue[no-script-url](http://172.16.117.224/fe/eslint-config-sunlands/issues/32) 30. 规则react/prop-types 增加字段form,参考issue[react/prop-types](http://172.16.117.224/fe/eslint-config-sunlands/issues/33) 31. 规则no-multi-spaces,允许import的from前面有多个空格,参考issue[no-multi-spaces](http://172.16.117.224/fe/eslint-config-sunlands/issues/36) ## Usage 规范被封装为 eslint 的 shareable configuration,直接在 eslint 的配置中通过 extend 配置项引用即可 ### 安装 ``` npm i @sunl-fe/eslint-config-sunlands or yarn add @sunl-fe/eslint-config-sunlands ``` 列出所有依赖的 `peerDependencies` ``` npm info "@sunl-fe/eslint-config-sunlands" peerDependencies ``` 依次安装这些 `peerDependencies` ``` npm info "@sunl-fe/eslint-config-sunlands@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs yarn add "@sunl-fe/eslint-config-sunlands@latest" ``` ### 引用 `.eslintrc.js` 为例,只需要进行一行配置 ``` /* .eslintrc.js */ module.exports = { 'extends': '@sunl-fe/eslint-config-sunlands', }; ``` 附: [sublime配置@sunl-fe/eslint-config-sunlands](http://172.16.117.224/fe/wiki/issues/38)