From 9581c33f83664803ed4995c4c9976e8e61fe32b6 Mon Sep 17 00:00:00 2001 From: Vyom Jain Date: Sun, 16 Oct 2022 12:21:04 +0530 Subject: [PATCH] chore: Added Prettier workflow for formatting (#152) Co-authored-by: Jonah Lawrence --- .github/workflows/prettier.yml | 43 ++++++++++++++++++++++++++++++++++ .prettierignore | 2 ++ CONTRIBUTING.md | 15 +++++++++++- composer.json | 6 +++-- docs/faq.md | 14 +++++++---- 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/prettier.yml create mode 100644 .prettierignore diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 0000000..763e3c5 --- /dev/null +++ b/.github/workflows/prettier.yml @@ -0,0 +1,43 @@ +name: Format with Prettier + +on: + push: + branches: + - main + pull_request: + paths: + - "**.php" + - "**.md" + - "**.js" + - "**.css" + +jobs: + prettier: + runs-on: ubuntu-latest + steps: + - 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: Check formatting with Prettier + continue-on-error: true + run: composer format:check + + - name: Prettify code + run: composer format + + - name: Commit changes + uses: EndBug/add-and-commit@v9 + with: + message: "style: Formatted code with Prettier" + default_author: github_actions diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..ace5727 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +vendor +*.min.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 699e59e..c2c22ea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,8 +50,21 @@ Before you can run tests, PHPUnit must be installed. You can install it using Co composer install ``` +### Format and test the code + +Run the following command to format the code with Prettier: +``` +composer run format +``` + +Run the following command to check if your code is formatted properly: +``` +composer run format:check +``` +> **Note** You need to have [`prettier`](https://prettier.io/) and the [prettier-php plugin](https://github.com/prettier/plugin-php) installed globally in order to run this command. + Run the following command to run the PHPUnit test script which will verify that the tested functionality is still working. ```bash composer test -``` \ No newline at end of file +``` diff --git a/composer.json b/composer.json index b824ffd..463fdb4 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,8 @@ }, "scripts": { "start": "php7 -S localhost:8000 -t src || php -S localhost:8000 -t src", - "test": "./vendor/bin/phpunit --testdox tests" + "test": "./vendor/bin/phpunit --testdox tests", + "format:check": "prettier --check *.md **/**/*.{php,md,js,css} --print-width 120", + "format": "prettier --write *.md **/**/*.{php,md,js,css} --print-width 120" } -} \ No newline at end of file +} diff --git a/docs/faq.md b/docs/faq.md index 2f69e22..e88cd29 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -12,9 +12,11 @@ Markdown files on GitHub support embedded images using Markdown or HTML. You can ### HTML + ```html - + ``` + ## The text is getting cut off at the end, how do I fix it? @@ -30,11 +32,13 @@ https://readme-typing-svg.demolab.com/?lines=Your+Long+Message+With+A+Long+Width To center align images, you must use the HTML syntax and wrap it in an element with the HTML attribute `align="center"`. + ```html

- +

``` + ## How do I add multiple spaces in the middle of a line? @@ -46,12 +50,14 @@ A workaround for adding extra spaces can be to use other whitespace characters ( As of May 2022, you can now [specify theme context](https://github.blog/changelog/2022-05-19-specify-theme-context-for-images-in-markdown-beta/) using the `` and `` elements as shown below. The dark mode version appears in the `srcset` of the `` tag and the light mode version appears in the `src` of the `` tag. + ```html - - + + ``` + ## How do I create a Readme for my profile?