javascripteslinteslintrc

ESLint - object-curly-newline


Is there a way to allow for {} (an empty object) while keeping the rest as is?

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

Solution

  • An empty object {} is ObjectExpression, so it always breaks line with your rule by specifying always. You can keep empty object without breaking line by configuring minProperties > 1:

    {
      "ObjectExpression": { "multiline": true, "minProperties": 1 },
    }