Indentation should be consistent to make the code easy to read, review and modify. To fix this issue, change the indentation so that the text starts at the expected column.

Why is this an issue?

Consistent indentation is a simple and effective way to improve the code’s readability. It reduces the differences that are committed to source control systems, making code reviews easier.

This rule raises an issue when the indentation does not match the configured value. Only the first line of a badly indented section is reported.

What is the potential impact?

The readability is decreased. It becomes more tedious to review and modify the code.

How to fix it

Change the indentation so that the text starts at the expected column. The expected column should be the configured indent size multiplied by the level at which the code block is nested.

Code examples

Noncompliant code example

With an indent size of 2:

<?xml version="1.0"?>
<catalog>
  <book id="bk101">
    <author>Gambardella, Matthew</author>
     <title>XML Developer's Guide</title>  <!-- Noncompliant, expected to start at column 4 -->
    <genre>Computer</genre>
    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <description>An in-depth look at creating applications
    with XML.</description>
  </book>
    <book id="bk102">  <!-- Noncompliant, expected to start at column 2 -->
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies,
      an evil sorceress, and her own childhood to become queen
      of the world.</description>
    </book>
</catalog>

Compliant solution

<?xml version="1.0"?>
<catalog>
  <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <genre>Computer</genre>
    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <description>An in-depth look at creating applications
    with XML.</description>
  </book>
  <book id="bk102">
    <author>Ralls, Kim</author>
    <title>Midnight Rain</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2000-12-16</publish_date>
    <description>A former architect battles corporate zombies,
    an evil sorceress, and her own childhood to become queen
    of the world.</description>
  </book>
</catalog>

Going the extra mile

You can adopt a tool or configure your IDE to take care of code formatting automatically.