NAME
Perl::Critic::Policy::CodeLayout::ProhibitLongLines - Prohibit long lines
VERSION
version v0.2.4
SYNOPSIS
[CodeLayout::ProhibitLongLines]
max_line_length = 72
# Bad - line exceeds configured maximum
my $very_long_variable_name = "long string that exceeds maximum length";
# Good - line within limit
my $very_long_variable_name =
"long string that exceeds maximum length";
DESCRIPTION
This policy flags lines that exceed a configurable maximum length. Long lines can be difficult to read, especially in narrow terminal windows or when viewing code side-by-side with diffs or other files.
The default maximum line length is 80 characters, which provides good readability across various display contexts while still allowing reasonable code density.
You can configure perltidy to keep lines within the specified limit. Only when it is unable to do that will you need to manually make changes.
CONFIGURATION
max_line_length
The maximum allowed line length in characters. Defaults to 80.
[CodeLayout::ProhibitLongLines]
max_line_length = 72
allow_lines_matching
A space-separated list of regex patterns. Lines matching any pattern are exempt from the length check. This is useful for lines that cannot reasonably be shortened, such as long package declarations or URLs.
[CodeLayout::ProhibitLongLines]
allow_lines_matching = ^\s*package\s+
Multiple patterns (space-separated):
[CodeLayout::ProhibitLongLines]
allow_lines_matching = ^\s*package\s+ https?://
gitattributes_line_length
The name of a git attribute to look up for per-file line length overrides. Defaults to custom-line-length. Set to an empty string to disable.
The attribute value may be an integer (overriding max_line_length for that file) or the literal string ignore (suppressing all violations for that file).
Configure in .gitattributes:
t/legacy/messy.t custom-line-length=ignore
t/generated/*.t custom-line-length=200
Then in .perlcriticrc (the default attribute name is shown; you only need this line if you want a different name):
[CodeLayout::ProhibitLongLines]
gitattributes_line_length = custom-line-length
Requires git on $PATH. Falls back to the configured max_line_length when git is unavailable, the file is outside a repository, or the attribute is unspecified.
EXAMPLES
Long Variable Assignments
# Bad - exceeds 72 characters
my $configuration_manager = VeryLongModuleName::ConfigurationManager->new;
# Good - broken into multiple lines
my $configuration_manager =
VeryLongModuleName::ConfigurationManager->new;
Long Method Calls
# Bad - exceeds 72 characters
$object->some_very_very_long_method_name($param1, $param2, $param3, $param4);
# Good - parameters on separate lines
$object->some_very_very_long_method_name(
$param1, $param2, $param3, $param4
);
Long String Literals
# Bad - exceeds 72 characters
my $error_message =
"This is a very long error message that exceeds the configured maximum";
# Good - use concatenation or heredoc
my $error_message = "This is a very long error message that " .
"exceeds the configured maximum";
METHODS
supported_parameters
This method returns the parameters supported by this policy.
AFFILIATION
This Policy is part of the Perl::Critic::PJCJ distribution.
AUTHOR
Paul Johnson <paul@pjcj.net>
COPYRIGHT
Copyright 2025 Paul Johnson.
LICENCE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.