Skip to content
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

CI: Enable commit linting #376

Merged
merged 1 commit into from
Apr 26, 2024
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
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}
52 changes: 52 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const componentScopes = require('@unovis/shared/integrations/components')
.getComponentList()
.map(c => c.name)

module.exports = {
parserPreset: {
parserOpts: {
headerPattern: /^\s*(\w*)(?:\s\|\s(\w*))?(?:\s\|\s([\w\s|]+))?: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subscopes', 'subject'],
issuePrefixes: ['#', 'unovis/issues-only#'],
},
},
rules: {
'header-trim': [2, 'always'],
'type-enum': [2, 'always', [
'React', 'Angular', 'Vue', 'Svelte', 'Website', 'Dev', 'Shared',
'Core', 'Component', 'Container', 'Release', 'CI', 'Misc',
]],
'scope-case': [2, 'always', 'pascal-case'],
'subject-case': [2, 'always', 'sentence-case'],
'subject-empty': [2, 'never'],
'validate-scope': [1, 'always'],
},
plugins: [
{
rules: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'validate-scope': c => {
// Allow empty scopes for CI and Release types
if (!c.scope) return [['Release', 'CI'].includes(c.type), 'scope should not be empty']

// Check if scope is one of the component scopes
if (c.type === 'Component') {
return [
componentScopes.includes(c.scope),
`Component scope must be one of [${componentScopes.join(', ')}]`,
]
}

// Verify pascal-case for additional scopes
c.subscopes?.split(' | ')?.forEach(s => {
if (s.match(/[A-Z][a-zA-Z0-9]*/) === null) return [false, `${s}: all scopes must be pascal-case`]
})

return [true]
},
},
},
],
helpUrl: 'https://github.com/f5/unovis/pull/375',
}
Loading
Loading