Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

javascript - Eslint规则在导入中放置新行(Eslint rule to put a new line inside import)

The rule that I'm looking should show error in this case:

(在这种情况下,我正在寻找的规则应显示错误:)

import {MY_CONSTANT1, MY_CONSTANT2, MY_CONSTANT3}

And considered as fine in this case:

(并且在这种情况下被认为是可以的:)

import {
   MY_CONSTANT1, 
   MY_CONSTANT2, 
   MY_CONSTANT3
}

Is there such eslint rule?

(有这样的陪同规则吗?)

  ask by Anna translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add the object-curly-newline rule to your .eslintrc.json , where at least ImportDeclaration is set to always (the other settings have no effect for enforcing newlines in import declarations).

(将object-curly-newline规则添加到.eslintrc.json ,其中至少将ImportDeclaration设置为always(其他设置对在导入声明中强制换行无效)。)

Example:

(例:)

"object-curly-newline": ["error", {
   "ObjectExpression": "always",
   "ObjectPattern": { "multiline": true },
   "ImportDeclaration": "always",
   "ExportDeclaration": { "multiline": true, "minProperties": 3 }
}]

This pattern will now result in an error:

(现在,此模式将导致错误:)

While this is valid:

(这是有效的:)


However, there is a catch - this rule only requires newlines after the opening brace and before the closing brace, so you can still double up on imports as long as they have newlines in between the braces:

(但是,有一个陷阱-该规则只需要在右大括号之后和右大括号之前使用换行符,因此,只要在括号之间包含换行符,您仍然可以加倍输入:)



与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...