8000 eslint中extends plugin config的区别 · Issue #13 · yan647/Blog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
eslint中extends plugin config的区别 #13
@yan647

Description

@yan647

extends

命名规范

extends 的模块名称以 eslint-config- 开头,例如 eslint-config-myconfig。也支持 npm 作用域模块,例如 : @scope/eslint-config 或 @scope/eslint-config-myconfig) 。使用的时候可以用全称,也可以用缩写。

extends: [ 
    'eslint-config-myconfig', // 全称 
    //'myconfig' 缩写 
    'plugin:myplugin/recommended' // 插件中的 config 
]

用途

extends可以看做是集成一个个配置方案的最佳实践。它配置的内容实际就是一份份别人配置好的.eslintrc.js。
允许 extends 配置多个模块,如果规则冲突,位置靠后的包将覆盖前面的。rules 中的规则相同,并且优先级恒定高于 extends,类似class的extends,支持多继承。

plugin

命名规范

每个插件是一个命名格式为 eslint-plugin-<plugin-name> 的 npm 模块,比如 eslint-plugin-jquery。你也可以用这样的格式 @<scope>/eslint-plugin-<plugin-name> 限定在包作用域下,比如 @jquery/eslint-plugin-jquery。 同样可以使用缩写。

用途

引入 plugin 可以理解为只是加载了插件,引入了额外的 自定义的rules。需要在 rules、extends 中定义后才会生效,如果没有则不生效。
plugin里不仅包括自定义的rules,还可以配置config,即总结的最佳实践,类似配置好的.eslintrc.js,因此这部分可以在extends里配置:plugin:config名称。

eslint的extends、plugin的区别

extends plugin
命名 eslint-config-<plguin-name>@scope/eslint-config@scope/eslint-config-myconfig eslint-plugin-<plugin-name>@scope/eslint-plugin-<plugin-name>
用途 扩展
集成一个个配置方案的最佳实践,即别人配置好的.exlintrc.js
插件
必有:一堆自定义的规则的集合
可能有:总结的最佳实践
配置 全称:eslint-config-myconfig
缩写:myconfig
插件中的config:plugin:plugin-name/config-nameplugin:myplugin/recommended
全称:eslint-plugin-myconfig
缩写:myconfig

extends里的config和plugin里的config的区别

extends中的config plugin中的config
extends的一种命名规范 plugin里的一个属性
extends扩展名称格式必须为eslint-config- 用于配置一堆自定义的规则的集合

参考

[1] https://zhuanlan.zhihu.com/p/210446846
[2] https://juejin.cn/post/6859291468138774535

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0