Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Latest commit

 

History

History
163 lines (148 loc) · 5.2 KB

terIndentRule.md

File metadata and controls

163 lines (148 loc) · 5.2 KB

ter-indent (ESLint: indent)

rule_source test_source

enforce consistent indentation

Rationale

Using only one of tabs or spaces for indentation leads to more consistent editor behavior, cleaner diffs in version control, and easier programmatic manipulation.

Config

The string 'tab' or an integer indicating the number of spaces to use per tab.

An object may be provided to fine tune the indentation rules:

  • "SwitchCase" (default: 0) enforces indentation level for case clauses in switch statements
  • "VariableDeclarator" (default: 1) enforces indentation level for var declarators; can also take an object to define separate rules for var, let and const declarations.
  • "outerIIFEBody" (default: 1) enforces indentation level for file-level IIFEs.
  • "MemberExpression" (off by default) enforces indentation level for multi-line property chains (except in variable declarations and assignments)
  • "FunctionDeclaration" takes an object to define rules for function declarations.
    • "parameters" (off by default) enforces indentation level for parameters in a function declaration. This can either be a number indicating indentation level, or the string "first" indicating that all parameters of the declaration must be aligned with the first parameter.
    • "body" (default: 1) enforces indentation level for the body of a function expression.
  • "FunctionExpression" takes an object to define rules for function declarations.
    • "parameters" (off by default) enforces indentation level for parameters in a function declaration. This can either be a number indicating indentation level, or the string "first" indicating that all parameters of the declaration must be aligned with the first parameter.
    • "body" (default: 1) enforces indentation level for the body of a function expression.
  • "CallExpression" takes an object to define rules for function call expressions.
    • "arguments" (off by default) enforces indentation level for arguments in a call expression. This can either be a number indicating indentation level, or the string "first" indicating that all arguments of the expression must be aligned with the first argument.

Examples

"ter-indent": [true, "tab"]
"ter-indent": [true, 2]
"ter-indent": [
  true,
  2,
  {
    "FunctionExpression": {
      "parameters": 1,
      "body": 1
    }
  }
]

Schema

{
  "type": "array",
  "items": [
    {
      "type": "number",
      "minimum": "0"
    },
    {
      "type": "string",
      "enum": [
        "tab"
      ]
    },
    {
      "type": "object",
      "properties": {
        "SwitchCase": {
          "type": "number",
          "minimum": 0
        },
        "VariableDeclarator": {
          "type": "object",
          "properties": {
            "var": {
              "type": "number",
              "minimum": 0
            },
            "let": {
              "type": "number",
              "minimum": 0
            },
            "const": {
              "type": "number",
              "minimum": 0
            }
          }
        },
        "outerIIFEBody": {
          "type": "number"
        },
        "FunctionDeclaration": {
          "type": "object",
          "properties": {
            "parameters": {
              "type": "number",
              "minimum": 0
            },
            "body": {
              "type": "number",
              "minimum": 0
            }
          }
        },
        "FunctionExpression": {
          "type": "object",
          "properties": {
            "parameters": {
              "type": "number",
              "minimum": 0
            },
            "body": {
              "type": "number",
              "minimum": 0
            }
          }
        },
        "MemberExpression": {
          "type": "number"
        },
        "CallExpression": {
          "type": "object",
          "properties": {
            "arguments": {
              "type": "number",
              "minimum": 0
            }
          }
        }
      },
      "additionalProperties": false
    }
  ],
  "minLength": 1,
  "maxLength": 2
}

TSLint Rule: indent

TSLint provides the indent rule but it currently only checks if we are using tabs or spaces. As of 11/1/2016 there is an open issue to add enhancements to the rule: palantir/tslint#581.