Skip to content

Commit b0c7df4

Browse files
committed
test(pre-commit): check JavaScript files using standardJS
1 parent 1e5cc9e commit b0c7df4

File tree

4 files changed

+111
-105
lines changed

4 files changed

+111
-105
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,8 @@ repos:
113113
- id: check-gitlab-ci
114114
name: Check GitLab CI config with check-jsonschema
115115
args: [--verbose]
116+
- repo: https://github.com/standard/standard
117+
rev: v17.1.2
118+
hooks:
119+
- id: standard
120+
name: Check JavaScript files using standardJS

commitlint.config.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = {
2-
extends: ['@commitlint/config-conventional'],
3-
rules: {
4-
'body-max-line-length': [2, 'always', 120],
5-
'footer-max-line-length': [2, 'always', 120],
6-
'header-max-length': [2, 'always', 72],
7-
},
8-
ignores: [
9-
(commit) => commit.startsWith("chore(copier):"),
10-
(commit) => commit.startsWith("chore(deps):"),
11-
(commit) => commit.startsWith("ci(pre-commit.ci):"),
12-
(commit) => commit.startsWith("[CI merge]")
13-
],
14-
};
2+
extends: ['@commitlint/config-conventional'],
3+
rules: {
4+
'body-max-line-length': [2, 'always', 120],
5+
'footer-max-line-length': [2, 'always', 120],
6+
'header-max-length': [2, 'always', 72]
7+
},
8+
ignores: [
9+
(commit) => commit.startsWith('chore(copier):'),
10+
(commit) => commit.startsWith('chore(deps):'),
11+
(commit) => commit.startsWith('ci(pre-commit.ci):'),
12+
(commit) => commit.startsWith('[CI merge]')
13+
]
14+
}

release-rules.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
//
44
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
55
module.exports = [
6-
{breaking: true, release: 'major'},
6+
{ breaking: true, release: 'major' },
77
// {type: 'build', release: 'patch'},
88
// {type: 'chore', release: 'patch'},
99
// {type: 'ci', release: 'patch'},
10-
{type: 'docs', release: 'patch'},
11-
{type: 'feat', release: 'minor'},
12-
{type: 'fix', release: 'patch'},
13-
{type: 'perf', release: 'patch'},
14-
{type: 'refactor', release: 'patch'},
15-
{type: 'revert', release: 'patch'},
16-
{type: 'style', release: 'patch'},
17-
{type: 'test', release: 'patch'},
18-
];
10+
{ type: 'docs', release: 'patch' },
11+
{ type: 'feat', release: 'minor' },
12+
{ type: 'fix', release: 'patch' },
13+
{ type: 'perf', release: 'patch' },
14+
{ type: 'refactor', release: 'patch' },
15+
{ type: 'revert', release: 'patch' },
16+
{ type: 'style', release: 'patch' },
17+
{ type: 'test', release: 'patch' }
18+
]

release.config.js

Lines changed: 83 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ module.exports = {
22
branch: 'master',
33
repositoryUrl: 'https://github.com/saltstack-formulas/template-formula',
44
plugins: [
5-
['@semantic-release/commit-analyzer', {
6-
preset: 'angular',
7-
releaseRules: './release-rules.js',
8-
}],
9-
'@semantic-release/release-notes-generator',
10-
['@semantic-release/changelog', {
11-
changelogFile: 'CHANGELOG.md',
12-
changelogTitle: '# Changelog',
13-
}],
14-
['@semantic-release/exec', {
15-
prepareCmd: 'sh ./pre-commit_semantic-release.sh ${nextRelease.version}',
16-
}],
17-
['@semantic-release/git', {
18-
assets: ['*.md', 'docs/*.rst', 'FORMULA'],
19-
}],
20-
'@semantic-release/github',
5+
['@semantic-release/commit-analyzer', {
6+
preset: 'angular',
7+
releaseRules: './release-rules.js'
8+
}],
9+
'@semantic-release/release-notes-generator',
10+
['@semantic-release/changelog', {
11+
changelogFile: 'CHANGELOG.md',
12+
changelogTitle: '# Changelog'
13+
}],
14+
['@semantic-release/exec', {
15+
// eslint-disable-next-line no-template-curly-in-string
16+
prepareCmd: 'sh ./pre-commit_semantic-release.sh ${nextRelease.version}'
17+
}],
18+
['@semantic-release/git', {
19+
assets: ['*.md', 'docs/*.rst', 'FORMULA']
20+
}],
21+
'@semantic-release/github'
2122
],
2223
generateNotes: {
2324
preset: 'angular',
@@ -26,82 +27,82 @@ module.exports = {
2627
// Bug: https://github.com/conventional-changelog/conventional-changelog/issues/317
2728
// Fix: https://github.com/conventional-changelog/conventional-changelog/pull/410
2829
transform: (commit, context) => {
29-
const issues = []
30+
const issues = []
3031

31-
commit.notes.forEach(note => {
32-
note.title = `BREAKING CHANGES`
33-
})
32+
commit.notes.forEach(note => {
33+
note.title = 'BREAKING CHANGES'
34+
})
3435

35-
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
36-
if (commit.type === `feat`) {
37-
commit.type = `Features`
38-
} else if (commit.type === `fix`) {
39-
commit.type = `Bug Fixes`
40-
} else if (commit.type === `perf`) {
41-
commit.type = `Performance Improvements`
42-
} else if (commit.type === `revert`) {
43-
commit.type = `Reverts`
44-
} else if (commit.type === `docs`) {
45-
commit.type = `Documentation`
46-
} else if (commit.type === `style`) {
47-
commit.type = `Styles`
48-
} else if (commit.type === `refactor`) {
49-
commit.type = `Code Refactoring`
50-
} else if (commit.type === `test`) {
51-
commit.type = `Tests`
52-
} else if (commit.type === `build`) {
53-
commit.type = `Build System`
36+
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
37+
if (commit.type === 'feat') {
38+
commit.type = 'Features'
39+
} else if (commit.type === 'fix') {
40+
commit.type = 'Bug Fixes'
41+
} else if (commit.type === 'perf') {
42+
commit.type = 'Performance Improvements'
43+
} else if (commit.type === 'revert') {
44+
commit.type = 'Reverts'
45+
} else if (commit.type === 'docs') {
46+
commit.type = 'Documentation'
47+
} else if (commit.type === 'style') {
48+
commit.type = 'Styles'
49+
} else if (commit.type === 'refactor') {
50+
commit.type = 'Code Refactoring'
51+
} else if (commit.type === 'test') {
52+
commit.type = 'Tests'
53+
} else if (commit.type === 'build') {
54+
commit.type = 'Build System'
5455
// } else if (commit.type === `chore`) {
5556
// commit.type = `Maintenance`
56-
} else if (commit.type === `ci`) {
57-
commit.type = `Continuous Integration`
58-
} else {
59-
return
60-
}
57+
} else if (commit.type === 'ci') {
58+
commit.type = 'Continuous Integration'
59+
} else {
60+
return
61+
}
6162

62-
if (commit.scope === `*`) {
63-
commit.scope = ``
64-
}
63+
if (commit.scope === '*') {
64+
commit.scope = ''
65+
}
6566

66-
if (typeof commit.hash === `string`) {
67-
commit.shortHash = commit.hash.substring(0, 7)
68-
}
67+
if (typeof commit.hash === 'string') {
68+
commit.shortHash = commit.hash.substring(0, 7)
69+
}
6970

70-
if (typeof commit.subject === `string`) {
71-
let url = context.repository
72-
? `${context.host}/${context.owner}/${context.repository}`
73-
: context.repoUrl
74-
if (url) {
75-
url = `${url}/issues/`
76-
// Issue URLs.
77-
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
78-
issues.push(issue)
79-
return `[#${issue}](${url}${issue})`
80-
})
71+
if (typeof commit.subject === 'string') {
72+
let url = context.repository
73+
? `${context.host}/${context.owner}/${context.repository}`
74+
: context.repoUrl
75+
if (url) {
76+
url = `${url}/issues/`
77+
// Issue URLs.
78+
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
79+
issues.push(issue)
80+
return `[#${issue}](${url}${issue})`
81+
})
82+
}
83+
if (context.host) {
84+
// User URLs.
85+
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
86+
if (username.includes('/')) {
87+
return `@${username}`
8188
}
82-
if (context.host) {
83-
// User URLs.
84-
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
85-
if (username.includes('/')) {
86-
return `@${username}`
87-
}
8889

89-
return `[@${username}](${context.host}/${username})`
90-
})
91-
}
90+
return `[@${username}](${context.host}/${username})`
91+
})
9292
}
93+
}
9394

94-
// remove references that already appear in the subject
95-
commit.references = commit.references.filter(reference => {
96-
if (issues.indexOf(reference.issue) === -1) {
97-
return true
98-
}
95+
// remove references that already appear in the subject
96+
commit.references = commit.references.filter(reference => {
97+
if (issues.indexOf(reference.issue) === -1) {
98+
return true
99+
}
99100

100-
return false
101-
})
101+
return false
102+
})
102103

103-
return commit
104-
},
105-
},
106-
},
107-
};
104+
return commit
105+
}
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)