-
Notifications
You must be signed in to change notification settings - Fork 221
tooling: update pre-commit hook to stop failure propagation of no-import rule of missing dependencies #5430
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
base: main
Are you sure you want to change the base?
Changes from all commits
bfb90e5
e9f8531
c2a4e4a
9e4d9f0
e6264c1
038564f
109fb02
7757a68
0e15bbc
5902583
f32711d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@spectrum-web-components/icon': minor | ||
--- | ||
|
||
fix: added missing reactive controller dependency for IconBase which was importing SystemContextResolution for context switching | ||
Moved all linting, formatting, and static analysis logic (ESLint, Stylelint, Prettier, Lit Analyzer) into a centralized lint-staged configuration. Simplifies the pre-commit hook by delegating to `yarn lint-staged`, improving maintainability and consistency across contributors. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,4 @@ | ||
#!/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 | ||
#!/bin/bash | ||
set -e | ||
echo "Running pre-commit hook via lint-staged..." | ||
yarn lint-staged --allow-empty |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,46 @@ | ||||||||||||||||||
/* eslint-disable no-console */ | ||||||||||||||||||
/* | ||||||||||||||||||
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. | ||||||||||||||||||
*/ | ||||||||||||||||||
import { execSync } from 'child_process'; | ||||||||||||||||||
|
||||||||||||||||||
export default { | ||||||||||||||||||
// Runs ESLint with fix on all staged JS/TS files | ||||||||||||||||||
'*.{js,ts}': (files) => { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So lint-staged is great because it actually shows you the files it's running against so you don't need to echo the file list. It also enables parallelization so unless the command requires it, you don't have to pass the files in manually. For example:
|
||||||||||||||||||
console.log('Running ESLint on:', files.join(' ')); | ||||||||||||||||||
return [`eslint --fix ${files.join(' ')}`]; | ||||||||||||||||||
}, | ||||||||||||||||||
|
||||||||||||||||||
// Runs lit-analyzer only on relevant .ts files inside src (excluding .css) | ||||||||||||||||||
'{packages,tools}/*/src/**/!(*.css).ts': (files) => { | ||||||||||||||||||
console.log('Running lit-analyzer on:', files.join(' ')); | ||||||||||||||||||
return [`lit-analyzer ${files.join(' ')}`]; | ||||||||||||||||||
}, | ||||||||||||||||||
|
||||||||||||||||||
// Runs stylelint with fix on all staged CSS files | ||||||||||||||||||
'{packages,tools}/**/*.css': (files) => { | ||||||||||||||||||
console.log('Running stylelint on:', files.join(' ')); | ||||||||||||||||||
return [`stylelint --fix ${files.join(' ')}`]; | ||||||||||||||||||
}, | ||||||||||||||||||
Comment on lines
+29
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Since stylelint has rules about which css files it will run against, we can pass any css file from the list and it will only run if it matches the rules. This lets us manage the CSS rules from the stylelint config instead of having to replicate it here too. |
||||||||||||||||||
|
||||||||||||||||||
// Formats selected staged files with Prettier | ||||||||||||||||||
'!(*.css|*.ts)': [ | ||||||||||||||||||
'prettier --cache --no-error-on-unmatched-pattern --ignore-unknown --log-level silent --write', | ||||||||||||||||||
], | ||||||||||||||||||
|
||||||||||||||||||
// Generates and add version file | ||||||||||||||||||
// This will always re-run and stage version.js | ||||||||||||||||||
'tools/base/src/version.js': () => { | ||||||||||||||||||
console.log('Generating version file...'); | ||||||||||||||||||
execSync('yarn genversion --es6 --semi tools/base/src/version.js'); | ||||||||||||||||||
return 'git add tools/base/src/version.js'; | ||||||||||||||||||
Comment on lines
+41
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This approach will still run them in parallel but it avoids using the exec function which is really problematic in scripts due to it's inconsistent way of returning warnings and information from the console. |
||||||||||||||||||
}, | ||||||||||||||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
"icons": "wireit", | ||
"icons:ui": "wireit", | ||
"icons:workflow": "wireit", | ||
"lint-staged": "lint-staged", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we benefit from this abstraction, can we look at just using the migration work I already put together? |
||
"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\"", | ||
|
@@ -175,6 +176,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", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} | ||
], | ||
Comment on lines
+21
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a import dependency rule to check for missing direct dependencies. |
||
"no-debugger": 2, | ||
"no-console": [ | ||
"error", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,8 @@ | |
], | ||
"dependencies": { | ||
"@spectrum-web-components/base": "1.6.0", | ||
"@spectrum-web-components/iconset": "1.6.0" | ||
"@spectrum-web-components/iconset": "1.6.0", | ||
"@spectrum-web-components/reactive-controllers": "1.6.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch here |
||
}, | ||
"devDependencies": { | ||
"@spectrum-css/icon": "9.1.0" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I've noticed this issue as well, however here's the documentation around why we added the bash wrapper: https://typicode.github.io/husky/how-to.html#bash
We're not currently supporting Windows so it seemed a fine compromise. The if syntax however is Bash syntax so removing that would be a potential issue. What do you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking we could migrate all these rules into a lint-staged config and just run the
yarn lint-staged
command here instead of all this logic. What are your thoughts? Was playing around with that here: #5393There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of migrate these in a module in a lint-staged config. More scalable. Let me update this here and test. Please feel free to add your thoughts too!