Skip to content

chore: lint-staged tooling to simplify pre-commit workflows #5393

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

castastrophe
Copy link
Collaborator

@castastrophe castastrophe commented Apr 23, 2025

Description

Swap out pretty-quick and manual linting calls in favor of the lint-staged tool which lets us define commands to run only when certain files are edited. These actions are only performed on files edited in a pull request or in git history to prevent leaking unrelated changes into pull requests which could expand scope of existing work.

Related issue(s)

  • SWC-855

How has this been tested?

  • yarn build
    • Expect yarn lint to run after the spectrum CSS assets are built; should run stylelint and prettier

For the below commands, we are editing committed assets and then running yarn lint to verify the correct commands are triggered. Assets do not need to be staged when running the yarn lint alias however, you can also verify running yarn lint-staged directly and expect the same results (as long as the files are staged first).

  • Update the packages/action-button/src/action-button.css to remove whitespace around the first selector and properties (i.e., ::slotted([slot='icon']) { flex-shrink: 0; })
    • Expect running yarn lint to run the stylelint and prettier commands
    • This should return the whitespace and indents to the selector
  • Update the packages/action-button/src/ActionButton.ts to reorder the imports
    • Expect running yarn lint to run the eslint command
    • This should return the import order
  • Update the packages/action-button/package.json to remove homepage and author
    • Expect running yarn lint to run the genversion and constraints commands
    • These commands should add back the homepage and author values

Types of changes

  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Checklist

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • If my change required a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices

Best practices

This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against main.

Copy link

changeset-bot bot commented Apr 23, 2025

⚠️ No Changeset found

Latest commit: abe0543

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

yarn genversion --es6 --semi $VERSION_FILE
git add $VERSION_FILE
EOF
yarn lint-staged --allow-empty
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Much less complexity! 🥳

Copy link

Branch preview

Review the following VRT differences

When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:

If the changes are expected, update the current_golden_images_cache hash in the circleci config to accept the new images. Instructions are included in that file.
If the changes are unexpected, you can investigate the cause of the differences and update the code accordingly.

Copy link

Tachometer results

Currently, no packages are changed by this PR...

.prettierrc.yaml Outdated
@@ -7,6 +7,6 @@ bracketSpacing: true
arrowParens: always
htmlWhitespaceSensitivity: ignore
overrides:
- files: '{tools,packages}/*/src/spectrum-*.css'
- files: '{tools,packages}/*/src/*.css'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All CSS assets benefit from this expanded line-length in order to prevent var function wraps that could block proper downstream minification efforts.

@@ -91,11 +91,10 @@ The `:nonbreaking` variant lets us release patch updates quickly in cases where

There are several commands that can be useful in specific scenarios:

- `yarn build:clear-cache` to remove previously created artifacts of the `tsc build` process.
- `yarn spectrum-vars` to ensure that theme files are up-to-date.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This command is no longer called directly so I removed it from the docs. All other updates are whitespace fixes from prettier.

governing permissions and limitations under the License.
*/

export default {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This mimics our existing linting rules

package.json Outdated
"lint:js": "pretty-quick --pattern \"tasks/**/*.js\" && pretty-quick --pattern \"scripts/**/*.js\"",
"lint:packagejson": "pretty-quick --pattern package.json --pattern \"packages/*/package.json\" --pattern \"projects/*/package.json\" --pattern \"tools/*/package.json\" --pattern \"react/*/package.json\"",
"lint:ts": "pretty-quick --pattern \"packages/**/*.ts\" && eslint -f pretty \"packages/**/*.ts\" && pretty-quick --pattern \"tools/**/*.ts\" && eslint -f pretty \"tools/**/*.ts\"",
"lint": "git status --porcelain && git add . && yarn lint-staged",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This git status command checks first if there are uncommitted assets and adds them before linting.

@@ -90,7 +84,7 @@
"test:watch:flags:focus": "yarn build && run-p build:watch \"test:start --watch --group {1} --config web-test-runner.config.ci-chromium-flags.js\" --",
"test:watch:focus": "yarn build && run-p build:watch \"test:start --watch --group {1}\" --",
"update:spectrum-css": "node ./scripts/update-spectrum-css.js --latest || yarn update:spectrum-css:cleanup",
"update:spectrum-css:cleanup": "yarn lint:packagejson && yarn --ignore-scripts && yarn process-spectrum",
"update:spectrum-css:cleanup": "yarn --ignore-scripts && yarn process-spectrum && yarn lint",
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 moved this order around because you can't run the linter until you've installed with yarn first anyway.

Copy link
Contributor

@Rajdeepc Rajdeepc May 6, 2025

Choose a reason for hiding this comment

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

nit: I don't think we need this script anymore for cut-off?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True but since we haven't merged the cutoff work yet, this PR was built to merge either before or after. If after, I'd just rebase the branch and update this bit.

@@ -217,7 +217,6 @@ jobs:
- run:
name: Lint
command: yarn lint
- run: yarn analyze
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This runs as part of the lint task if the appropriate files are edited

@castastrophe castastrophe force-pushed the castastrophe/chore-lint-staged-tooling branch 5 times, most recently from d45da11 to 4e4d4a0 Compare May 1, 2025 15:57
@castastrophe castastrophe force-pushed the castastrophe/chore-lint-staged-tooling branch 3 times, most recently from 919df82 to 2593a58 Compare May 5, 2025 18:36
@@ -90,7 +84,7 @@
"test:watch:flags:focus": "yarn build && run-p build:watch \"test:start --watch --group {1} --config web-test-runner.config.ci-chromium-flags.js\" --",
"test:watch:focus": "yarn build && run-p build:watch \"test:start --watch --group {1}\" --",
"update:spectrum-css": "node ./scripts/update-spectrum-css.js --latest || yarn update:spectrum-css:cleanup",
"update:spectrum-css:cleanup": "yarn lint:packagejson && yarn --ignore-scripts && yarn process-spectrum",
"update:spectrum-css:cleanup": "yarn --ignore-scripts && yarn process-spectrum && yarn lint",
Copy link
Contributor

@Rajdeepc Rajdeepc May 6, 2025

Choose a reason for hiding this comment

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

nit: I don't think we need this script anymore for cut-off?

@@ -386,7 +380,7 @@
]
},
"process-spectrum": {
"command": "node ./scripts/spectrum-vars.js && node ./tasks/process-spectrum.js && node ./scripts/generate-tokens.js && yarn format:css",
"command": "node ./scripts/spectrum-vars.js && node ./tasks/process-spectrum.js && node ./scripts/generate-tokens.js && yarn lint",
Copy link
Contributor

@Rajdeepc Rajdeepc May 6, 2025

Choose a reason for hiding this comment

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

nit: Maybe comment out this also?

@castastrophe castastrophe force-pushed the castastrophe/chore-lint-staged-tooling branch 3 times, most recently from 116824d to e16703a Compare May 6, 2025 13:22
@castastrophe castastrophe marked this pull request as ready for review May 6, 2025 13:24
@castastrophe castastrophe requested a review from a team as a code owner May 6, 2025 13:24
@castastrophe castastrophe self-assigned this May 6, 2025
@castastrophe castastrophe force-pushed the castastrophe/chore-lint-staged-tooling branch 7 times, most recently from 38ec2eb to 66f6f45 Compare May 6, 2025 15:05
@castastrophe castastrophe force-pushed the castastrophe/chore-lint-staged-tooling branch from 66f6f45 to abe0543 Compare May 6, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants