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:
(但是,有一个陷阱-该规则只需要在右大括号之后和右大括号之前使用换行符,因此,只要在括号之间包含换行符,您仍然可以加倍输入:)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…