상세 컨텐츠

본문 제목

How to install phpcs in visual studio code?

Tools/VisualStudioCode

by w3labkr 2021. 12. 8. 21:31

본문

Installation

$ composer require --dev squizlabs/php_codesniffer
$ composer update

Configure

ruleset.xml

<?xml version="1.0"?>
<ruleset name="MyPSR2">

    <description>The PSR-2 coding standard.</description>

    <exclude-pattern>*/node_modules/*</exclude-pattern>
    <exclude-pattern>*/vendor/*</exclude-pattern>
    <exclude-pattern>*/dist/*</exclude-pattern>

    <!-- 2. General -->

    <!-- 2.1 Basic Coding Standard -->

    <!-- Include the whole PSR-2 standard -->
    <rule ref="PSR2" />

    <!-- 2.3 Lines -->

    <!-- The soft limit on line length MUST be 120 characters; automated style checkers MUST warn but MUST NOT error at the soft limit. -->
    <rule ref="Generic.Files.LineLength">
        <properties>
            <property name="lineLimit" value="120" />
            <property name="absoluteLineLimit" value="0" />
        </properties>
    </rule>

</ruleset>

.vscode/settings.json

{
  "phpcs.enable": true,
  "phpcs.standard": "PSR2"
}