Skip to content

line-too-long (S001)

This rule is turned on by default.

What does it do?

Checks line length isn't too long

Why is this bad?

Long lines are more difficult to read, and may not fit on some developers' terminals. The line continuation character '&' may be used to split a long line across multiple lines, and overly long expressions may be broken down into multiple parts.

The maximum line length can be changed using the flag --line-length=N. The default maximum line length is 100 characters. This is a fair bit more than the traditional 80, but due to the verbosity of modern Fortran it can sometimes be difficult to squeeze lines into that width, especially when using large indents and multiple levels of indentation.

In the interest of pragmatism, this rule makes a few exceptions when determining whether a line is overlong. Namely, it:

  1. Ignores lines that consist of a single "word" (that is, without any whitespace between its characters).
  2. Ignores lines that end with a URL, as long as the URL starts before the line-length threshold.
  3. Ignores SPDX license identifiers and copyright notices (for example, ! SPDX-License-Identifier: MIT), which are machine-readable and should not wrap over multiple lines.

Note that the Fortran standard states a maximum line length of 132 characters1, and while most modern compilers will support longer lines2, for portability it is recommended to stay beneath this limit.

Example

call my_long_subroutine(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10)

Use instead:

call my_long_subroutine(&
    param1, param2, param3, param4, param5, &
    param6, param7, param8, param9, param10 &
)

Options


  1. In F77 this was only 72, and in F2023 it was relaxed to 10,000. 

  2. Sometimes a compiler flag is required.