Skip to content

Commit 0108f9c

Browse files
authored
Implement Laravel Pint coding standards Composer package with configuration and shell scripts (#3)
1 parent b304aff commit 0108f9c

File tree

7 files changed

+347
-1
lines changed

7 files changed

+347
-1
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Vendor dependencies
2+
vendor/
3+
4+
# IDE files
5+
.vscode/
6+
.idea/
7+
*.swp
8+
*.swo
9+
10+
# OS files
11+
.DS_Store
12+
Thumbs.db
13+
14+
# Temporary files
15+
*.tmp
16+
*.temp

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 SynergiTech
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,112 @@
1-
# laravel-coding-standards
1+
# Laravel Coding Standards
2+
3+
A Composer package for implementing Laravel Pint coding standards across Laravel packages.
4+
5+
## Overview
6+
7+
This package provides:
8+
- A standardized `pint.json` configuration file with PSR-12 preset and custom rules
9+
- Shell scripts to run Laravel Pint for code formatting and testing
10+
- Automatic Laravel Pint dependency management through Composer
11+
12+
## Installation
13+
14+
### Via Composer (Recommended)
15+
16+
Install the package using Composer:
17+
18+
```bash
19+
composer require synergitech/laravel-coding-standards --dev
20+
```
21+
22+
This will automatically install Laravel Pint as a dependency and make the scripts available in your project.
23+
24+
### Alternative Installation Methods
25+
26+
1. **As a Git Submodule:**
27+
```bash
28+
git submodule add https://github.com/SynergiTech/laravel-coding-standards.git tools/coding-standards
29+
```
30+
31+
2. **Manual Installation:**
32+
Copy the files directly to your project and install Laravel Pint separately:
33+
```bash
34+
composer require laravel/pint --dev
35+
```
36+
37+
## Usage
38+
39+
### Running Pint
40+
41+
#### Apply Code Formatting
42+
To automatically fix coding standard issues:
43+
```bash
44+
./vendor/synergitech/laravel-coding-standards/pint
45+
```
46+
47+
Or if installed as submodule/manually:
48+
```bash
49+
./tools/coding-standards/pint
50+
# or
51+
./pint
52+
```
53+
54+
#### Test Code Standards
55+
To check for coding standard issues without making changes:
56+
```bash
57+
./vendor/synergitech/laravel-coding-standards/pint-test
58+
```
59+
60+
Or if installed as submodule/manually:
61+
```bash
62+
./tools/coding-standards/pint-test
63+
# or
64+
./pint-test
65+
```
66+
67+
### Adding Scripts to Your Composer.json
68+
69+
For easier access, you can add these scripts to your project's `composer.json`:
70+
71+
```json
72+
{
73+
"scripts": {
74+
"pint": "./vendor/synergitech/laravel-coding-standards/pint",
75+
"pint:test": "./vendor/synergitech/laravel-coding-standards/pint-test"
76+
}
77+
}
78+
```
79+
80+
Then run:
81+
```bash
82+
composer run pint # Apply formatting
83+
composer run pint:test # Test standards
84+
```
85+
86+
## Configuration
87+
88+
The `pint.json` file includes:
89+
- PSR-12 preset as the base standard
90+
- Custom rules for enhanced code quality
91+
- Exclusion of common directories (vendor, storage, bootstrap/cache)
92+
93+
## Custom Rules Included
94+
95+
- Array syntax and indentation improvements
96+
- Multiline comment alignment
97+
- String concatenation with single space
98+
- Strict type comparisons
99+
- Ordered class elements and imports
100+
- Modern PHP syntax preferences
101+
- And many more quality-of-life improvements
102+
103+
For a full list of rules, see the `pint.json` configuration file.
104+
105+
## Requirements
106+
107+
- PHP ^8.1
108+
- Laravel Pint ^1.0 (automatically installed with this package)
109+
110+
## License
111+
112+
This package is open-sourced software licensed under the [MIT license](LICENSE).

composer.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "synergitech/laravel-coding-standards",
3+
"description": "A generic package for implementing Laravel Pint coding standards across Laravel packages",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "SynergiTech",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": "^8.1",
14+
"laravel/pint": "^1.0"
15+
},
16+
"require-dev": {
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"SynergiTech\\LaravelCodingStandards\\": "src/"
21+
}
22+
},
23+
"bin": [
24+
"pint",
25+
"pint-test"
26+
],
27+
"extra": {
28+
"laravel": {
29+
"providers": []
30+
}
31+
},
32+
"config": {
33+
"sort-packages": true,
34+
"optimize-autoloader": true
35+
},
36+
"minimum-stability": "stable",
37+
"prefer-stable": true,
38+
"keywords": [
39+
"laravel",
40+
"pint",
41+
"coding-standards",
42+
"php-cs-fixer",
43+
"code-quality",
44+
"psr-12"
45+
]
46+
}

pint

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# Laravel Pint - Apply coding standards
4+
# This script runs Laravel Pint to automatically fix coding standard issues
5+
6+
# Get the directory where this script is located
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
9+
# Path to the pint.json config file
10+
CONFIG_FILE="$SCRIPT_DIR/pint.json"
11+
12+
# Try to find pint executable in different locations
13+
PINT_EXECUTABLE=""
14+
if [ -f "./vendor/bin/pint" ]; then
15+
PINT_EXECUTABLE="./vendor/bin/pint"
16+
elif [ -f "../../../bin/pint" ]; then
17+
# When installed via Composer in vendor/synergitech/laravel-coding-standards
18+
PINT_EXECUTABLE="../../../bin/pint"
19+
elif command -v pint >/dev/null 2>&1; then
20+
PINT_EXECUTABLE="pint"
21+
else
22+
echo "Error: Laravel Pint not found. Please install it with 'composer require laravel/pint --dev'"
23+
exit 1
24+
fi
25+
26+
# Check if config file exists
27+
if [ ! -f "$CONFIG_FILE" ]; then
28+
echo "Error: pint.json config file not found at $CONFIG_FILE"
29+
exit 1
30+
fi
31+
32+
# Run pint with the config file
33+
echo "Running Laravel Pint with config: $CONFIG_FILE"
34+
$PINT_EXECUTABLE --config="$CONFIG_FILE"

pint-test

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# Laravel Pint - Test coding standards
4+
# This script runs Laravel Pint in test mode to check for coding standard issues without making changes
5+
6+
# Get the directory where this script is located
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
9+
# Path to the pint.json config file
10+
CONFIG_FILE="$SCRIPT_DIR/pint.json"
11+
12+
# Try to find pint executable in different locations
13+
PINT_EXECUTABLE=""
14+
if [ -f "./vendor/bin/pint" ]; then
15+
PINT_EXECUTABLE="./vendor/bin/pint"
16+
elif [ -f "../../../bin/pint" ]; then
17+
# When installed via Composer in vendor/synergitech/laravel-coding-standards
18+
PINT_EXECUTABLE="../../../bin/pint"
19+
elif command -v pint >/dev/null 2>&1; then
20+
PINT_EXECUTABLE="pint"
21+
else
22+
echo "Error: Laravel Pint not found. Please install it with 'composer require laravel/pint --dev'"
23+
exit 1
24+
fi
25+
26+
# Check if config file exists
27+
if [ ! -f "$CONFIG_FILE" ]; then
28+
echo "Error: pint.json config file not found at $CONFIG_FILE"
29+
exit 1
30+
fi
31+
32+
# Run pint in test mode with the config file
33+
echo "Testing coding standards with Laravel Pint using config: $CONFIG_FILE"
34+
$PINT_EXECUTABLE --test --config="$CONFIG_FILE"

pint.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"preset": "psr12",
3+
"rules": {
4+
"align_multiline_comment": true,
5+
"array_indentation": true,
6+
"array_push": true,
7+
"array_syntax": true,
8+
"assign_null_coalescing_to_coalesce_equal": true,
9+
"blank_line_after_namespace": true,
10+
"blank_line_after_opening_tag": true,
11+
"combine_consecutive_issets": true,
12+
"combine_consecutive_unsets": true,
13+
"concat_space": {
14+
"spacing": "one"
15+
},
16+
"declare_parentheses": true,
17+
"explicit_indirect_variable": true,
18+
"explicit_string_variable": true,
19+
"final_class": false,
20+
"fully_qualified_strict_types": true,
21+
"global_namespace_import": {
22+
"import_classes": true,
23+
"import_functions": true
24+
},
25+
"is_null": true,
26+
"lambda_not_used_import": true,
27+
"logical_operators": true,
28+
"mb_str_functions": true,
29+
"method_argument_space": {
30+
"on_multiline": "ensure_fully_multiline"
31+
},
32+
"method_chaining_indentation": true,
33+
"modernize_strpos": true,
34+
"modernize_types_casting": true,
35+
"new_with_braces": true,
36+
"no_empty_comment": true,
37+
"no_superfluous_elseif": false,
38+
"no_useless_else": true,
39+
"not_operator_with_successor_space": true,
40+
"nullable_type_declaration_for_default_null_value": true,
41+
"ordered_class_elements": {
42+
"order": [
43+
"use_trait",
44+
"case",
45+
"constant",
46+
"constant_public",
47+
"constant_protected",
48+
"constant_private",
49+
"property_public",
50+
"property_protected",
51+
"property_private",
52+
"construct",
53+
"destruct",
54+
"magic",
55+
"phpunit",
56+
"method_abstract",
57+
"method_public_static",
58+
"method_public",
59+
"method_protected_static",
60+
"method_protected",
61+
"method_private_static",
62+
"method_private"
63+
],
64+
"sort_algorithm": "none"
65+
},
66+
"ordered_imports": {
67+
"sort_algorithm": "alpha"
68+
},
69+
"ordered_traits": true,
70+
"protected_to_private": true,
71+
"simplified_if_return": true,
72+
"strict_comparison": true,
73+
"ternary_to_null_coalescing": true,
74+
"trim_array_spaces": true,
75+
"use_arrow_functions": true,
76+
"void_return": false,
77+
"yoda_style": false
78+
},
79+
"exclude": [
80+
"vendor",
81+
"storage",
82+
"bootstrap/cache"
83+
]
84+
}

0 commit comments

Comments
 (0)