From b0c7df414a53b6a5da970170bb66dd7ffa75ae30 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Tue, 24 Jun 2025 21:22:35 +0100 Subject: [PATCH] test(pre-commit): check JavaScript files using standardJS --- .pre-commit-config.yaml | 5 ++ commitlint.config.js | 26 +++---- release-rules.js | 20 ++--- release.config.js | 165 ++++++++++++++++++++-------------------- 4 files changed, 111 insertions(+), 105 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2cee5444..4e9a7296 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -113,3 +113,8 @@ repos: - id: check-gitlab-ci name: Check GitLab CI config with check-jsonschema args: [--verbose] + - repo: https://github.com/standard/standard + rev: v17.1.2 + hooks: + - id: standard + name: Check JavaScript files using standardJS diff --git a/commitlint.config.js b/commitlint.config.js index 10160835..fc3c51f4 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,14 +1,14 @@ module.exports = { - extends: ['@commitlint/config-conventional'], - rules: { - 'body-max-line-length': [2, 'always', 120], - 'footer-max-line-length': [2, 'always', 120], - 'header-max-length': [2, 'always', 72], - }, - ignores: [ - (commit) => commit.startsWith("chore(copier):"), - (commit) => commit.startsWith("chore(deps):"), - (commit) => commit.startsWith("ci(pre-commit.ci):"), - (commit) => commit.startsWith("[CI merge]") - ], -}; + extends: ['@commitlint/config-conventional'], + rules: { + 'body-max-line-length': [2, 'always', 120], + 'footer-max-line-length': [2, 'always', 120], + 'header-max-length': [2, 'always', 72] + }, + ignores: [ + (commit) => commit.startsWith('chore(copier):'), + (commit) => commit.startsWith('chore(deps):'), + (commit) => commit.startsWith('ci(pre-commit.ci):'), + (commit) => commit.startsWith('[CI merge]') + ] +} diff --git a/release-rules.js b/release-rules.js index c63c850d..1093d1f9 100644 --- a/release-rules.js +++ b/release-rules.js @@ -3,16 +3,16 @@ // // NOTE: Any changes here must be reflected in `CONTRIBUTING.md`. module.exports = [ - {breaking: true, release: 'major'}, + { breaking: true, release: 'major' }, // {type: 'build', release: 'patch'}, // {type: 'chore', release: 'patch'}, // {type: 'ci', release: 'patch'}, - {type: 'docs', release: 'patch'}, - {type: 'feat', release: 'minor'}, - {type: 'fix', release: 'patch'}, - {type: 'perf', release: 'patch'}, - {type: 'refactor', release: 'patch'}, - {type: 'revert', release: 'patch'}, - {type: 'style', release: 'patch'}, - {type: 'test', release: 'patch'}, -]; + { type: 'docs', release: 'patch' }, + { type: 'feat', release: 'minor' }, + { type: 'fix', release: 'patch' }, + { type: 'perf', release: 'patch' }, + { type: 'refactor', release: 'patch' }, + { type: 'revert', release: 'patch' }, + { type: 'style', release: 'patch' }, + { type: 'test', release: 'patch' } +] diff --git a/release.config.js b/release.config.js index 708d1722..15fa1203 100644 --- a/release.config.js +++ b/release.config.js @@ -2,22 +2,23 @@ module.exports = { branch: 'master', repositoryUrl: 'https://github.com/saltstack-formulas/template-formula', plugins: [ - ['@semantic-release/commit-analyzer', { - preset: 'angular', - releaseRules: './release-rules.js', - }], - '@semantic-release/release-notes-generator', - ['@semantic-release/changelog', { - changelogFile: 'CHANGELOG.md', - changelogTitle: '# Changelog', - }], - ['@semantic-release/exec', { - prepareCmd: 'sh ./pre-commit_semantic-release.sh ${nextRelease.version}', - }], - ['@semantic-release/git', { - assets: ['*.md', 'docs/*.rst', 'FORMULA'], - }], - '@semantic-release/github', + ['@semantic-release/commit-analyzer', { + preset: 'angular', + releaseRules: './release-rules.js' + }], + '@semantic-release/release-notes-generator', + ['@semantic-release/changelog', { + changelogFile: 'CHANGELOG.md', + changelogTitle: '# Changelog' + }], + ['@semantic-release/exec', { + // eslint-disable-next-line no-template-curly-in-string + prepareCmd: 'sh ./pre-commit_semantic-release.sh ${nextRelease.version}' + }], + ['@semantic-release/git', { + assets: ['*.md', 'docs/*.rst', 'FORMULA'] + }], + '@semantic-release/github' ], generateNotes: { preset: 'angular', @@ -26,82 +27,82 @@ module.exports = { // Bug: https://github.com/conventional-changelog/conventional-changelog/issues/317 // Fix: https://github.com/conventional-changelog/conventional-changelog/pull/410 transform: (commit, context) => { - const issues = [] + const issues = [] - commit.notes.forEach(note => { - note.title = `BREAKING CHANGES` - }) + commit.notes.forEach(note => { + note.title = 'BREAKING CHANGES' + }) - // NOTE: Any changes here must be reflected in `CONTRIBUTING.md`. - if (commit.type === `feat`) { - commit.type = `Features` - } else if (commit.type === `fix`) { - commit.type = `Bug Fixes` - } else if (commit.type === `perf`) { - commit.type = `Performance Improvements` - } else if (commit.type === `revert`) { - commit.type = `Reverts` - } else if (commit.type === `docs`) { - commit.type = `Documentation` - } else if (commit.type === `style`) { - commit.type = `Styles` - } else if (commit.type === `refactor`) { - commit.type = `Code Refactoring` - } else if (commit.type === `test`) { - commit.type = `Tests` - } else if (commit.type === `build`) { - commit.type = `Build System` + // NOTE: Any changes here must be reflected in `CONTRIBUTING.md`. + if (commit.type === 'feat') { + commit.type = 'Features' + } else if (commit.type === 'fix') { + commit.type = 'Bug Fixes' + } else if (commit.type === 'perf') { + commit.type = 'Performance Improvements' + } else if (commit.type === 'revert') { + commit.type = 'Reverts' + } else if (commit.type === 'docs') { + commit.type = 'Documentation' + } else if (commit.type === 'style') { + commit.type = 'Styles' + } else if (commit.type === 'refactor') { + commit.type = 'Code Refactoring' + } else if (commit.type === 'test') { + commit.type = 'Tests' + } else if (commit.type === 'build') { + commit.type = 'Build System' // } else if (commit.type === `chore`) { // commit.type = `Maintenance` - } else if (commit.type === `ci`) { - commit.type = `Continuous Integration` - } else { - return - } + } else if (commit.type === 'ci') { + commit.type = 'Continuous Integration' + } else { + return + } - if (commit.scope === `*`) { - commit.scope = `` - } + if (commit.scope === '*') { + commit.scope = '' + } - if (typeof commit.hash === `string`) { - commit.shortHash = commit.hash.substring(0, 7) - } + if (typeof commit.hash === 'string') { + commit.shortHash = commit.hash.substring(0, 7) + } - if (typeof commit.subject === `string`) { - let url = context.repository - ? `${context.host}/${context.owner}/${context.repository}` - : context.repoUrl - if (url) { - url = `${url}/issues/` - // Issue URLs. - commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => { - issues.push(issue) - return `[#${issue}](${url}${issue})` - }) + if (typeof commit.subject === 'string') { + let url = context.repository + ? `${context.host}/${context.owner}/${context.repository}` + : context.repoUrl + if (url) { + url = `${url}/issues/` + // Issue URLs. + commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => { + issues.push(issue) + return `[#${issue}](${url}${issue})` + }) + } + if (context.host) { + // User URLs. + commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => { + if (username.includes('/')) { + return `@${username}` } - if (context.host) { - // User URLs. - commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => { - if (username.includes('/')) { - return `@${username}` - } - return `[@${username}](${context.host}/${username})` - }) - } + return `[@${username}](${context.host}/${username})` + }) } + } - // remove references that already appear in the subject - commit.references = commit.references.filter(reference => { - if (issues.indexOf(reference.issue) === -1) { - return true - } + // remove references that already appear in the subject + commit.references = commit.references.filter(reference => { + if (issues.indexOf(reference.issue) === -1) { + return true + } - return false - }) + return false + }) - return commit - }, - }, - }, -}; + return commit + } + } + } +}