Skip to content

👬 Incoherent code style #539

@jakob-info

Description

@jakob-info

Description
Sometimes, the code is styled differently in the same file. While writing new code, my IDE formats code, including existing one. This means, on commit I have to revert all style changes to existing code that is not mine.

I saw in your contributing guidelines that you use PSR12. I suggest setting up a ruleset for php codesniffer and a ruleset for js.
You can setup a github action that formats code for every pull request, that warns you on unfixable style issues or let a test fail when encountering commented out code. This means less work for you, as it is automated. I checked out laravel/pint which uses php codesniffer under the hodd and thought a phpcs.xml would be better because it is also used outside of laravel and other styleguides are also written in xml.

Suggestion
In addition to PSR12, I found rules for type hints

<ruleset name="pcsg-generated-ruleset">
<rule ref="PSR12"/>
<rule ref="Generic.Classes.DuplicateClassName"/>
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.ForbiddenFunctions"/>

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
    <properties>
        <property name="spacesCountAroundEqualsSign" value="0"/> 
    </properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>

<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint">
    <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint"/>
</rule>
</ruleset>

This script needs to be checked

name: Fix Code Style
 
on: [push]
 
jobs:
  lint:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: true
      matrix:
        php: [8.4]
 
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
 
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: json, dom, curl, libxml, mbstring
          coverage: none

      - name: Install php codesniffer and slevomat coding-standard
        run: cd backend/
        run: composer global require slevomat/coding-standard -n
 
      - name: Run codesniffer
        run: vendor/bin/phpcbf
 
      - name: Commit linted files
        uses: stefanzweifel/git-auto-commit-action@v5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions