Skip to content

Commit

Permalink
feat(fmt): add ecs
Browse files Browse the repository at this point in the history
montchr committed Jun 20, 2024
1 parent 2a94992 commit 7d4380b
Showing 2 changed files with 60 additions and 5 deletions.
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -3,10 +3,7 @@
"description": "PHP coding standards for Klein Digitial Initiatives",
"license": "GPL-3.0-or-later",
"type": "phpcodesniffer-standard",
"keywords": [
"phpcs",
"static analysis"
],
"keywords": ["phpcs", "static analysis"],
"require": {
"php": ">=8.1",
"automattic/vipwpcs": "^3.0",
@@ -16,12 +13,20 @@
"wp-coding-standards/wpcs": "^3.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.43"
"ergebnis/composer-normalize": "^2.43",
"symplify/easy-coding-standard": "^12.3"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true
}
},
"scripts": {
"ecs": "ecs check --config=$PRJ_ROOT/ecs.php",
"fix": ["@ecs --fix --ansi", "@phpcbf"],
"lint": ["@ecs --ansi", "@phpcs"],
"phpcbf": "phpcbf --extensions=php --standard=$PRJ_ROOT/phpcs.xml.dist",
"phpcs": "phpcs --extensions=php --standard=$PRJ_ROOT/phpcs.xml.dist"
}
}
50 changes: 50 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* ECS configuration for Kleinweb projects.
*/

declare(strict_types=1);

use PhpCsFixer\Fixer\ClassNotation\OrderedTypesFixer;
use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer;
use PhpCsFixer\Fixer\ReturnNotation\SimplifiedNullReturnFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withPaths([
'ecs.php',
])
->withPreparedSets(strict: true, common: true, psr12: true, symplify: true, cleanCode: true)
->withPhpCsFixerSets(symfony: true)
->withRules([PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer::class])
->withSkip([
// Fully-qualified namespaces provide clarity here.
GlobalNamespaceImportFixer::class => ['ecs.php'],

// Can cause invalid return types.
SimplifiedNullReturnFixer::class,

// PhpdocSummaryFixer::class,
])
->withConfiguredRule(YodaStyleFixer::class, [
'equal' => false,
'identical' => false,
'less_and_greater' => false,
])
->withConfiguredRule(GlobalNamespaceImportFixer::class, [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
])
->withConfiguredRule(OrderedTypesFixer::class, [
'null_adjustment' => 'always_last',
])
->withConfiguredRule(TrailingCommaInMultilineFixer::class, [
'after_heredoc' => true,
'elements' => ['arguments', 'arrays', 'match', 'parameters'],
])

;

0 comments on commit 7d4380b

Please sign in to comment.