-
Notifications
You must be signed in to change notification settings - Fork 513
Adding lint commit and husky to root configuration #4311
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?
Adding lint commit and husky to root configuration #4311
Conversation
|
Welcome @dibyanshu-pal-kushwaha! |
|
Hey hey. please check the contribution commit guidelines. There are some examples of commit messages that are good and bad in there. We do not use fix and chore for example. |
|
cool, thanks. Please check the failed checks to see what the errors are? Can you please rebase and squash your commits down to just the ones to be merged? Probably there should be one or two commits. |
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.
Pull request overview
This PR adds automated commit message validation by integrating Husky git hooks and commitlint at the root level. The implementation aims to enforce the project's commit guidelines that require an <area>: <description> format for all commit messages.
Key Changes
- Moved Husky from frontend to root configuration with upgraded version (v4.3.8 → v9.1.7)
- Added
lint:commitscript to validate commit messages against the main branch - Created custom commitlint configuration with a
headlamp-formatrule to validate commit message structure - Set up git hooks for commit-msg validation and pre-commit linting
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Added husky to root devDependencies, created prepare and lint:commit scripts, upgraded concurrently version |
| package-lock.json | Added extensive new dependencies for eslint, prettier, lint-staged, and related tooling |
| frontend/package.json | Removed husky dependency and husky.hooks configuration, but contains critical JSON syntax errors with duplicate lint-staged configurations |
| commitlint.config.js | Created custom headlamp-format rule to validate commit message format with regex pattern |
| .husky/commit-msg | Added hook to run commitlint on commit message creation |
| .husky/pre-commit | Added hook to run lint-staged on pre-commit |
Comments suppressed due to low confidence (1)
frontend/package.json:233
- There are three duplicate lint-staged configurations in this file (lines 126-157, 163-194, and 202-233). This is redundant and will cause confusion about which configuration is actually used. Only one lint-staged configuration should be present at the top level of package.json.
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx}": [
"eslint -c package.json --fix"
],
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../app/**/*.{ts,tsx}": [
"eslint -c package.json --fix"
],
"../app/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../plugins/headlamp-plugin/{bin,lib}/**/*.{ts,tsx}": [
"eslint -c package.json --fix"
],
"../plugins/headlamp-plugin/{bin,lib}/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../plugins/examples/**/*.{ts,tsx}": [
"eslint -c package.json --fix --resolve-plugins-relative-to ."
],
"../plugins/examples/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../e2e-tests/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../e2e-tests/**/*.{ts,tsx}": [
"eslint -c package.json --fix --resolve-plugins-relative-to ."
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],"lint-staged": {
"src/**/*.{js,jsx,ts,tsx}": [
"eslint -c package.json --fix"
],
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../app/**/*.{ts,tsx}": [
"eslint -c package.json --fix"
],
"../app/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../plugins/headlamp-plugin/{bin,lib}/**/*.{ts,tsx}": [
"eslint -c package.json --fix"
],
"../plugins/headlamp-plugin/{bin,lib}/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../plugins/examples/**/*.{ts,tsx}": [
"eslint -c package.json --fix --resolve-plugins-relative-to ."
],
"../plugins/examples/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../e2e-tests/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../e2e-tests/**/*.{ts,tsx}": [
"eslint -c package.json --fix --resolve-plugins-relative-to ."
]
},
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx}": [
"eslint -c package.json --fix"
],
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../app/**/*.{ts,tsx}": [
"eslint -c package.json --fix"
],
"../app/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../plugins/headlamp-plugin/{bin,lib}/**/*.{ts,tsx}": [
"eslint -c package.json --fix"
],
"../plugins/headlamp-plugin/{bin,lib}/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../plugins/examples/**/*.{ts,tsx}": [
"eslint -c package.json --fix --resolve-plugins-relative-to ."
],
"../plugins/examples/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../e2e-tests/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --config package.json --write"
],
"../e2e-tests/**/*.{ts,tsx}": [
"eslint -c package.json --fix --resolve-plugins-relative-to ."
]
},
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
88c3e35 to
60e40bf
Compare
|
@dibyanshu-pal-kushwaha Can you please check the comments by the copilot? Comment for ones that you have addressed “I have done this”, or write if it does not make sense “this does not make sense because of these reasons…” |
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.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Can you please address the open items?
I think also “frontend: Add nnn” should be disallowed.
Please add the areas you are changing, not just frontend. For example “frontend: resourceMap: Fix performance issue with clicking on items”. This is because many changes are in backend, so it does not give enough context really.
Same with “backend: Add feature” should be disallowed.
Please add the areas you are changing, not just “backend:”. For example “backend: auth: Add new test for logging in”. This is because many changes are in backend, so it does not give enough context really.
This is because many changes are in frontend or backend, so it does not give context really.
illume
left a comment
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.
Thanks for all of that.
I resolved all those open conversations you had finished, and will look into it in more detail later.
Probably the commits could be squashed into one again.
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.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8ad3773 to
5d1d93a
Compare
illume
left a comment
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.
Thanks. I marked some more comments resolved.
Check out your commit messages… there should be a capitalized verb, and also you have a space before the : which should not be there.
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.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5955ab6 to
cfa9417
Compare
illume
left a comment
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.
Nice work.
Note in the git commits style we use the verb at the beginning should be “imperative mood” like Add. Not past tense like Added.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dibyanshu-pal-kushwaha The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| with: | ||
| node-version: '20' | ||
| - name: Install dependencies | ||
| run: npm ci |
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.
@dibyanshu-pal-kushwaha The husky install command in the workflow seems to be failing , might be perhaps because the husky dependency was removed from frontend and readjusted in the root package.json.
The test plugin workflow failure is simpler to resolve, I think, by running the update-dependencies command.
👍🏼 Hope this helps
00a216e to
7a4f3ce
Compare
frontend: tsconfig: Update tsconfig.json
5187952 to
3e6a0fa
Compare
…ration Signed-off-by: Dibyanshu Pal Kushwaha <[email protected]>
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.
Pull request overview
Copilot reviewed 8 out of 11 changed files in this pull request and generated 8 comments.
Files not reviewed (2)
- frontend/package-lock.json: Language not supported
- plugins/headlamp-plugin/template/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!description) { | ||
| return [false, 'Description must not be empty']; | ||
| } | ||
| if (description[0] !== description[0].toUpperCase()) { |
Copilot
AI
Jan 11, 2026
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.
The validation logic for the description starting with a capital letter checks description[0] !== description[0].toUpperCase() which would fail for descriptions starting with numbers or special characters. For example, "frontend: HomeButton: 123 items added" would incorrectly fail this check since '1'.toUpperCase() === '1'. Consider using a more specific check like /^[A-Z]/.test(description) to ensure the description starts with an uppercase letter.
| if (description[0] !== description[0].toUpperCase()) { | |
| if (!/^[A-Z]/.test(description)) { |
| "concurrently": "^8.2.2" | ||
| "concurrently": "^8.2.2", | ||
| "husky": "^4.3.8", | ||
| "@commitlint/cli": "^19.5.0" |
Copilot
AI
Jan 11, 2026
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.
The package.json includes @commitlint/cli but is missing @commitlint/config-conventional or a similar config package that commitlint typically depends on. While a custom configuration is defined in commitlint.config.js, having a base config package is often recommended for better maintainability. However, since this PR implements a completely custom rule, this might be intentional. Just ensure that the custom configuration covers all necessary validation rules.
| "@commitlint/cli": "^19.5.0" | |
| "@commitlint/cli": "^19.5.0", | |
| "@commitlint/config-conventional": "^19.5.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.
We have defined our custom convention that is defined in the commit guidelines of the Headlamp.That's why we dont require it.
| `Commits starting with "${area}" must follow format: ` + | ||
| `<${area}>: <sub-area>: <description>\n` + | ||
| `Example: "${area}: HomeButton: Fix navigation"`, |
Copilot
AI
Jan 11, 2026
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.
The error message for strict areas uses string concatenation that could be improved for readability. The multi-line string concatenation with + operators makes the code harder to read. Consider using template literals for cleaner formatting: `Commits starting with "${area}" must follow format: <${area}>: <sub-area>: <description>\nExample: "${area}: HomeButton: Fix navigation"`
| `Commits starting with "${area}" must follow format: ` + | |
| `<${area}>: <sub-area>: <description>\n` + | |
| `Example: "${area}: HomeButton: Fix navigation"`, | |
| `Commits starting with "${area}" must follow format: <${area}>: <sub-area>: <description>\nExample: "${area}: HomeButton: Fix navigation"`, |
| if (description[0] !== description[0].toUpperCase()) { | ||
| return [false, 'Description must start with a capitalized verb']; | ||
| } | ||
| return [true,'']; |
Copilot
AI
Jan 11, 2026
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.
There's a spacing issue in the return statement. The return statement has return [true,'']; with no space after the comma. For consistency with JavaScript formatting conventions, this should be return [true, '']; with a space after the comma.
| return [true,'']; | |
| return [true, '']; |
| npm run lint:commit | ||
| ``` | ||
|
|
||
| This command check all commit messages that exist after origin/main against our guidelines. The same check runs in our CI system for every Pull Request. |
Copilot
AI
Jan 11, 2026
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.
There's a grammatical error in the documentation. The sentence "This command check all commit messages" is missing the verb conjugation. It should be "This command checks all commit messages" with an 's' on 'checks'.
| This command check all commit messages that exist after origin/main against our guidelines. The same check runs in our CI system for every Pull Request. | |
| This command checks all commit messages that exist after origin/main against our guidelines. The same check runs in our CI system for every Pull Request. |
| - uses: actions/checkout@v2 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v2 |
Copilot
AI
Jan 11, 2026
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.
The GitHub Actions versions used in this workflow are outdated. actions/checkout@v2 and actions/setup-node@v2 are deprecated and should be updated to their latest major versions (actions/checkout@v4 and actions/setup-node@v4) to ensure continued support and access to the latest features and security updates.
| - uses: actions/checkout@v2 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v2 | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 |
| `Example: "${area}: HomeButton: Fix navigation"`, | ||
| ]; | ||
| } | ||
| const description = parts.length >= 3 ? parts[2] : parts[1]; |
Copilot
AI
Jan 11, 2026
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.
The logic that extracts the description has an issue. When there are 3 or more parts, it only takes parts[2] as the description, but commit messages could have multiple colons in the description itself (e.g., "frontend: Component: Add feature: new functionality"). In this case, only "Add feature" would be validated while "new functionality" would be ignored. Consider joining all parts after the required ones: const description = parts.length >= 3 ? parts.slice(2).join(': ') : parts[1];
| const description = parts.length >= 3 ? parts[2] : parts[1]; | |
| const description = parts.length >= 3 ? parts.slice(2).join(': ') : parts[1]; |
| 'Commit message must follow format: <area>: <description>', | ||
| ]; | ||
| } | ||
| const [area, subOrDesc, desc] = parts; |
Copilot
AI
Jan 11, 2026
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.
Unused variable desc.
| const [area, subOrDesc, desc] = parts; | |
| const [area, subOrDesc] = parts; |
Summary
This PR fixes the lack of automated commit message validation and integrates Husky for git hooks to ensure contribution guidelines are followed.
Related Issue
Fixes #4303
Changes
Steps to Test
2.Try to create any commit with wrong format (for example : git commit -m "test commit")