Skip to content

ci: only format and lint changed files #301

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scripts/*
.eslintignore
.prettierignore
.github/workflows/*
*.md
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
'plugin:svelte/recommended',
'prettier',
],
plugins: ['svelte', 'simple-import-sort'],
plugins: ['svelte', 'simple-import-sort', 'json-files'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without any rules and an overrides section mentioning .json, I don't think adding this plugin does anything

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does! Because in this case the list of files is passed explicitly to eslint (versus being generated off the include and exclude lists).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, we're not configuring any rules. Is this just here so a JSON parser is used and ESLint doesn't choke when a JSON file comes in the diff list? Would adding JSON to the ESLint ignore achieve the same thing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add json files to the ignore list, but if I can get eslint to check them instead, hey, why not?

rules: {
'simple-import-sort/imports': 'error',
},
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ jobs:
svelte: ['3', '4']
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout main branch of repo
uses: actions/checkout@v4
with:
ref: main

- name: ⬇️ Checkout repo
uses: actions/checkout@v4

Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scripts/*
.eslintignore
.prettierignore
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ The module is released automatically from the `main` branch using [semantic-rele

## Development setup

After cloning the repository, use the `setup` script to install development dependencies and the `validate` script to run all checks and tests to verify your setup.
After cloning the repository, install the project's dependencies and run the `validate` script to run all checks and tests to verify your setup.

```shell
npm run setup
npm install # or `pnpm install`, or `yarn install`, etc.
npm run validate
```

Expand All @@ -27,13 +27,13 @@ npm run validate
Run auto-formatting to ensure any changes adhere to the code style of the repository:

```shell
npm run format
npm run format:delta
```

To run lint and format checks without making any changes:

```shell
npm run lint
npm run lint:delta
```

### Test
Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@
],
"scripts": {
"toc": "doctoc README.md",
"lint": "(prettier . --check || true) && eslint .",
"lint": "prettier . --check && eslint .",
"lint:delta": "npm-run-all -p prettier:delta eslint:delta",
"prettier:delta": "prettier --check `./scripts/changed-files`",
"eslint:delta": "eslint `./scripts/changed-files`",
"format": "prettier . --write && eslint . --fix",
"format:delta": "npm-run-all format:prettier:delta format:eslint:delta",
"format:prettier:delta": "prettier --write `./scripts/changed-files`",
"format:eslint:delta": "eslint --fix `./scripts/changed-files`",
Copy link
Collaborator

@mcous mcous Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • POSIX recommends $(...) over backticks for shell command substitution, IIRC
  • I don't know if this is Windows friendly
  • Currently, if the bash script fails, the npm script will still run, causing the failure of the script to be swallowed in CI
Screenshot 2024-01-30 at 05 30 25

"test": "vitest run --coverage",
"test:watch": "vitest",
"test:update": "vitest run --update",
"setup": "npm install && npm run validate",
"validate": "npm-run-all lint test",
"validate": "npm-run-all lint:delta test",
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate"
},
Expand All @@ -72,6 +78,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-json-files": "^4.1.0",
"eslint-plugin-n": "^16.0.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
Expand Down
3 changes: 3 additions & 0 deletions scripts/changed-files
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't feel very Windows friendly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It ain't. Are you developing under Windows?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Occasionally! I try to keep things shell/os-agnostic in my own projects. I dislike the idea of having a barrier to contributing based on OS when I could structure things to be more compatible

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I try to be as friendly as possible, but something I've learn along the years is that there is a limit on how much out of shape one should bend for the remote possibility that somebody with a specific setup might potentially want to contribute. My rule of thumb is: optimize for the comfort of who are working right now on the thing, and don't actively be a jerk for the rest.


git diff --name-only --diff-filter=d origin/main