diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml index b2d8d465..8b043291 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier.yml @@ -1,27 +1,43 @@ name: Format with Prettier on: - pull_request: push: branches: - main + pull_request: + paths: + - "**.php" + - "**.md" + - "**.js" + - "**.css" jobs: prettier: runs-on: ubuntu-latest - steps: - - name: Checkout + - name: Checkout Pull Request + if: ${{ github.event_name == 'pull_request' }} + uses: actions/checkout@v3 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} + + - name: Checkout Push + if: ${{ github.event_name != 'pull_request' }} uses: actions/checkout@v3 - name: Install prettier and plugin-php run: npm install --global prettier @prettier/plugin-php + - name: Lint with Prettier + continue-on-error: true + run: composer lint + - name: Prettify code run: composer lint-fix - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 + uses: EndBug/add-and-commit@v9 with: - commit_message: "style: Formatted code with Prettier" - branch: ${{ github.head_ref }} + message: "style: Formatted code with Prettier" + default_author: github_actions diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..22d0d82f --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +vendor diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 66201c5f..b109436f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -86,6 +86,18 @@ Run the following command to run the PHPUnit test script which will verify that composer test ``` +## Linting + +This project uses Prettier for formatting PHP, Markdown, JavaScript and CSS files. + +```bash +# Run prettier and show the files that need to be fixed +composer lint + +# Run prettier and fix the files +composer lint-fix +``` + ## Submitting Contributions 👨‍💻 Below you will find the process and workflow used to review and merge your changes. diff --git a/README.md b/README.md index e11e261a..ad4a6a95 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,18 @@ Run the following command to run the PHPUnit test script which will verify that composer test ``` +### Linting + +This project uses Prettier for formatting PHP, Markdown, JavaScript and CSS files. + +```bash +# Run prettier and show the files that need to be fixed +composer lint + +# Run prettier and fix the files +composer lint-fix +``` + ## 🙋‍♂️ Support 💙 If you like this project, give it a ⭐ and share it with friends! diff --git a/composer.json b/composer.json index 8f5e3f9e..16c733b4 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "php -S localhost:8000 -t src" ], "test": "./vendor/bin/phpunit --testdox tests", - "lint": "prettier --check **/*.{php,md,js,css} !**/*.min.js --print-width 120", - "lint-fix": "prettier --write **/*.{php,md,js,css} !**/*.min.js --print-width 120" + "lint": "prettier --check *.md **/*.{php,md,js,css} !**/*.min.js --print-width 120", + "lint-fix": "prettier --write *.md **/*.{php,md,js,css} !**/*.min.js --print-width 120" } } \ No newline at end of file diff --git a/src/index.php b/src/index.php index 58367637..ea723508 100644 --- a/src/index.php +++ b/src/index.php @@ -8,7 +8,6 @@ require_once "card.php"; // load .env - $dotenv = \Dotenv\Dotenv::createImmutable(dirname(__DIR__, 1)); $dotenv->safeLoad();