简体   繁体   English

如何在全球范围内设置 eslint 规则?

[英]how to set eslint rules globally?

I am new in Eslint, and I was trying to set theses rules globally, so i don't have to write them in all projects everytimes.我是 Eslint 的新手,我试图在全球范围内设置这些规则,所以我不必每次都在所有项目中编写它们。 So, in my .eslintrc.json file i wrote:所以,在我的.eslintrc.json文件中,我写道:

"rules": {
    
    "no-unused-vars":"warn",
    "prefer-const":"warn",
    "quotes":"off",
    "space-before-blocks":"warn",
    "space-in-parens":"warn",
    "space-before-function-paren":"warn"
    
}

How can I achieve that?我怎样才能做到这一点?

From the manual :手册

The first way to use configuration files is via .eslintrc.* and package.json files.使用配置文件的第一种方法是通过 .eslintrc.* 和 package.json 文件。 ESLint will automatically look for them in the directory of the file to be linted, and in successive parent directories all the way up to the root directory of the filesystem (/), the home directory of the current user (~/), or when root: true is specified. ESLint 会自动在要检查的文件的目录中查找它们,并在连续的父目录中一直到文件系统的根目录 (/)、当前用户的主目录 (~/) 或当root: true 被指定。

So just put the file in your home directory.因此,只需将文件放在您的主目录中即可。

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

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