Phpinsights: [Question] How to configure public param $lineLimit in LineLengthSniff

Created on 22 May 2019  路  4Comments  路  Source: nunomaduro/phpinsights

| Q | A
| ---------------- | -----
| Bug report? | no
| Feature request? | maybe?
| Library version | 1.3

So, my entire code is intended have <120 characters per line and the default configuration LineLengthSniff uses is 80.

I know I could add it to remove and be done with it, but I'd much rather change the public parameter $lineLimit to enforce this sniff.

Is it possible?

Also, the same thing applies to pretty much any length-related sniff (e.g. FunctionLengthSniff).

Regards, DAVI

question

All 4 comments

Yep, it can be customised.
For LineLengthSniff there are 3 properties to look for.

/**
 * The limit that the length of a line should not exceed.
 *
 * @var integer
 */
public $lineLimit = 80;

/**
 * The limit that the length of a line must not exceed.
 *
 * Set to zero (0) to disable.
 *
 * @var integer
 */
public $absoluteLineLimit = 100;

/**
 * Whether or not to ignore comment lines.
 *
 * @var boolean
 */
public $ignoreComments = false;

You can set them in your config file under config like so

LineLengthSniff::class => [
    'absoluteLineLimit' => 120, 
    'lineLimit' => 120,
    'ignoreComments' => false,
]

Please return with feedback if this works for you.

Thank you @olivernybroe !

@olivernybroe I tried that and didn't work for me :(

Edit: I just figured that I had to add

use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;

and LineLengthSniff::class, under add.

config/insights.php:

<?php

declare(strict_types=1);

use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;

return [
    // Other stuff

    'config' => [
        LineLengthSniff::class => [
            'absoluteLineLimit' => 120,
            'lineLimit' => 120,
            'ignoreComments' => false,
        ],
];
Was this page helpful?
0 / 5 - 0 ratings

Related issues

erwinw picture erwinw  路  6Comments

Naxon picture Naxon  路  4Comments

michaelnguyen547 picture michaelnguyen547  路  6Comments

nunomaduro picture nunomaduro  路  5Comments

brunocfalcao picture brunocfalcao  路  5Comments