Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a phpcs.xml file #227

Open
dawehner opened this issue Dec 8, 2016 · 3 comments
Open

Adding a phpcs.xml file #227

dawehner opened this issue Dec 8, 2016 · 3 comments
Labels
State: Needs more discussion The issue requires more discussion Type: Feature Issue is a new feature request

Comments

@dawehner
Copy link

dawehner commented Dec 8, 2016

It would be kind of nice to ship with a phpcs.xml file. Ideally this would be default at least have the rules be available in core by default, and point to just code running in modules/custom, themes/custom

@gergelypap
Copy link

gergelypap commented May 11, 2017

+1

We can use core's ruleset as a starting point: https://github.com/drupal/drupal/blob/8.4.x/core/phpcs.xml.dist

@AlexSkrypnyk AlexSkrypnyk changed the title Adding a phpcs.xmlfile Adding a phpcs.xml file May 12, 2024
@AlexSkrypnyk
Copy link
Collaborator

Since this projects provides tooling via drupal/core-dev, supporting of the configs for that tooling does make sense.

If we decide to do so, we would need to:

  1. Add PHPCS configuration to support Coder rules with custom locations as targets.
  2. Update CI config to include code standards check using PHPCS

@AlexSkrypnyk AlexSkrypnyk self-assigned this May 12, 2024
@AlexSkrypnyk AlexSkrypnyk added Type: Feature Issue is a new feature request State: Needs more discussion The issue requires more discussion and removed feature request labels May 13, 2024
@AlexSkrypnyk AlexSkrypnyk removed their assignment May 14, 2024
@AlexSkrypnyk
Copy link
Collaborator

Config for core development contains a lot of core-specific rules that are not useful for consumer sites.

Here is an example of the config file that can be used in this project (taken from 🌀Vortex Drupal project template and currently used on consumer sites):

<?xml version="1.0"?>
<ruleset name="custom">
    <description>Custom PHPCS Standard, based on Drupal standards.</description>

    <file>web/modules/custom</file>
    <file>web/themes/custom</file>
    <file>web/sites/default/settings.php</file>
    <file>web/sites/default/includes</file>
    <file>tests</file>

    <rule ref="Drupal"/>
    <rule ref="DrupalPractice"/>
    <rule ref="Generic.PHP.RequireStrictTypes" />
    <rule ref="Generic.Debug.ESLint"/>
    <rule ref="PHPCompatibility"/>

    <arg name="extensions" value="inc,info,install,module,php,profile,test,theme,js,css"/>
    <arg name="colors"/>
    <arg value="sp"/>
    <arg name="parallel" value="75"/>

    <!-- Lint code against platform version specified in composer.json key "config.platform.php". -->
    <config name="testVersion" value="8.3"/>

    <!-- Exclude theme assets. -->
    <exclude-pattern>web\/themes\/custom\/.*\/build\/.*</exclude-pattern>
    <exclude-pattern>web\/themes\/custom\/.*\/fonts\/.*</exclude-pattern>
    <exclude-pattern>web\/themes\/custom\/.*\/images\/.*</exclude-pattern>
    <exclude-pattern>web\/themes\/custom\/.*\/node_modules\/.*</exclude-pattern>
    <exclude-pattern>*\.min\.*</exclude-pattern>

    <!-- Force no empty lines after function opening brace. -->
    <rule ref="Squiz.WhiteSpace.FunctionOpeningBraceSpace">
        <type>warning</type>
    </rule>

    <!-- Force no empty lines before control structure closing. -->
    <rule ref="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose">
        <type>warning</type>
    </rule>

    <!-- Force no empty lines after control structure closing. -->
    <rule ref="Squiz.WhiteSpace.ControlStructureSpacing.LineAfterClose">
        <type>warning</type>
    </rule>

    <!-- Allow long array lines in tests. -->
    <rule ref="Drupal.Arrays.Array.LongLineDeclaration">
        <exclude-pattern>*.Test\.php</exclude-pattern>
        <exclude-pattern>*.TestCase\.php</exclude-pattern>
        <exclude-pattern>*.test</exclude-pattern>
    </rule>

    <!-- Ignore prefixing of class names with project name in Behat tests. -->
    <rule ref="DrupalPractice.General.ClassName.ClassPrefix">
        <exclude-pattern>*\/tests\/behat\/bootstrap/*\.php</exclude-pattern>
    </rule>
</ruleset>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
State: Needs more discussion The issue requires more discussion Type: Feature Issue is a new feature request
Projects
None yet
Development

No branches or pull requests

4 participants