Skip to content

Formatting ​

info native off by default quick-fix

Group: Code style

Reports every place where the file's layout differs from what custos format would write: indentation, spaces, line breaks, braces, blank lines and the other settings of the project's format configuration. It brings formatting checks into the analysis, the editor and the baseline, with each change offered as a quick-fix.

Example ​

php
<?php

function total($a,$b){
  return $a + $b;
}
php
<?php

function total($a, $b)
{
    return $a + $b;
}

Reported:

  • line 3: Fix the spaces between tokens
  • line 3: Move the function opening brace
  • line 3: Fix the indentation

Detection ​

  • Lay the file out as custos format would, with the format settings that apply to it: the format section of the configuration, .editorconfig files and the configuration of other tools, as for the format command without command-line options. Report each change the formatter makes.
  • D2. When the format settings ask for long lines to be reported, report each line that stays wider than the line length once formatted.

Exceptions (no report) ​

  • Files the format.exclude globs leave out, and every file when the format settings are invalid.
  • Files the formatter leaves as written: files with syntax errors, files carrying a format-ignore comment, and files whose formatting the formatter cannot prove safe.
  • Code inside format-ignore regions.

Fix ​

  • F1. The first quick-fix applies that one change.
  • F2. The second quick-fix, Format the file, applies every change of the file at once, giving the output of custos format.

A long line (D2) has no quick-fix: formatting cannot shorten it.

PHP versions ​

No gating. The formatter parses the file at the target PHP version.

Configure ​

In custos.json:

json
{
  "rules": {
    "Formatting": {
      "enabled": true
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file):

php
// @custos-ignore Formatting

Released under the MIT License. Native rules and rules modeled on Php Inspections (EA Extended); independent clean-room implementation.