Skip to content

Added magento/magento-coding-standard to keep closer to Magento standards #3

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

Merged
merged 15 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.0.0
### Added
- Composer package youwe/coding-standard which is now included in the Youwe coding standards for Magento 2.
- Comments for why the ruleset was added.
- Coding standards for phtml templates.
- Package [magento/magento-coding-standard](https://github.com/magento/magento-coding-standard) as a requirement.
The version v25 is used as a base. If not compatible please update the `phpcs.xml` in project root.

### Removed
- Rule PSR2.Methods.MethodDeclaration.Underscore since this is already excluded by Magento.
- Argument colors and added it in the common Youwe coding standards.
- Old coding ruleset directories and migrated them to YouweMagento2.

## 1.7.0 - 2021-12-24
### Changed
- Vendor from MediactMagento2 to Magento2
- Copyrights.

### Removed
- Dependency squizlabs/php_codesniffer.
- Dependency squizlabs/php_codesniffer.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Introduction

This is the MediaCT coding standard for Magento 2 projects. It is based on
the default MediaCT coding standard but some tests have been removed to create
This is the Youwe coding standard for Magento 2 projects. It is based on
the default Magento2 coding standard but some tests have been removed to create
a workable and fast standard.

# Installation

Use composer to require the standard in a project.

```shell
composer require --dev mediact/coding-standard-magento2
composer require --dev youwe/coding-standard-magento2 -W
```

To let PHPCS know that this standard should be used add a phpcs.xml file in the
Expand All @@ -18,20 +18,20 @@ root of the project.
```xml
<?xml version="1.0"?>
<ruleset>
<rule ref="./vendor/mediact/coding-standard-magento2/src/MediactMagento2"/>
<rule ref="YouweMagento2"/>
</ruleset>
```

# Integration with PHPStorm and automatic testing

The recommended way to enable the coding standard in PHPStorm and automatic
testing is by requiring the MediaCT testing suite in a project.
testing is by requiring the Youwe testing suite in a project.

```shell
composer require --dev mediact/testing-suite
composer require --dev youwe/testing-suite
```

For more information go to [MediaCT Testing Suite](https://github.com/mediact/testing-suite).
For more information go to [Youwe Testing Suite](https://github.com/YouweGit/testing-suite).

# Contribution guidelines

Expand Down
17 changes: 12 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
{
"name": "youwe/coding-standard-magento2",
"description": "Youwe PHP Coding Standard for Magento2",
"type": "phpcs-sniffs",
"homepage": "https://github.com/YouweGit/coding-standard-magento2",
"license": "proprietary",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, but maybe a good idea to change this to a different license in the future as the code is open source and not proprietary.

"type": "phpcodesniffer-standard",
"authors": [
{
"name": "Youwe B.V.",
"email": "info@youweagency.com"
}
],
"homepage": "https://github.com/YouweGit/coding-standard-magento2",
"require": {
"youwe/coding-standard": ">=3.3.0"
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
"magento/magento-coding-standard": ">= 9",
"youwe/coding-standard": "^3.5.0"
},
"autoload": {
"psr-0": {
"MediactMagento2": "src/MediactMagento2",
"Magento2": "src/Magento2"
"YouweMagento2": "src/YouweMagento2"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
}
}
50 changes: 0 additions & 50 deletions src/Magento2/ruleset.xml

This file was deleted.

17 changes: 0 additions & 17 deletions src/MediactMagento2/phpmd.xml

This file was deleted.

11 changes: 0 additions & 11 deletions src/MediactMagento2/ruleset.xml

This file was deleted.

File renamed without changes.
113 changes: 113 additions & 0 deletions src/YouweMagento2/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0"?>
<!--
/**
* Copyright Youwe. All rights reserved.
* https://www.youweagency.com
*
* TODO:: Create a separate ruleset for phtml files, since a lot of exceptions need to be made just for adding phtml to code sniffer.
*/
-->
<ruleset name="YouweMagento2">
<description>Youwe coding standards for Magento2 websites and modules</description>
<!-- TODO:: Check if these values are correct. Did not see anything about how to configure this in documentation -->
<arg name="extensions" value="php/PHP,phtml/PHP,js/JS,css/CSS,xml/XML,less/CSS" />

<!-- Base rules on Youwe -->
<rule ref="Youwe">
<!-- Magento 2 does not use return types everywhere in the code base yet. So we cannot make this mandatory. -->
<exclude name="GlobalCommon.Php7.ReturnType" />
<!-- Magento 2 still uses $_ to tell if it's protected, so we cannot mandate this. -->
<exclude name="GlobalCommon.NamingConventions.ValidVariableName" />
<!-- TODO:: Check if this rule still needs to be excluded. Seems logical that all classes should start with camelcase -->
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<!--TODO:: Check if this should not be excluded. Seems logical to add throws in function comment. -->
<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows" />
<!-- Magento 2 still does not strict type arguments of functions. This is why this rule is excluded. -->
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing" />
<!-- Magento 2 still does not strict type arguments of functions. This is why this rule is excluded. -->
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing" />
</rule>

<!-- Import most rules from official Magento2 coding standard -->
<rule ref="Magento2">
<!-- Excluded because short descriptions are not mandatory in Youwe for a method. -->
<exclude name="Magento2.Annotation" />
<!--
Excluded because in PHP 8.1 it's already possible to declare what type it is.
Also most class properties are self-explanatory.
-->
<exclude name="Magento2.Commenting.ClassPropertyPHPDocFormatting" />
</rule>

<!-- Detects function that use a for-loops call in their function. -->
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed">
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="Generic.Commenting.DocComment">
<!-- default Magento 2 templates also not cohere to this. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="Generic.ControlStructures.InlineControlStructure.NotAllowed">
<!-- Magento 2 templates do not cohere to this rule. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="Generic.Files.LineLength.TooLong">
<!-- Magento 2 phtml & xml both have long lines think of checkout_index_index.xml -->
<exclude-pattern>*.phtml</exclude-pattern>
<exclude-pattern>*.xml</exclude-pattern>
</rule>

<rule ref="PEAR.Functions.FunctionCallSignature">
<!-- default Magento 2 templates also not cohere to this. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
<!-- In some cases Magento 2 still uses underscores for their properties. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="PSR2.ControlStructures.ControlStructureSpacing">
<!-- default Magento 2 templates also not cohere to this. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="PSR12.ControlStructures.ControlStructureSpacing">
<!-- default Magento 2 templates also not cohere to this. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="PSR12.Files.FileHeader.SpacingAfterBlock">
<!-- default Magento 2 templates also not cohere to this. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="PSR12.Operators.OperatorSpacing">
<!-- default Magento 2 templates also not cohere to this. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="Squiz.ControlStructures.ControlSignature">
<!-- Magento 2 uses a different notation for patterns like do { / if { for phtml that's why this was excluded. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="Squiz.WhiteSpace.ControlStructureSpacing">
<!-- default Magento 2 templates also not cohere to this. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

<rule ref="Squiz.WhiteSpace.MemberVarSpacing" >
<properties>
<property name="spacingBeforeFirst" value="0"/>
</properties>
</rule>

<rule ref="Squiz.WhiteSpace.ScopeClosingBrace">
<!-- Magento 2 phptml files end differently and use endif; for example. -->
<exclude-pattern>*.phtml</exclude-pattern>
</rule>
</ruleset>