Skip to content

line-limit

Ensure that lines do not exceed a given limit

Options

code

Maximum length of a code line

Type: number

Default: 80

comment

Maximum length of a comment line. Defaults to the value of code

Type: number

Default: undefined

Examples

  • Examples of correct code for this rule using default options

Code under the line limit

php
<?php
function test($first_param, $second_param, $third_param, $fourth_param){
	echo "under line limit";
}

Comment the line limit

php
<?php
/**
 * This comment is under 80 characters which is the default line limit
 */
function test($first_param, $second_param, $third_param, $fourth_param) {
	echo "under line limit";
}
  • Examples of incorrect code for this rule using default options

Code exceeds the line limit

php
<?php
function test($first_param, $second_param, $third_param, $fourth_param, $fifth_param) {
	echo "exceeds line limit";
}

Comment exceeds the line limit

php
<?php
/**
 * This comment is way over 80 characters. Comments default to this the line limit of the code if not specified.
 */
function test($first_param, $second_param, $third_param, $fourth_param) {
	echo "exceeds line limit";
}

code

  • Examples of correct code for this rule using code option

Code under the set line limit

php
<?php
/* taqwim "psr/line-limit": {code: 120} */
function test($first_param, $second_param, $third_param, $fourth_param, $fifth_param, $sixth_param) {
	echo "exceeds line limit";
}

Comment will follow the code line limit if not specified

php
<?php
/* taqwim "psr/line-limit": {code: 120} */
/*
 * The comment is 117 charchaters but does not produce a warning. It defaults to the value of code if not specified.
 */
function test($first_param, $second_param, $third_param, $fourth_param, $fifth_param, $sixth_param) {
	echo "exceeds line limit";
}

comment

  • Examples of correct code for this rule using comment option

Comment can be set to a different line limit than code

php
<?php
/* taqwim "psr/line-limit": {comment: 120} */
/*
 * The comment is 104 charchaters but does not produce a warning. This is because comment is set to 120
 */
function test($first_param, $second_param, $third_param, $fourth_param) {
	echo "exceeds line limit";
}
  • Examples of incorrect code for this rule using comment option

Comment will produce a warning because it exceeds the line limit

php
<?php
/* taqwim "psr/line-limit": {comment: 70} */
/*
 * The comment will produce a warning because it is 71 characters long ...
 */
function test($first_param, $second_param, $third_param, $fourth_param) {
	echo "exceeds line limit";
}

Released under the MIT License.