简体   繁体   English

如何在箭头函数之前/之后创建空格,eslint

[英]How to make spaces before/after arrow functions , eslint

I want to autoformat this kind of arrow functions, make spaces before/after equal sign and "=>", also spaces between functions我想自动格式化这种箭头函数,在等号和“=>”之前/之后创建空格,函数之间也有空格

const test=()=>{

}

I haven't worked with eslint before, could you please help me我以前没有和 eslint 合作过,你能帮帮我吗

The only way to get eslint to fix issues is by using the --fix option on the command-line, though you may be able to configure your IDE to ensure this happens when you save a file, for example.eslint修复问题的唯一方法是在命令行上使用--fix选项,尽管您可以配置 IDE 以确保在保存文件时发生这种情况,例如。

To generate warnings for these problems:要为这些问题生成警告:

Here's the documentation for this rule .这是此规则的文档

There are several ways to go about this. go 关于这个有几种方法。

1) If you want to fix this issue for the whole of one file add the following to the very top of the file: 1)如果您想为整个一个文件解决此问题,请将以下内容添加到文件的最顶部:

/* eslint arrow-spacing: ["error", { "before": true, "after": true }] */

2) If you want to disable it for just that line 2)如果您只想为该行禁用它

/* eslint arrow-spacing: ["error", { "before": true, "after": true }] */
const test=()=>{
}

3) If you want all files to be affected you need an eslint configuration file to which you can add rules. 3)如果您希望所有文件都受到影响,您需要一个可以添加规则的 eslint 配置文件。 You may already have one of those.您可能已经拥有其中之一。 It will be in you root folder and will be called .eslintrc .它将在您的根文件夹中,并将被称为.eslintrc If you don't have one here's the information on how to set one up .如果您没有, 这里是关于如何设置的信息 Then all you need to do is add the rule depending on your requirements:然后您需要做的就是根据您的要求添加规则:

"rules": {
 // ...
 "arrow-spacing": ["error", { "before": true, "after": true }]
}

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

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