From 7d4380bab074e3871020119eb6d78c675d6c76ce Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Thu, 20 Jun 2024 16:36:39 -0400 Subject: [PATCH] feat(fmt): add ecs --- composer.json | 15 ++++++++++----- ecs.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 ecs.php diff --git a/composer.json b/composer.json index 1dda0a7..333ed96 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..b378b82 --- /dev/null +++ b/ecs.php @@ -0,0 +1,50 @@ +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'], + ]) + +;