Skip to content

Formatting code

Nick Kwiatkowski edited this page Nov 25, 2026 · 1 revision

Formatting code

clif format runs the same formatter the editor uses for Format Document, Format Selection and format-on-save. It rebuilds each file from its syntax tree, and by default refuses any result that changes more than whitespace.

clif format [-w] [--allow-non-whitespace] [--root <dir>] [--follow-symlinks] <file> [...]

Options

Option Description
(none) Print the formatted file to stdout
-w Rewrite the file in place
--allow-non-whitespace Permit changes beyond whitespace (off by default). Turns off the whitespace guard; use only when you have reviewed what the formatter does to a file
--root <dir> Read the formatting config from this directory's .clif.json instead of each file's own
--follow-symlinks With -w, rewrite a symlinked file's target wherever it is. Without it a link is followed only to a file in its own directory or beneath it, or beneath --root

The formatting settings come from the formatting block of each file's governing .clif.json. They are documented in full in Formatter Options.

Examples

Preview a file:

clif format src/handlers/Main.cfc

Rewrite several files in place:

clif format -w src/handlers/Main.cfc src/views/main/index.cfm

Use one config for files outside the project (for example a shared template directory):

clif format -w --root ~/projects/myapp ../shared/templates/header.cfm

Format every changed file before committing (bash):

git diff --name-only --diff-filter=ACM -- '*.cfm' '*.cfc' | xargs clif format -w

PowerShell:

git diff --name-only --diff-filter=ACM -- '*.cfm' '*.cfc' | ForEach-Object { clif format -w $_ }

Input and output example

With this .clif.json:

{
  "formatting": {
    "enabled": true,
    "lowercaseTags": true,
    "doubleQuoteAttributes": true,
    "selfCloseTags": true,
    "indentWidth": 4
  }
}

Input:

<CFIF x GT 1><CFSET y = 'a'><br>
<cfoutput>#y#</cfoutput></CFIF>

clif format page.cfm (illustrative output):

<cfif x GT 1>
    <cfset y = "a">
    <br />
    <cfoutput>#y#</cfoutput>
</cfif>

The case change, the re-quoted attribute and <br /> all pass the whitespace guard, which allows exactly those canonicalisations.

The whitespace guard

With whitespaceOnly on (the default) the formatter compares its output with the input, skipping whitespace, and refuses the result if anything else differs. The comparison deliberately allows the formatter's own canonicalisations:

Allowed difference Example
Letter case <CFOUTPUT> → <cfoutput>
A / before > (self-closing) <br> → <br />
Attribute re-quoting: unquoted → quoted, single → double <cfset a='x'> attribute values → "x"
An added ;, { or } in CFScript a missing semicolon gained, a single-statement body braced

Anything else (a dropped quote or token, a changed word) makes the formatter decline, and the file is left unchanged. Comments are compared separately and must survive intact.

Checking formatting in CI

Use the format check of clif check, which counts files clif format -w would change without writing anything:

clif check --checks format .

The MCP server's check_format tool does the same and can return a diff preview.

Notes

Topic Behaviour
Tabs vs spaces The CLI indents with spaces, indentWidth per level. In the editor, useTabs and tabSize come from the editor's formatting options instead
Final newline The output ends with exactly one newline. In the editor, insertFinalNewline and trimFinalNewlines are honoured
Trailing whitespace Never emitted: the output is rebuilt from the syntax tree
<cfquery> content Emitted verbatim unless queryFormat is true

← Running the CLIF command-line tool · Home

Clone this wiki locally