eslint插件开发教程 (2)

要在其它项目中使用的eslint-plugin插件的话,可以把整个插件的根目录拷贝到目标项目的node_modules中或者发布到npm中去,其它项目直接通过npm install 安装这个依赖

下面介绍发布到npm的步骤

注册npm账号(有的话直接跳过这步骤)

直接点击官网注册

设置登陆的账号
登录之前修改registry为原来的,因为国内一般用的镜像源例如淘宝源:https://registry.npm.taobao.org

npm config set registry https://registry.npmjs.org/ npm login

按提示依次输入账号,密码,邮箱

登录完成之后,查看当前npm用户,不报错说明登录成功

npm whoami

编写README.md方便指引他人使用

修改packgae.json

{ "name": "eslint-plugin-comments-key", "version": "1.0.0", "description": "校验注释中是否包含指定关键词的插件", "main": "index.js", "directories": { "lib": "lib", "test": "tests" }, "scripts": { "test": "mocha tests/lib/rules" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "eslint": "^7.0.0", "mocha": "^7.1.2" } }

运行npm publish发布npm包

至此发布整个流程完毕

6.项目中引入 Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-comments-key:

$ npm install eslint-plugin-comments-key --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-comments-key globally.

Usage

Add comments-key to the plugins section of your .eslintrc configuration file or package.json. You can omit the eslint-plugin- prefix:

package.json demo

"eslintConfig": { "plugins": [ "comments-key" ], "rules": { "comments-key/diy":[1,{ "wordKeys":["fixme","xxx"] }] } }

tips: 如果编辑器中安装了Eslint插件,在编码的时候就会给予警告⚠️

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpffpy.html