简体   繁体   English

如何创建自定义的ESLint规则?

[英]How to create customized ESLint rules?

Sorry for this newbie question but I could not find the infomation on the net: I want to develop my own ESLint rules. 对这个新手问题很抱歉,但是我在网上找不到信息:我想开发自己的ESLint规则。 For that I want to set up an environment in Webstorm. 为此,我想在Webstorm中设置一个环境。 EsLint is an node.js project and I need to access code from other modules. EsLint是一个node.js项目,我需要从其他模块访问代码。 Can somebody give me a hint how to set up everythin that I can develop a custom rule and test ist. 有人可以给我提示如何设置所有可以开发自定义规则和测试专家的内容。 I am not really familiar with node.js maybe that is allready the problem - i do not know how to access the node.js modules. 我不太熟悉node.js,也许这已经是问题了-我不知道如何访问node.js模块。 Locally in my workspace or the central installation of the node.exe that I am starting? 在我的工作区本地或我要启动的node.exe的中央安装中?

You can use https://github.com/eslint/generator-eslint as a starting point for development of the custom rules. 您可以将https://github.com/eslint/generator-eslint用作开发自定义规则的起点。 You would need locally installed Node.js and NPM. 您将需要本地安装的Node.js和NPM。 You will also need to install Yeoman using NPM ( npm install -g yo ) and then follow the instructions on the generator-eslint page. 您还需要使用NPM( npm install -g yo )安装Yeoman,然后按照generator-eslint页面上的说明进行操作。 That will create a template for a custom eslint plugin. 这将为自定义eslint插件创建模板。 To create rules and use external modules, you will need to install those modules first, again, using NPM and save them to the package.json file (using npm install ... --save command). 要创建规则并使用外部模块,您将需要首先使用NPM再次安装这些模块,并将其保存到package.json文件中(使用npm install ... --save命令)。 After that you should be able to require those modules inside of you rule. 之后,您应该可以在规则中require这些模块。 There are plenty of eslint plugins out there, that you can look at for an example: 有很多eslint插件,您可以看一个例子:

After you are done, you will need to publish your plugin to NPM to be able to use it. 完成后,您将需要将插件发布到NPM才能使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM