Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Prettier GitHub workflow #9163

Merged
merged 25 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d96de69
replace older eslintrc with newer eslint.config.js
jazzsequence Aug 8, 2024
01db848
replace older prettierrc with newer prettier.config.cjs
jazzsequence Aug 8, 2024
c968d31
require eslint
jazzsequence Aug 8, 2024
2d7314b
needs to be a module so we can call the eslint.config.js
jazzsequence Aug 8, 2024
1bf0d63
add a lint script
jazzsequence Aug 8, 2024
2452fda
remove debugging
jazzsequence Aug 8, 2024
e10fd34
add a lint action
jazzsequence Aug 8, 2024
9d40615
remove semi from prettier config
jazzsequence Aug 8, 2024
744a260
remove the eslint line at the end
jazzsequence Aug 8, 2024
f6179d9
update readme
jazzsequence Aug 8, 2024
430b3fe
refactor eslint to prettier action
jazzsequence Aug 14, 2024
97e9f0b
only trigger on workflow dispatch
jazzsequence Aug 15, 2024
4893d9e
update the prettier path
jazzsequence Aug 15, 2024
4718d3b
add fetch depth to checkout
jazzsequence Aug 15, 2024
bff590c
oneline the pr comment
jazzsequence Aug 15, 2024
9540ba0
output the changed files & diff to the github env
jazzsequence Aug 15, 2024
7b2c180
proper diff and fetch main
jazzsequence Aug 15, 2024
feebb3d
simplify path mapping
jazzsequence Aug 15, 2024
728bd2c
update gh action with tweaks from https://github.com/pantheon-systems…
jazzsequence Aug 26, 2024
5f8e55d
Merge branch 'main' into 9082-re-add-prettier
jazzsequence Oct 11, 2024
43fe4da
add some inline docs to the action
jazzsequence Oct 11, 2024
2943260
readme copy changes
jazzsequence Oct 11, 2024
775c1bd
remove plugin-prettier
jazzsequence Oct 11, 2024
27dd390
update package-lock
jazzsequence Oct 11, 2024
6b3174a
Update README.md
stevector Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .eslintrc

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: ESLint

on:
pull_request:
paths:
- 'src/**/*.{js,jsx,ts,tsx}'
- '.github/workflows/eslint.yml'
types:
- opened
- synchronize
- reopened
- ready_for_review
workflow_dispatch:

permissions:
contents: read
pull-requests: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'latest'
- name: Install Node dependencies
run: npm ci
- name: Lint only affected files
env:
GH_TOKEN: ${{ github.token }}
run: |
CHANGED_FILES=$(gh pr diff ${{ github.event.pull_request.number }} --name-only | grep -E '\.js$|\.jsx$|\.ts$|\.tsx$' || echo "")
if [ -n "$CHANGED_FILES" ]; then
echo "Linting the following files:"
echo "$CHANGED_FILES"
echo "$CHANGED_FILES" | xargs npx eslint
else
echo "No files to lint"
fi
7 changes: 0 additions & 7 deletions .prettierrc

This file was deleted.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ lando start

You can view the local environment at `localhost:8000/`. Updates to docs are automatically refreshed in the browser.

## Linting and Code Formatting
We use ESLint and Prettier to enforce code style. On each pull request to the repository, if any `.js`, `.jsx`, `.ts` or `.tsx` files are modified in the `/src` directory, ESLint will run against our Prettier configuration to check for code styling issues on the updated/changed files.
jazzsequence marked this conversation as resolved.
Show resolved Hide resolved

To check for linting issues locally, run:
```bash
npm run lint
```

To automatically fix linting issues across the entire `/src` directory, run:
jazzsequence marked this conversation as resolved.
Show resolved Hide resolved
```bash
npm run format
```
Be cautious when running this command, as it will automatically fix any linting issues it can.
stevector marked this conversation as resolved.
Show resolved Hide resolved

## Testing

We include several tools to test that new content doesn't break the documentation. Most of these tests are performed automatically by our continuous integration service, but pull requests created from external contributors aren't included in CI tests. If you want to manually test your branch, you can execute the following tests within the Docker container.
Expand Down
27 changes: 27 additions & 0 deletions eslint.config.js
jazzsequence marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import prettier from 'eslint-config-prettier';

const compat = new FlatCompat({
baseDirectory: process.cwd(),
recommendedConfig: js.configs.recommended,
});

export default [
{
ignores: ['node_modules/**'],
},
...compat.config({
extends: ['plugin:prettier/recommended'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
},
globals: {
MktoForms2: 'readonly',
jQuery: 'readonly',
$: 'readonly',
},
}),
prettier,
];
Loading
Loading