@ethima/commitlint-config 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2023 Joris Kraak
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Commitlint Configuration
2
+
3
+ A shareable configuration for [Commitlint][commitlint-url] for projects
4
+ maintained by [the Ethima organization][ethima-url]. The configuration is based
5
+ on [the conventional commits][conventional-commits-url]
6
+ [configuration][commitlint-config-conventional-url], with some minor
7
+ adjustments as detailed below.
8
+
9
+ ## Differences from the [`config-conventional` configuration][commitlint-config-conventional-url]
10
+
11
+ ### More lenient rules regarding long lines in bodies and footers
12
+
13
+ When referencing URIs in commit messages, which is a common scenario when
14
+ referencing code on source hosting platforms, etc., it is trivial to trigger
15
+ the `{body,footer}-max-line-length` rules.
16
+
17
+ To ensure URIs like these can be included in commit messages, this
18
+ configuration replaces the `{body,footer}-max-line-length` rules with the
19
+ `{body,footer}-max-line-length-with-footnote-exemption` rules. These rules
20
+ allow long lines in either the body or the footer of commit messages if they
21
+ are written as Markdown footnotes, e.g. `[^1]: <long line>`,
22
+ `[^named-footnote]: <long line>`. These footnotes can then be referenced
23
+ elsewhere in the commit message and most hosting platforms will render these
24
+ footnotes with proper links, etc.
25
+
26
+ Both the `body-` and `footer-` rules are replaced as some URIs may trigger the
27
+ footer detection in the commit meesage parser, particularly when a URI includes
28
+ a `#`.
29
+
30
+ ### Stricter rules on merge and `fixup!`/`squash!` commits
31
+
32
+ The desired workflow for projects using this configuration is to use feature
33
+ branches that are continuously rebased on top of (pre)release branches. This
34
+ includes the use of `fixup!` and `squash!` commits, which should all be rebased
35
+ out _prior_ to merging into a (pre)release branch. However, by default, these
36
+ types of commits are [allowed by the `is-ignored`
37
+ configuration][commitlint-is-ignored-fixup-squash-url], resulting in merge/pull
38
+ requests not being blocked when they should be by Commitlint.
39
+
40
+ Additionally, [the default `is-ignored`
41
+ configuration][commitlint-is-ignored-wildcards-url] allows different types of
42
+ merge commits which do not align well with the process set out here, e.g.
43
+ merging _into_ a feature branch or pulling updates using a merge strategy. All
44
+ of these commits should also be rebased out prior to merging into a
45
+ (pre)release branch.
46
+
47
+ The only acceptable commits that are ignored by default are those related to
48
+ "reverts", which may be used to update/undo conventionally documented changes
49
+ prior to a release and merge commits that result from merging feature branches
50
+ into (pre)release branches.
51
+
52
+ [commitlint-config-conventional-url]: https://www.npmjs.com/package/@commitlint/config-conventional
53
+ [commitlint-is-ignored-fixup-squash-url]: https://github.com/conventional-changelog/commitlint/blob/3bc4726f0dddfa051bc75f6af7b7ca076b04a839/%40commitlint/is-ignored/src/defaults.ts#L23
54
+ [commitlint-is-ignored-wildcards-url]: https://github.com/conventional-changelog/commitlint/blob/3bc4726f0dddfa051bc75f6af7b7ca076b04a839/%40commitlint/is-ignored/src/defaults.ts#L17-L29
55
+ [commitlint-url]: https://commitlint.js.org
56
+ [conventional-commits-url]: https://conventionalcommits.org/
57
+ [ethima-url]: https://gitlab.com/ethima/
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@ethima/commitlint-config",
3
+ "version": "1.0.0",
4
+ "description": "A shareable Commitlint configuration for the Ethima organization",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "ava"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@gitlab.com/ethima/commitlint-config.git"
12
+ },
13
+ "keywords": [
14
+ "commitlint",
15
+ "ethima",
16
+ "configuration"
17
+ ],
18
+ "author": "Joris Kraak <me@joriskraak.nl>",
19
+ "license": "MIT",
20
+ "bugs": {
21
+ "url": "https://gitlab.com/ethima/commitlint-config/-/issues"
22
+ },
23
+ "homepage": "https://gitlab.com/ethima/commitlint-config",
24
+ "dependencies": {
25
+ "@commitlint/config-conventional": "18.1.0",
26
+ "@commitlint/is-ignored": "18.1.0"
27
+ },
28
+ "devDependencies": {
29
+ "@commitlint/lint": "18.1.0",
30
+ "@commitlint/load": "18.2.0",
31
+ "ava": "5.3.1"
32
+ }
33
+ }
package/src/index.js ADDED
@@ -0,0 +1,72 @@
1
+ const baseConfiguration = require("@commitlint/config-conventional");
2
+ const {
3
+ wildcards: defaultIgnoreFunctions,
4
+ } = require("@commitlint/is-ignored/lib/defaults");
5
+
6
+ const footnoteMatcher = new RegExp("^\\[\\^.+?\\]:");
7
+
8
+ // When referencing URIs in commit messages, it is very common to hit
9
+ // `max-line-length` restrictions. As a work-around, these URIs may be added as
10
+ // Markdown footnotes which can then be detected and given an exemption
11
+ const buildMaxLineLengthWithFootnoteExemption = (section) => {
12
+ return (parsed, _, value) => {
13
+ const sectionContent = parsed[section];
14
+
15
+ if (!sectionContent) {
16
+ return [true];
17
+ }
18
+
19
+ const lines = sectionContent.split(/\r?\n/);
20
+
21
+ const result = lines.every(
22
+ (line) => line.length <= value || footnoteMatcher.test(line),
23
+ );
24
+
25
+ return [
26
+ result,
27
+ `A ${section}'s lines must not be longer than ${value} characters`,
28
+ ];
29
+ };
30
+ };
31
+
32
+ // Only keep the default ignore functions allowing:
33
+ //
34
+ // - Merge/pull request merge commits into (pre)release branches.
35
+ // - Revert commits (to allow undoing/modifying previously conventionally
36
+ // documented changes).
37
+ //
38
+ // Instead of duplicating these function definitions, it is more
39
+ // straightforward to obtain them from the defaults
40
+ const ignores = defaultIgnoreFunctions.filter(
41
+ (ignoreFunction) =>
42
+ ignoreFunction("Revert ") || ignoreFunction("Merge 'x' into 'y' "),
43
+ );
44
+
45
+ module.exports = {
46
+ // Do not use the default ignore patterns as they allow patterns, e.g.
47
+ // `fixup!` and `squash!` commits, that should be blocked in the workflows
48
+ // primarily supported by this configuration
49
+ defaultIgnores: false,
50
+ extends: ["@commitlint/config-conventional"],
51
+ ignores,
52
+ plugins: [
53
+ {
54
+ rules: {
55
+ "body-max-line-length-with-footnote-exemption":
56
+ buildMaxLineLengthWithFootnoteExemption("body"),
57
+ "footer-max-line-length-with-footnote-exemption":
58
+ buildMaxLineLengthWithFootnoteExemption("footer"),
59
+ },
60
+ },
61
+ ],
62
+ // Disable the original `max-line-length` rules and replace them with
63
+ // versions that have an exemption for footnotes
64
+ rules: {
65
+ "body-max-line-length": [0],
66
+ "body-max-line-length-with-footnote-exemption":
67
+ baseConfiguration.rules["body-max-line-length"],
68
+ "footer-max-line-length": [0],
69
+ "footer-max-line-length-with-footnote-exemption":
70
+ baseConfiguration.rules["footer-max-line-length"],
71
+ },
72
+ };