@astral/commitlint-config 1.3.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -0
  3. package/index.js +85 -0
  4. package/package.json +22 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Astral.Soft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # @astral/commitlint-config
2
+
3
+ # Usage
4
+
5
+ ## Installation
6
+
7
+ ### Npm
8
+ ```shell
9
+ npm i commitlint @astral/commitlint-config --save-dev
10
+ ```
11
+
12
+ ### Yarn
13
+ ```shell
14
+ yarn add commitlint @astral/commitlint-config -D
15
+ ```
16
+
17
+ ### Configuration
18
+ ```commitlint.config.js```
19
+ ```js
20
+ const { createConfig } = require('@astral/commitlint-config');
21
+
22
+ module.exports = createConfig({
23
+ scopes: ['ui', 'server'],
24
+ ticketPrefix: 'UIKIT',
25
+ });
26
+ ```
27
+
28
+ ```.huskyrc```
29
+ ```json
30
+ {
31
+ "hooks": {
32
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
33
+ }
34
+ }
35
+ ```
36
+
37
+ ### Message example
38
+ #### Valid
39
+ ```feat(UIKIT-222,ui): Title```
40
+ ```feat: Title```
41
+ ```feat(UIKIT-222): Title```
42
+
43
+ #### Invalid
44
+ ```feat(UIKIT222): Title```
45
+ ```feat(unknown): Title```
46
+
47
+ # Format
48
+
49
+ ```${ENUM}(SCOPE|TASK): Description```
50
+
51
+ Default ENUM:
52
+ - feat
53
+ - bug
54
+ - wip (work in progress)
55
+ - refactor
56
+ - doc
57
+ - build
58
+ - chore
59
+
60
+ # API
61
+ ## createConfig
62
+ ```ts
63
+ const { createConfig } = require('@astral/commitlint-config');
64
+
65
+ type Params = {
66
+ /**
67
+ * Список доступных scopes.
68
+ * @example
69
+ * // createConfig({ scopes: ['server', 'ui'], ticketPrefix: 'UIKIT' })
70
+ */
71
+ scopes?: string[];
72
+ /**
73
+ * Название префикса задач, данный префикс будет доступен в scope.
74
+ * @example
75
+ * // createConfig({ ticketPrefix: 'UIKIT' })
76
+ */
77
+ ticketPrefix: string;
78
+ /**
79
+ * Список доступных type. Дефолтное значение указано в разделе Format
80
+ * @example
81
+ * // createConfig({ typeEnum: ['feat', 'ci'], ticketPrefix: 'UIKIT', })
82
+ */
83
+ typeEnum?: string[];
84
+ };
85
+
86
+ createConfig(params: Params);
87
+ ```
package/index.js ADDED
@@ -0,0 +1,85 @@
1
+ const DEFAULT_TYPE_ENUM = [
2
+ 'feat',
3
+ 'bug',
4
+ 'wip',
5
+ 'refactor',
6
+ 'doc',
7
+ 'build',
8
+ 'chore',
9
+ 'revert',
10
+ 'style',
11
+ ];
12
+
13
+ /**
14
+ * Создает commitlint config
15
+ * @param {Object} params - Параметры инициализации конфига.
16
+ * @param {string[]} [params.scopes=[]] - Список доступных scopes.
17
+ * @param {string} params.ticketPrefix - Название префикса задач, данный префикс будет доступен в scope.
18
+ * @param {string[]} [params.typeEnum=[]] - Список доступных type.
19
+ * @example
20
+ * // createConfig({ scopes: ['server', 'ui'], ticketPrefix: 'UIKIT' })
21
+ */
22
+ const createConfig = ({
23
+ scopes = [],
24
+ ticketPrefix,
25
+ typeEnum = DEFAULT_TYPE_ENUM,
26
+ }) => ({
27
+ extends: ['@commitlint/config-conventional'],
28
+
29
+ plugins: ['commitlint-plugin-function-rules'],
30
+
31
+ rules: {
32
+ // Тело коммита должно начинаться с пустой строки
33
+ 'body-leading-blank': [2, 'always'],
34
+
35
+ // Нижний колонтитул коммита должен начинаться с пустой строки
36
+ 'footer-leading-blank': [2, 'always'],
37
+
38
+ // Максимальная длина заголовка 90 символов
39
+ 'header-max-length': [2, 'always', 90],
40
+
41
+ // Для scope разрешается использовать только: lower-case, camel-case, kebab-case, pascal-case
42
+ 'scope-case': [2, 'never', ['sentence-case', 'start-case']],
43
+
44
+ // Описание не может быть пустым
45
+ 'subject-empty': [2, 'never'],
46
+
47
+ // Описание не должно заканчиваться '.'
48
+ 'subject-full-stop': [2, 'never', '.'],
49
+
50
+ // Описание должно начинаться с большой буквы
51
+ 'subject-case': [2, 'always', 'sentence-case'],
52
+
53
+ // Тип всегда только в нижнем регистре
54
+ 'type-case': [2, 'always', 'lower-case'],
55
+
56
+ // Тип не может быть пустым
57
+ 'type-empty': [2, 'never'],
58
+
59
+ // Перечислим все возможные варианты коммитов
60
+ 'type-enum': [2, 'always', typeEnum],
61
+
62
+ // функция вызывается при проверке scopes
63
+ 'function-rules/scope-enum': [
64
+ 2,
65
+ 'always',
66
+ ({ scope }) => {
67
+ const isTicketScope = scope?.startsWith(`${ticketPrefix}-`);
68
+
69
+ if (!scope || scopes.includes(scope) || isTicketScope) {
70
+ return [true];
71
+ }
72
+
73
+ const scopesEnumsMessage = [...scopes, `${ticketPrefix}-XXXX`].join(
74
+ ', ',
75
+ );
76
+
77
+ return [false, `scope must be one of [${scopesEnumsMessage}]`];
78
+ },
79
+ ],
80
+ },
81
+ });
82
+
83
+ module.exports = {
84
+ createConfig,
85
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@astral/commitlint-config",
3
+ "version": "1.3.0",
4
+ "main": "./index.js",
5
+ "dependencies": {
6
+ "@commitlint/config-conventional": "^17.0.2",
7
+ "commitlint-plugin-function-rules": "^1.7.1"
8
+ },
9
+ "peerDependencies": {
10
+ "commitlint": "16.x.x"
11
+ },
12
+ "author": "Astral.Soft",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/kaluga-astral/code-style"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/kaluga-astral/code-style/issues"
20
+ },
21
+ "keywords": []
22
+ }