Skip to content

Commit

Permalink
APPS-4764 Use default phpcs.xml for the codesniffer tasks. (#169)
Browse files Browse the repository at this point in the history
* APPS-4764 Use default phpcs.xml, removed allowing to pass a config path for the Code Sniffer.

* APPS-4764: Fixed tests.

* APPS-4764: Changed default value for code sniffer and fixer tasks.

* APPS-4764: Changed default value for code sniffer and fixer tasks.

* APPS-4764: Provided\updated help messages for the command that are using code sniffer.

* APPS-4769: Moved phpcs options to the ruleset.xml config file and adjusted development and production environments.

* APPS-4769: Renamed ruleset.xml to phpcs.xml for automatic usage by default.

* APPS-4769: phpcs.xml path fixes and docker stuff updates.

* APPS-4769: Fixed typo.

* APPS-4769: Changed help messages for the sniffer related tasks and skipped related tests.

* APPS-4769: Fixed tests.

* APPS-4769: Fixed tests.

* APPS-4769: Fixed Eslint tests.

Co-authored-by: pavlo.maksymov <[email protected]>
  • Loading branch information
stereomon and pavelmaksimov25 authored Aug 22, 2022
1 parent 0832d3f commit ab78cb8
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 26 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
"symfony/polyfill-php72": "*"
},
"scripts": {
"cs-check": "phpcs --colors -p -s --extensions=php --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml --ignore=/tests/_project/, src/ tests/ extension/",
"cs-fix": "phpcbf --colors -p --extensions=php --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml --ignore=/tests/_project/, src/ tests/ extension/",
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"stan": "phpstan analyze -l 8 src/",
"linters": [
"@cs-fix",
Expand Down
1 change: 1 addition & 0 deletions infrastructure/sdk.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ COPY --chown=spryker:spryker .env.prod ${srcRoot}/.env.prod

RUN --mount=type=cache,id=composer,sharing=locked,target=/home/spryker/.composer/cache,uid=1000 \
composer dump-autoload -o

ENV APP_ENV=prod

RUN bin/console cache:warmup
Expand Down
25 changes: 25 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<ruleset name="Sdk">
<description>
Spryker Coding Standard for Project.

Extends main Spryker Coding Standard.
All sniffs in ./Sniffs will be auto loaded
</description>

<rule ref="vendor/spryker/code-sniffer/Spryker/ruleset.xml"/>

<file>src/</file>
<file>tests/</file>
<file>extension/</file>

<exclude-pattern>/tests/_project/*</exclude-pattern>
<exclude-pattern>/tests/_output/*</exclude-pattern>
<exclude-pattern>/tests/_support/_generated/*</exclude-pattern>
<exclude-pattern>/tests/_support/data/*</exclude-pattern>

<arg name="extensions" value="php" />
<arg name="colors"/>
<arg value="sp"/>

</ruleset>
11 changes: 2 additions & 9 deletions src/Extension/Task/CodesnifferFixerTask.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
id: "validation:php:codestyle-fix"
short_description: "Check your code by running a static code analysis"
help: ~
help: "You may need to set default phpcs standard before using it. By default uses phpcs.xml from the project root."
stage: build
version: 1.0.0
command: "php %sdk_dir%/vendor/bin/phpcbf %severity% --standard=%config% ./%path%"
command: "php %sdk_dir%/vendor/bin/phpcbf %severity% ./%path%"
type: local_cli
optional: true
placeholders:
Expand All @@ -17,13 +17,6 @@ placeholders:
configuration:
name: 'severity'
description: 'Severity level of the CodeSniffer'
- name: "%config%"
value_resolver: CONFIG_PATH
optional: true
configuration:
name: "config"
description: "Config file"
defaultValue: "vendor/spryker/code-sniffer/Spryker/ruleset.xml"
- name: "%path%"
value_resolver: STATIC
optional: false
Expand Down
19 changes: 6 additions & 13 deletions src/Extension/Task/CodesnifferTask.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
---
id: "validation:php:codestyle-check"
short_description: "Check your code by running a static code analysis and generate report with violations"
help: ~
help: "You may need to set default phpcs standard before using it. By default uses phpcs.xml from the project root."
stage: build
version: 1.0.0
command: "php %sdk_dir%/vendor/bin/phpcs %severity% --standard=%config% --report=json ./%path% --report-file=%reportDir%/phpcs.codestyle.json"
command: "php %sdk_dir%/vendor/bin/phpcs %severity% --report=json ./%path% --report-file=%reportDir%/phpcs.codestyle.json"
type: local_cli
placeholders:
- name: "%sdk_dir%"
value_resolver: SDK_DIR
optional: true
- name: "%config%"
value_resolver: CONFIG_PATH
optional: true
configuration:
name: "config"
description: "Config file"
defaultValue: "vendor/spryker/code-sniffer/Spryker/ruleset.xml"
- name: "%path%"
value_resolver: STATIC
optional: false
Expand All @@ -41,7 +34,7 @@ placeholders:
name: 'severity'
description: 'Severity level of the CodeSniffer'
report_converter:
name: CheckstyleViolationReportConverter
configuration:
input_file: phpcs.codestyle.json
producer: phpcs
name: CheckstyleViolationReportConverter
configuration:
input_file: phpcs.codestyle.json
producer: phpcs
2 changes: 1 addition & 1 deletion src/Extension/Task/CodesnifferTaskSet.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: "validation:php:codestyle"
short_description: "Fixes violations and validates your php code using different approaches like codestyle. Generate report in the end."
help: "Fixes violations and validates your php code using different approaches like codestyle. Generate report in the end."
help: "Fixes violations and validates your php code using different approaches like codestyle. Generate report in the end. By default uses phpcs.xml from the project root."
stage: build
version: 1.0.0
command: ~
Expand Down
2 changes: 1 addition & 1 deletion src/Extension/Task/SnifferTaskSet.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: "validation:php:all"
short_description: "Validates your php code using different approaches like codestyle, architecural and static analysis"
help: "Validates your php code using different approaches like codestyle, architecural and static analysis"
help: "Validates your php code using different approaches like codestyle, architecural and static analysis. By default uses phpcs.xml from the project root."
stage: build
version: 1.0.0
command: ~
Expand Down
11 changes: 11 additions & 0 deletions tests/_project/project/phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<ruleset name="SdkTest">
<description>
Spryker Coding Standard Stub for the acceptance tests.

Extends main Spryker Coding Standard.
</description>

<rule ref="../../../vendor/spryker/code-sniffer/Spryker/ruleset.xml"/>

</ruleset>

0 comments on commit ab78cb8

Please sign in to comment.