Skip to content

Commit

Permalink
✨ use grumphp-config for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti committed Jul 31, 2023
1 parent 88719f3 commit 1a91eba
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-grumphp-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ jobs:
image: kanti/buildy:${{ matrix.php }}
steps:
- uses: actions/checkout@v2
- run: composer install --no-progress --no-scripts -n
- run: COMPOSER_ROOT_VERSION=dev-main composer install --no-progress --no-scripts -n
- run: ./vendor/bin/grumphp run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
composer.lock
var/
Empty file modified bin/fixbom
100644 → 100755
Empty file.
73 changes: 41 additions & 32 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
{
"name": "pluswerk/grumphp-bom-task",
"description": "Force files to have no BOM",
"type": "library",
"license": "LGPL-3.0-or-later",
"authors": [
{
"name": "Matthias Vogel",
"email": "[email protected]",
"homepage": "https://www.andersundsehr.com"
}
],
"support": {
"issues": "https://github.com/pluswerk/grumphp-bom-task/issues"
},
"bin": ["bin/fixbom"],
"autoload":{
"psr-4":{
"PLUS\\GrumPHPBomTask\\": "src/"
}
},
"require": {
"php": "~8.1.0 || ~8.2.0",
"phpro/grumphp": "^2",
"opis/closure": "^3.6.2"
},
"require-dev": {
"squizlabs/php_codesniffer": ">=3.5.0 <4.0.0"
},
"config": {
"allow-plugins": {
"phpro/grumphp": true
}
"name": "pluswerk/grumphp-bom-task",
"description": "Force files to have no BOM",
"license": "LGPL-3.0-or-later",
"type": "library",
"authors": [
{
"name": "Matthias Vogel",
"email": "[email protected]",
"homepage": "https://www.andersundsehr.com"
}
],
"support": {
"issues": "https://github.com/pluswerk/grumphp-bom-task/issues"
},
"require": {
"php": "~8.1.0 || ~8.2.0",
"phpro/grumphp": "^2.0.0"
},
"require-dev": {
"pluswerk/grumphp-config": "^6.8.0"
},
"autoload": {
"psr-4": {
"PLUS\\GrumPHPBomTask\\": "src/"
}
},
"bin": [
"bin/fixbom"
],
"config": {
"allow-plugins": {
"phpro/grumphp": true,
"phpstan/extension-installer": true,
"ergebnis/composer-normalize": true,
"pluswerk/grumphp-config": true
}
},
"extra": {
"branch-alias": {
"dev-main": "8.0.x-dev"
}
}
}
43 changes: 16 additions & 27 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
grumphp:
tasks:
composer:
with_dependencies: false
strict: false
git_blacklist:
keywords:
- "die("
- "var_dump("
- "exit;"
triggered_by: [php]
git_commit_message:
max_subject_width: 120
max_body_width: 120
enforce_capitalized_subject: false
jsonlint:
detect_key_conflicts: true
phpcs:
standard: "PSR12"
warning_severity: 0
tab_width: 4
yamllint: ~
plus_bom_fixer:
metadata:
priority: 100
extensions:
- PLUS\GrumPHPBomTask\ExtensionLoader
imports:
- { resource: vendor/pluswerk/grumphp-config/grumphp.yml }
parameters:
convention.process_timeout: 240
convention.security_checker_blocking: true
convention.jsonlint_ignore_pattern: { }
convention.xmllint_ignore_pattern: { }
convention.yamllint_ignore_pattern: { }
convention.phpcslint_ignore_pattern: { }
convention.phpcslint_exclude: { }
convention.xlifflint_ignore_pattern: { }
convention.rector_ignore_pattern: { }
convention.rector_enabled: true
convention.rector_config: rector.php
convention.rector_clear-cache: false
convention.phpstan_level: null
2 changes: 2 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors: []
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- phpstan-baseline.neon
- vendor/andersundsehr/phpstan-git-files/extension.php

parameters:
level: 8
reportUnmatchedIgnoredErrors: false
42 changes: 42 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

use PLUS\GrumPHPConfig\RectorSettings;
use Rector\Config\RectorConfig;
use Rector\Caching\ValueObject\Storage\FileCacheStorage;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->parallel();
$rectorConfig->importNames();
$rectorConfig->importShortClasses();
$rectorConfig->cacheClass(FileCacheStorage::class);
$rectorConfig->cacheDirectory('./var/cache/rector');

$rectorConfig->paths(
array_filter(explode("\n", (string)shell_exec("git ls-files | xargs ls -d 2>/dev/null | grep -E '\.(php|html|typoscript)$'")))
);

// define sets of rules
$rectorConfig->sets(
[
...RectorSettings::sets(true),
...RectorSettings::setsTypo3(false),
]
);

// remove some rules
// ignore some files
$rectorConfig->skip(
[
...RectorSettings::skip(),
...RectorSettings::skipTypo3(),

/**
* rector should not touch these files
*/
//__DIR__ . '/src/Example',
//__DIR__ . '/src/Example.php',
]
);
};
31 changes: 19 additions & 12 deletions src/BomFixerTask.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

declare(strict_types=1);

namespace PLUS\GrumPHPBomTask;

use Symfony\Component\Finder\SplFileInfo;
use GrumPHP\Runner\TaskResult;
use GrumPHP\Runner\TaskResultInterface;
use GrumPHP\Task\Config\ConfigOptionsResolver;
Expand All @@ -15,8 +18,7 @@

final class BomFixerTask implements TaskInterface
{
/** @var TaskConfigInterface */
private $config;
private EmptyTaskConfig|TaskConfigInterface $config;

public function __construct()
{
Expand Down Expand Up @@ -63,20 +65,19 @@ public function run(ContextInterface $context): TaskResultInterface

if (is_file('./vendor/bin/fixbom')) {
$fixCommand = './vendor/bin/fixbom';
} elseif (is_file('./bin/fixbom')) {
$fixCommand = './bin/fixbom';
} else {
if (is_file('./bin/fixbom')) {
$fixCommand = './bin/fixbom';
} else {
$fixCommand = 'fixbom';
}
$fixCommand = 'fixbom';
}

$shouldGetFixedLog = [];
/** @var \Symfony\Component\Finder\SplFileInfo $file */
/** @var SplFileInfo $file */
foreach ($files as $file) {
$execFile = $file->getPathname();
if ($this->isFileWithBOM($execFile)) {
$shouldGetFixedLog[] = $execFile . ' has BOM and should be fixed';
$fixCommand .= ' \'' . $execFile . '\'';
$fixCommand .= " '" . $execFile . "'";
}
}

Expand All @@ -86,6 +87,7 @@ public function run(ContextInterface $context): TaskResultInterface
. $fixCommand;
return TaskResult::createFailed($this, $context, $errorMessage);
}

return TaskResult::createPassed($this, $context);
}

Expand All @@ -98,9 +100,14 @@ private function fileInfoSearch(string $filename, string $search): bool
{
$output = [];
exec('file ' . '"' . $filename . '"', $output, $returnVar);
if ($returnVar === 0 && !empty($output[0]) && strpos($output[0], $search) !== false) {
return true;
if ($returnVar !== 0) {
return false;
}
return false;

if (empty($output[0])) {
return false;
}

return str_contains($output[0], $search);
}
}
5 changes: 3 additions & 2 deletions src/ExtensionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

namespace PLUS\GrumPHPBomTask;

use Iterator;
use GrumPHP\Extension\ExtensionInterface;

class ExtensionLoader implements ExtensionInterface
final class ExtensionLoader implements ExtensionInterface
{
public function imports(): iterable
public function imports(): Iterator
{
yield __DIR__ . '/../Services.yaml';
}
Expand Down

0 comments on commit 1a91eba

Please sign in to comment.