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

Merged
merged 3 commits into from
May 9, 2025
Merged
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
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

- run:
name: Are there changes?
command: git diff-files --exit-code
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ tools/**/*.test-vrt.ts
!tools/base/src/version.js
!tools/base/src/version.d.ts


# cache directories
.wireit
.eslintcache
.stylelintcache

stats.html

Expand Down Expand Up @@ -111,4 +113,4 @@ chromatic.config.json
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versio;/
!.yarn/version
17 changes: 1 addition & 16 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
#!/usr/bin/env bash
bash << EOF
STAGED_FILES_TO_LINT=$(git diff --name-only --cached --diff-filter=d -- "*.ts" "*.js")
STAGED_FILES_TO_ANALYZE=$(git diff --name-only --cached --diff-filter=d -- "{packages,tools}/*/src/**/!(*.css).ts")
STAGED_CSS_FILES=$(git diff --name-only --cached --diff-filter=d -- "{packages,tools}/**/*.css")
VERSION_FILE=$(dirname "$0")/../tools/base/src/version.js

[ -z "$STAGED_FILES_TO_LINT" ] || yarn eslint -f pretty $STAGED_FILES_TO_LINT
[ -z "$STAGED_FILES_TO_ANALYZE" ] || yarn lit-analyzer $STAGED_FILES_TO_ANALYZE
[ -z "$STAGED_CSS_FILES" ] || yarn stylelint $STAGED_CSS_FILES

yarn pretty-quick --staged

yarn genversion --es6 --semi $VERSION_FILE
git add $VERSION_FILE
EOF
yarn lint-staged --allow-empty
69 changes: 34 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ To this end, Spectrum Web Components only targets _modern_, evergreen browsers t

# Requirements

- NodeJS >= 20.0.0
- Typescript
- Supported desktop browsers:
- Last 2 versions of Chrome
- Last 2 versions of Firefox
- Last 2 versions of Safari
- Last 2 versions of Edge
- Or appropriate [polyfills](https://github.com/webcomponents/webcomponentsjs) in older browsers.
- We support all viewport sizes across supported desktop browsers.
- While our components are designed to be responsive and mobile-friendly, we do not yet fully support mobile browsers due to limited testing in mobile hardware. We advise testing updates on mobile devices before updating and are happy to address any reported issues.
- NodeJS >= 20.0.0
- Typescript
- Supported desktop browsers:
- Last 2 versions of Chrome
- Last 2 versions of Firefox
- Last 2 versions of Safari
- Last 2 versions of Edge
- Or appropriate [polyfills](https://github.com/webcomponents/webcomponentsjs) in older browsers.
- We support all viewport sizes across supported desktop browsers.
- While our components are designed to be responsive and mobile-friendly, we do not yet fully support mobile browsers due to limited testing in mobile hardware. We advise testing updates on mobile devices before updating and are happy to address any reported issues.

# Getting started

Expand All @@ -34,7 +34,7 @@ Typical development will involve running `yarn storybook`, `yarn test`, and `yar
Creating a new component from the command line can be done by running the following:

```bash
$ yarn new-package
yarn new-package
```

This will scaffold your component's required architecture by prompting you for 2 data points - the desired name for your package and the name of the Spectrum CSS asset from which you will be building.
Expand Down Expand Up @@ -81,8 +81,8 @@ yarn docs:build

There are two mechanisms for broadly updating SWC's Spectrum CSS dependencies:

- `yarn update:spectrum-css` brings all Spectrum CSS dependencies to 'latest'
- `yarn update:spectrum-css:nonbreaking` brings them to the latest minor or patch version
- `yarn update:spectrum-css` brings all Spectrum CSS dependencies to 'latest'
- `yarn update:spectrum-css:nonbreaking` brings them to the latest minor or patch version

We aim to keep Spectrum CSS as current as possible, to track the Spectrum design system closely.
The `:nonbreaking` variant lets us release patch updates quickly in cases where more work is required to be compatible with 'latest.'
Expand All @@ -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.

- `yarn process-icons` to make sure that the most recent icons are included.
- `yarn process-spectrum` to process the spectrum CSS style sources into the individual packages.
- `yarn build` to make sure the available JS has been built from the current TS source.
- `yarn build:clear-cache` to remove previously created artifacts of the `tsc build` process.
- `yarn process-icons` to make sure that the most recent icons are included.
- `yarn process-spectrum` to process the spectrum CSS style sources into the individual packages.
- `yarn build` to make sure the available JS has been built from the current TS source.

## Linting

Expand Down Expand Up @@ -179,23 +178,23 @@ This will run the defined [Tachometer](https://www.npmjs.com/package/tachometer)

There is extended documentation on adding a new component to the library in the [documentation site](https://opensource.adobe.com/spectrum-web-components/guides/generating-components). However, at a high level, you will be building the following structure:

- packages
- new-component-name
- src
- index.ts
- new-component-name.css
- new-component-name.ts
- spectrum-config.js
- spectrum-new-component-name.css
- stories
- new-component-name.stories.ts
- test
- benchmark
- test-basic.ts
- new-component-name.test.ts
- package.json
- README.md
- tsconfig.json
- packages
- new-component-name
- src
- index.ts
- new-component-name.css
- new-component-name.ts
- spectrum-config.js
- spectrum-new-component-name.css
- stories
- new-component-name.stories.ts
- test
- benchmark
- test-basic.ts
- new-component-name.test.ts
- package.json
- README.md
- tsconfig.json

For a list of component waiting to be implemented, visit our [`missing components`](https://github.com/adobe/spectrum-web-components/labels/missing%20components) tag.

Expand Down
32 changes: 32 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2025 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
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

'*.css': [
'stylelint --fix --cache --allow-empty-input',
'prettier --cache --no-error-on-unmatched-pattern --ignore-unknown --log-level silent --write',
],
'*.ts': [
'eslint --fix --format pretty --cache --no-error-on-unmatched-pattern --quiet',
'prettier --cache --no-error-on-unmatched-pattern --ignore-unknown --log-level silent --write',
],
'{packages,tools}/*/src/**/!(*.css).ts': ['yarn lit-analyzer'],
'package.json': () => [
'genversion --es6 --semi tools/base/src/version.js',
'yarn constraints --fix',
'yarn install --refresh-lockfile',
'git add tools/base/src/version.js yarn.lock',
],
'!(*.css|*.ts)': [
'prettier --cache --no-error-on-unmatched-pattern --ignore-unknown --log-level silent --write',
],
};
18 changes: 6 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,11 @@
"docs:review": "alex packages/**/*.md",
"docs:start": "yarn workspace documentation serve --watch",
"find": "test -f custom-elements.json",
"format:css": "yarn lint:css --fix && pretty-quick --pattern \"{packages,tools}/**/*.css\"",
"gen-react-wrapper": "node ./tasks/gen-react-wrapper.js",
"icons": "wireit",
"icons:ui": "wireit",
"icons:workflow": "wireit",
"lint": "run-p lint:js lint:docs lint:ts lint:css lint:packagejson",
"lint:css": "stylelint \"packages/**/*.css\" \"tools/**/*.css\"",
"lint:docs": "eslint -f pretty \"projects/documentation/**/*.ts\"",
"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 . && lint-staged --allow-empty",
"lint:versions": "node ./scripts/lint-versions.js",
"new-package": "cd projects/templates && plop",
"postcustom-element-json": "node ./tasks/run-check-cem.js",
Expand Down Expand Up @@ -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.

"update:spectrum-css:nonbreaking": "node ./scripts/update-spectrum-css.js || yarn update:spectrum-css:cleanup",
"verify-build-artifacts": "node ./scripts/verify-build-artifacts.js",
"vrt:preview": "yarn wds --config test/visual/wds-vrt.config.js",
Expand Down Expand Up @@ -175,6 +169,7 @@
"husky": "^9.0.10",
"latest-version": "^9.0.0",
"lightningcss": "1.19.0",
"lint-staged": "^15.5.1",
"lit": "^2.5.0 || ^3.1.3",
"lit-analyzer": "^2.0.3",
"lit-html": "^2.4.0 || ^3.1.3",
Expand All @@ -185,10 +180,9 @@
"npm-run-all2": "^8.0.1",
"patch-package": "^8.0.0",
"pinst": "^3.0.0",
"prettier": "^3.0.0",
"prettier": "^3.5.3",
"prettier-plugin-package": "^1.3.0",
"pretty-bytes": "^6.1.1",
"pretty-quick": "^4.1.1",
"re-template-tag": "^2.0.1",
"rimraf": "^5.0.1",
"rollup": "^4.12.0",
Expand Down Expand Up @@ -321,7 +315,7 @@
]
},
"icons": {
"command": "node ./scripts/process-icons.js && pretty-quick --pattern \"packages/**/*.svg.ts\" && eslint -f pretty --fix \"packages/**/*.svg.ts\"",
"command": "node ./scripts/process-icons.js && yarn lint",
"files": [
"scripts/process-icons.js"
],
Expand Down Expand Up @@ -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?

"files": [
"tasks/process-spectrum.js",
"packages/**/spectrum-config.js",
Expand Down
15 changes: 14 additions & 1 deletion packages/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@
"es6": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "notice", "@spectrum-web-components"],
"plugins": [
"@typescript-eslint",
"notice",
"@spectrum-web-components",
"import"
],
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:lit-a11y/recommended"
],
"rules": {
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": false,
"optionalDependencies": false,
"peerDependencies": false
}
],
"no-debugger": 2,
"no-console": [
"error",
Expand Down
Loading
Loading