eslint修改换行规则
时间: 2023-10-07 09:11:04 浏览: 106
ESLint 中的 `max-len` 规则可以用来配置一行的最大长度,但是如果你想要配置换行规则,可以使用 `implicit-arrow-linebreak` 规则。这个规则用来控制箭头函数的换行方式,可以配置为以下三种选项:
- `"beside"`:要求箭头函数体与箭头在同一行。
- `"below"`:要求箭头函数体与箭头在不同的行,且箭头在函数体前面。
- `"above"`:要求箭头函数体与箭头在不同的行,且箭头在函数体后面。
例如,将箭头函数体与箭头在同一行,可以这样配置:
```json
{
"rules": {
"implicit-arrow-linebreak": ["error", "beside"]
}
}
```
需要注意的是,`implicit-arrow-linebreak` 规则只适用于箭头函数,对于其他类型的函数,换行的规则需要通过其他规则来控制。
相关问题
vscode 配置 eslint 换行规则
您可以按照以下步骤进行配置:
1. 安装 `eslint` 和 `prettier` 插件:
```
npm install eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-node eslint-config-node -D
```
2. 在 VS Code 中打开 `settings.json` 文件,添加以下配置:
```
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"vue",
"html",
"vue-html"
],
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
```
上述配置实现了在保存文件时,自动格式化代码,并按照 `prettier` 的规则进行换行。
3. 在项目根目录下添加 `.eslintrc.js` 文件,添加以下配置:
```
module.exports = {
root: true,
env: {
node: true
},
extends: [
"eslint:recommended",
"plugin:node/recommended",
"plugin:prettier/recommended"
],
plugins: ["prettier"],
rules: {
"prettier/prettier": "error"
}
};
```
上述配置中,通过 `eslint:recommended` 和 `plugin:node/recommended` 启用了基本的 `eslint` 规则和 Node.js 环境的规则,通过 `plugin:prettier/recommended` 启用了 `prettier` 和 `eslint` 的规则集成,同时添加了 `prettier` 插件,并开启了 `prettier/prettier` 规则,以使 `prettier` 的规则生效。
应用以上配置后,您就可以在 VS Code 中愉快地编写 JavaScript 或 Vue 项目,并且自动格式化代码和换行。
eslint 关闭 html 换行规则
可以通过在.eslintrc配置文件中添加以下规则实现关闭 HTML 换行规则:
```json
{
"rules": {
"no-multiple-empty-lines": [
"error",
{ "max": 1, "maxEOF": 0, "maxBOF": 0 }
]
}
}
```
你可以根据具体需求修改该规则的配置。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)