Skip to content

Commit ec6b896

Browse files
authored
ci: Enhancements to prettier workflow and linting documentation (#311)
1 parent 336c947 commit ec6b896

File tree

6 files changed

+49
-9
lines changed

6 files changed

+49
-9
lines changed

.github/workflows/prettier.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
11
name: Format with Prettier
22

33
on:
4-
pull_request:
54
push:
65
branches:
76
- main
7+
pull_request:
8+
paths:
9+
- "**.php"
10+
- "**.md"
11+
- "**.js"
12+
- "**.css"
813

914
jobs:
1015
prettier:
1116
runs-on: ubuntu-latest
12-
1317
steps:
14-
- name: Checkout
18+
- name: Checkout Pull Request
19+
if: ${{ github.event_name == 'pull_request' }}
20+
uses: actions/checkout@v3
21+
with:
22+
repository: ${{ github.event.pull_request.head.repo.full_name }}
23+
ref: ${{ github.event.pull_request.head.ref }}
24+
25+
- name: Checkout Push
26+
if: ${{ github.event_name != 'pull_request' }}
1527
uses: actions/checkout@v3
1628

1729
- name: Install prettier and plugin-php
1830
run: npm install --global prettier @prettier/plugin-php
1931

32+
- name: Lint with Prettier
33+
continue-on-error: true
34+
run: composer lint
35+
2036
- name: Prettify code
2137
run: composer lint-fix
2238

2339
- name: Commit changes
24-
uses: stefanzweifel/git-auto-commit-action@v4
40+
uses: EndBug/add-and-commit@v9
2541
with:
26-
commit_message: "style: Formatted code with Prettier"
27-
branch: ${{ github.head_ref }}
42+
message: "style: Formatted code with Prettier"
43+
default_author: github_actions

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ Run the following command to run the PHPUnit test script which will verify that
8686
composer test
8787
```
8888

89+
## Linting
90+
91+
This project uses Prettier for formatting PHP, Markdown, JavaScript and CSS files.
92+
93+
```bash
94+
# Run prettier and show the files that need to be fixed
95+
composer lint
96+
97+
# Run prettier and fix the files
98+
composer lint-fix
99+
```
100+
89101
## Submitting Contributions 👨‍💻
90102

91103
Below you will find the process and workflow used to review and merge your changes.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ Run the following command to run the PHPUnit test script which will verify that
223223
composer test
224224
```
225225

226+
### Linting
227+
228+
This project uses Prettier for formatting PHP, Markdown, JavaScript and CSS files.
229+
230+
```bash
231+
# Run prettier and show the files that need to be fixed
232+
composer lint
233+
234+
# Run prettier and fix the files
235+
composer lint-fix
236+
```
237+
226238
## 🙋‍♂️ Support
227239

228240
💙 If you like this project, give it a ⭐ and share it with friends!

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"php -S localhost:8000 -t src"
3232
],
3333
"test": "./vendor/bin/phpunit --testdox tests",
34-
"lint": "prettier --check **/*.{php,md,js,css} !**/*.min.js --print-width 120",
35-
"lint-fix": "prettier --write **/*.{php,md,js,css} !**/*.min.js --print-width 120"
34+
"lint": "prettier --check *.md **/*.{php,md,js,css} !**/*.min.js --print-width 120",
35+
"lint-fix": "prettier --write *.md **/*.{php,md,js,css} !**/*.min.js --print-width 120"
3636
}
3737
}

src/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
require_once "card.php";
99

1010
// load .env
11-
1211
$dotenv = \Dotenv\Dotenv::createImmutable(dirname(__DIR__, 1));
1312
$dotenv->safeLoad();
1413

0 commit comments

Comments
 (0)