Skip to content

Commit ffbbce6

Browse files
connorhuthePanz
authored andcommitted
Add(linting) Add code linting to GitHub workflow, use php-cs-fixer
1 parent 2c5a4d6 commit ffbbce6

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.github/workflows/lint.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Code Linting"
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
8+
jobs:
9+
php-cs-fixer:
10+
name: 'PHP-CS-Fixer'
11+
runs-on: 'ubuntu-latest'
12+
steps:
13+
- uses: 'actions/checkout@v3'
14+
15+
- name: 'Setup PHP'
16+
uses: 'shivammathur/setup-php@v2'
17+
with:
18+
php-version: '8.1'
19+
tools: php-cs-fixer, cs2pr
20+
21+
- uses: 'actions/cache@v3'
22+
with:
23+
path: '.php-cs-fixer.cache'
24+
key: '${{ github.repository }}-8.1-phpcsfixer-${{ github.ref_name }}'
25+
restore-keys: |
26+
${{ github.repository }}-8.1-phpcsfixer-main
27+
${{ github.repository }}-8.1-phpcsfixer-
28+
29+
- name: 'Run PHP-CS-Fixer'
30+
# Using cs2pr settings, see: https://github.com/shivammathur/setup-php#tools-with-checkstyle-support
31+
run: 'php-cs-fixer fix --dry-run --format checkstyle | cs2pr'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
lib/plugins/sfDoctrinePlugin/test/functional/fixtures/log/
77
/vendor
88
/composer.lock
9+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->ignoreVCSIgnored(true)
5+
->in(__DIR__.'/lib')
6+
->in(__DIR__.'/data/bin')
7+
->in(__DIR__.'/test')
8+
->append(array(__FILE__))
9+
// Exclude PHP classes templates/generators, which are not valid PHP files
10+
->exclude('task/generator/skeleton/')
11+
->exclude('plugins/sfDoctrinePlugin/data/generator/')
12+
// Exclude generated files (single files)
13+
->notPath('unit/config/fixtures/sfDefineEnvironmentConfigHandler/prefix_result.php')
14+
->notPath('unit/config/fixtures/sfFilterConfigHandler/result.php')
15+
;
16+
17+
$config = new PhpCsFixer\Config();
18+
$config->setRules(array(
19+
'@PhpCsFixer' => true,
20+
'@Symfony' => true,
21+
'array_syntax' => array(
22+
'syntax' => 'long',
23+
),
24+
))
25+
->setCacheFile('.php-cs-fixer.cache')
26+
->setFinder($finder)
27+
;
28+
29+
return $config;

0 commit comments

Comments
 (0)