uocs / uncanny-owl-coding-standards
PHP_CodeSniffer rules (sniffs) to enforce Uncanny Owl coding conventions
Installs: 746
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Type:phpcodesniffer-standard
Requires
- php: >=7.4
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.2
- phpcompatibility/php-compatibility: ^9.3
- phpcompatibility/phpcompatibility-paragonie: ^1.3
- phpcompatibility/phpcompatibility-wp: ^2.1
- phpcsstandards/phpcsextra: ^1.1
- phpcsstandards/phpcsutils: ^1.0
- squizlabs/php_codesniffer: ^3.10.1
- wp-coding-standards/wpcs: ^3.1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- slevomat/coding-standard: ^8.0
- squizlabs/php_codesniffer: ^3.10
- szepeviktor/phpstan-wordpress: ^1.3
- vimeo/psalm: ^5.0
README
PHP_CodeSniffer rules and sniffs to enforce Uncanny Owl coding conventions.
Requirements
- PHP 7.4 or higher
- Composer
Installation
Global Installation (Recommended)
composer global require uocs/uncanny-owl-coding-standards
Project Installation
composer require --dev uocs/uncanny-owl-coding-standards
Usage
After installation, you can use the standards in several ways:
Using Composer Scripts (Recommended)
# Check coding standards composer uocs [path] # Fix coding standards composer uocbf [path] # Use strict mode composer uocs-strict [path] composer uocbf-strict [path]
Using PHPCS Directly
# Check coding standards vendor/bin/phpcs --standard=Uncanny-Owl [path] # Fix coding standards vendor/bin/phpcbf --standard=Uncanny-Owl [path]
Standards
The UOCS includes and extends the following standards:
- WordPress Coding Standards
- PHP Compatibility
- PHPCSExtra
- Custom Uncanny Owl rules
Available Standards
Uncanny-Owl
: Default standard with common rulesUncanny-Owl-Strict
: Stricter version with additional checks
Custom Ruleset
You can override the default ruleset for your project in two ways:
- Project-specific ruleset (Recommended):
Create a
phpcs.xml
orphpcs.xml.dist
in your project root:
<?xml version="1.0"?> <ruleset name="Custom Project Standard"> <!-- Use Uncanny-Owl as base --> <rule ref="Uncanny-Owl"> <!-- Exclude rules you don't want --> <exclude name="WordPress.Files.FileName"/> </rule> <!-- Add your own custom rules --> <rule ref="Generic.Arrays.DisallowLongArraySyntax"/> <!-- Configure specific rules --> <rule ref="Generic.Files.LineLength"> <properties> <property name="lineLimit" value="120"/> </properties> </rule> <!-- Define your paths --> <file>src/</file> <file>tests/</file> <!-- Define exclusions --> <exclude-pattern>/vendor/*</exclude-pattern> <exclude-pattern>/node_modules/*</exclude-pattern> </ruleset>
- Command-line Override:
# Using composer script composer uocs --standard=/path/to/your/custom-ruleset.xml [path] # Or directly with PHPCS vendor/bin/phpcs --standard=/path/to/your/custom-ruleset.xml [path]
IDE Integration
Visual Studio Code
- Install the PHP Sniffer & Beautifier extension
- Configure settings.json:
{ "phpSniffer.standard": "Uncanny-Owl", "phpSniffer.run": "onType" }
PhpStorm
- Go to Settings → PHP → Quality Tools → PHP_CodeSniffer
- Set PHP_CodeSniffer path to your vendor/bin/phpcs
- Go to Settings → Editor → Inspections
- Enable PHP → Quality Tools → PHP_CodeSniffer validation
- Set 'Coding Standard' to Uncanny-Owl
CI/CD Integration
Buddy
- pipeline: "Code Standards" trigger_mode: "ON_EVERY_PUSH" ref_name: "refs/heads/*" actions: - action: "Install Dependencies" type: "BUILD" working_directory: "/buddy/app" docker_image_name: "library/php" docker_image_tag: "8.1" execute_commands: - composer install - action: "Check Coding Standards" type: "BUILD" working_directory: "/buddy/app" docker_image_name: "library/php" docker_image_tag: "8.1" execute_commands: - composer uocs
GitHub Actions
name: PHP_CodeSniffer on: [push, pull_request] jobs: phpcs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.1' - name: Install Dependencies run: composer install - name: Run PHPCS run: composer uocs
Troubleshooting
Common Issues
-
Standards Not Found
- Ensure Composer installation was successful
- Try running
composer install
again - Check if the standard is listed in
vendor/bin/phpcs -i
-
Path Issues
- Use relative paths from your project root
- Ensure the path exists and is readable
Debug Mode
For detailed output, add -v
to the composer command:
composer uocs -v [path]
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support, please open an issue in the GitHub repository or contact the Uncanny Owl development team.
IDE Integration
Visual Studio Code
- Install the PHP Sniffer & Beautifier extension
- Configure settings.json:
{ "phpsab.standard": "Uncanny-Owl", "phpsab.executablePathCS": "/usr/local/bin/uocs", "phpsab.executablePathCBF": "/usr/local/bin/uocbf" }
PhpStorm
- Go to Settings → PHP → Quality Tools → PHP_CodeSniffer
- Set PHP_CodeSniffer path to the
uocs
binary - In Editor → Inspections → PHP → Quality Tools
- Enable PHP_CodeSniffer and select "Uncanny-Owl" standard
Troubleshooting
Common Issues
- Standards Not Found
make reinstall
- Permission Issues
sudo chmod +x ./bin/uocs ./bin/uocbf
- Path Issues
./bin/uocs --debug <path>
Debug Mode
For detailed output about paths and configuration:
./bin/uocs --debug <path> ./bin/uocbf --debug <path>
Contributing
- Fork the repository
- Create your feature branch
- Make your changes
- Run tests and ensure coding standards:
make check-standards
./bin/uocs .
- Submit a pull request
License
MIT License - see LICENSE file for details.