How force declaration to be on new line ? How to make this illegal?
function foo() {
if ( 'error' ) {
return 'It failed';
}if ( 'loading' ) {// if need to be on new line
return "It's still loading";
}
}
and force this pattern
function foo() {
if ( 'error' ) {
return 'It failed';
}
if ( 'loading' ) {
return "It's still loading";
}
}
my current rule
"rules": {
"brace-style":["warn", "1tbs"],
"array-bracket-newline": ["warn", { "multiline": true }],
"comma-spacing": ["warn", { "before": true, "after": true }],
"curly": [2],
"array-bracket-spacing": ["warn","always"],
"object-curly-spacing": ["warn", "always"],
"object-curly-newline": ["warn", {
"ObjectExpression": { "consistent": true, "multiline": true ,"minProperties": 4},
"ObjectPattern": { "consistent": true, "multiline": true },
"ImportDeclaration": "never",
"ExportDeclaration": { "multiline": true, "minProperties": 3 }
}],
"computed-property-spacing": ["warn", "never", { "enforceForClassMembers": true }],
"space-in-parens": ["warn", "always"],
"padding-line-between-statements": [
"warn",
{ "blankLine": "always", "prev": ["const", "let", "var"], "next": "*"},
{ "blankLine": "any", "prev": ["const", "let", "var"], "next": ["const", "let", "var"]}
],
"sort-imports": ["warn",{
"ignoreCase": false,
"ignoreDeclarationSort": true,
"ignoreMemberSort": false,
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"],
"allowSeparatedGroups": false
}],
"operator-linebreak": ["warn", "none"],
"no-mixed-spaces-and-tabs": "warn",
"object-property-newline": ["warn",{ "allowAllPropertiesOnSameLine": true }],
"no-multiple-empty-lines": ["warn", { "max": 1, "maxEOF": 4 }],
"lines-between-class-members": ["warn", "always"],
"no-multi-spaces": "warn",
"comma-dangle": ["warn", "always-multiline"],
"padded-blocks": ["warn", { "classes": "always","blocks": "never" }, { "allowSingleLineBlocks": true }],
"comma-style": ["warn", "last"],
"arrow-parens": ["warn", "always"],
"indent": ["warn", "tab"],
"no-console": "warn",
"no-return-assign": "warn",
"no-var": "warn",
"no-duplicate-imports": "error",
"react/prop-types": [
0,
{}
],
"react/jsx-curly-brace-presence": "warn",
"space-infix-ops": "warn",
"spaced-comment": ["warn", "always"],
"space-unary-ops": "warn",
"no-else-return": ["error", {"allowElseIf": false}],
//style "vudge"
"grouped-accessor-pairs": ["warn", "getBeforeSet"]
}
Is there a way to prevent this ?
padding-line-between-statements
will do what you want, you just have to configure it appropriately.
https://eslint.org/docs/rules/padding-line-between-statements
currently you only have it configured to enforce there are lines in relation to variable declarations - but you've indicated you want to enforce around if
s as well - so you'll want to add config for "block-like"
as well.
Here's an example of it working with a really lazy config using "*"