Skip to content

Commit

Permalink
Add prettier formatting of JavaScript, style, and HTML files, and che…
Browse files Browse the repository at this point in the history
…ck formatting in a workflow.

Prettier is used to format JavaScript, style, and HTML files in htdocs.
The configuration chosen is in .prettierrc and .editorconfig.  Prettier
doesn't really have many options as it is very opinionated.  I am not
entirely happy with everything prettier does, but it does give a more
uniform code format to files.  Furthermore, it is nice to be able to be
able to just run prettier and not need to worry about formatting code.

A workflow now checks formatting of JavaScript, style, and HTML files
with prettier in addition checking formatting of perl files with
perltidy.  Note the "linter" workflow has been renamed to
"check-formats", because that is what it does, and this really does not
have anything to do with linting.

Note that developers can (and should) run `npm run prettier-format` in
the htdocs directory to format files.  You can also run `npm run
prettier-check` to check that formatting of these files is correct, and
not actually change the files.  This is what the workflow does.
  • Loading branch information
drgrice1 committed Feb 13, 2024
1 parent 8cc8a86 commit e12a9f0
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 33 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4

[*.yml]
indent_style = space
indent_size = 2

[*.pg]
trim_trailing_whitespace = false
44 changes: 44 additions & 0 deletions .github/workflows/check-formats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: Check Formatting of Code Base

defaults:
run:
shell: bash

on:
push:
branches-ignore: [main, develop]
pull_request:

jobs:
perltidy:
name: Check Perl file formatting with perltidy
runs-on: ubuntu-22.04
container:
image: perl:5.34
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: cpanm -n Perl::Tidy@20220613
- name: Run perltidy
shell: bash
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
shopt -s extglob globstar nullglob
perltidy --pro=./.perltidyrc -b -bext='/' ./**/*.p[lm] ./**/*.t && git diff --exit-code
prettier:
name: Check JavaScript, style, and HTML file formatting with prettier
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Dependencies
run: cd htdocs && npm ci --ignore-scripts
- name: Check formatting with prettier
run: cd htdocs && npm run prettier-check
32 changes: 0 additions & 32 deletions .github/workflows/linter.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"printWidth": 120,
"semi": true,
"singleQuote": true,
"trailingComma": "none"
}
22 changes: 22 additions & 0 deletions htdocs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion htdocs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"license": "GPL-2.0+",
"scripts": {
"generate-assets": "node generate-assets",
"prepare": "npm run generate-assets"
"prepare": "npm run generate-assets",
"prettier-format": "prettier --ignore-path=../.gitignore --write \"**/*.{js,css,scss,html}\"",
"prettier-check": "prettier --ignore-path=../.gitignore --check \"**/*.{js,css,scss,html}\""
},
"repository": {
"type": "git",
Expand All @@ -28,6 +30,7 @@
"chokidar": "^3.5.3",
"cssnano": "^6.0.1",
"postcss": "^8.4.31",
"prettier": "^3.1.1",
"rtlcss": "^4.1.1",
"sass": "^1.69.5",
"terser": "^5.24.0",
Expand Down

0 comments on commit e12a9f0

Please sign in to comment.