Skip to content

Commit

Permalink
Add(linting) Add code linting to GitHub workflow, use php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhu authored and thePanz committed Feb 22, 2023
1 parent 2c5a4d6 commit ffbbce6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Code Linting"
on:
push:
branches:
- master
pull_request:

jobs:
php-cs-fixer:
name: 'PHP-CS-Fixer'
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v3'

- name: 'Setup PHP'
uses: 'shivammathur/setup-php@v2'
with:
php-version: '8.1'
tools: php-cs-fixer, cs2pr

- uses: 'actions/cache@v3'
with:
path: '.php-cs-fixer.cache'
key: '${{ github.repository }}-8.1-phpcsfixer-${{ github.ref_name }}'
restore-keys: |
${{ github.repository }}-8.1-phpcsfixer-main
${{ github.repository }}-8.1-phpcsfixer-
- name: 'Run PHP-CS-Fixer'
# Using cs2pr settings, see: https://github.com/shivammathur/setup-php#tools-with-checkstyle-support
run: 'php-cs-fixer fix --dry-run --format checkstyle | cs2pr'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
lib/plugins/sfDoctrinePlugin/test/functional/fixtures/log/
/vendor
/composer.lock
.php-cs-fixer.cache
29 changes: 29 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

$finder = PhpCsFixer\Finder::create()
->ignoreVCSIgnored(true)
->in(__DIR__.'/lib')
->in(__DIR__.'/data/bin')
->in(__DIR__.'/test')
->append(array(__FILE__))
// Exclude PHP classes templates/generators, which are not valid PHP files
->exclude('task/generator/skeleton/')
->exclude('plugins/sfDoctrinePlugin/data/generator/')
// Exclude generated files (single files)
->notPath('unit/config/fixtures/sfDefineEnvironmentConfigHandler/prefix_result.php')
->notPath('unit/config/fixtures/sfFilterConfigHandler/result.php')
;

$config = new PhpCsFixer\Config();
$config->setRules(array(
'@PhpCsFixer' => true,
'@Symfony' => true,
'array_syntax' => array(
'syntax' => 'long',
),
))
->setCacheFile('.php-cs-fixer.cache')
->setFinder($finder)
;

return $config;

0 comments on commit ffbbce6

Please sign in to comment.