@icebreakers/commitlint-config 1.1.0 → 1.1.1

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/dist/index.cjs CHANGED
@@ -1,112 +1,21 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/config.ts
2
-
3
-
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
2
+ var _configconventional = require('@commitlint/config-conventional'); var _configconventional2 = _interopRequireDefault(_configconventional);
4
3
  var _types = require('@commitlint/types');
5
-
6
- // src/constants.ts
7
- var DEFAULT_PARSER_PRESET = "conventional-changelog-conventionalcommits";
8
- var DEFAULT_HEADER_MAX_LENGTH = 100;
9
- var DEFAULT_BODY_MAX_LINE_LENGTH = 100;
10
- var DEFAULT_FOOTER_MAX_LINE_LENGTH = 100;
11
- var DEFAULT_FULL_STOP = ".";
12
- var DEFAULT_SUBJECT_FORBIDDEN_CASES = [
13
- "sentence-case",
14
- "start-case",
15
- "pascal-case",
16
- "upper-case"
17
- ];
18
- var DEFAULT_COMMIT_TYPES = [
19
- {
20
- value: "build",
21
- title: "Builds",
22
- description: "Changes that affect the build system or external dependencies (example scopes: pnpm, webpack, docker)",
23
- emoji: "\u{1F6E0}"
24
- },
25
- {
26
- value: "chore",
27
- title: "Chores",
28
- description: "Other changes that don't modify src or test files",
29
- emoji: "\u267B\uFE0F"
30
- },
31
- {
32
- value: "ci",
33
- title: "Continuous Integrations",
34
- description: "Changes to our CI configuration files and scripts (example scopes: GitHub Actions, Travis, Circle)",
35
- emoji: "\u2699\uFE0F"
36
- },
37
- {
38
- value: "docs",
39
- title: "Documentation",
40
- description: "Documentation only changes",
41
- emoji: "\u{1F4DA}"
42
- },
43
- {
44
- value: "feat",
45
- title: "Features",
46
- description: "A new feature",
47
- emoji: "\u2728"
48
- },
49
- {
50
- value: "fix",
51
- title: "Bug Fixes",
52
- description: "A bug fix",
53
- emoji: "\u{1F41B}"
54
- },
55
- {
56
- value: "perf",
57
- title: "Performance Improvements",
58
- description: "A code change that improves performance",
59
- emoji: "\u{1F680}"
60
- },
61
- {
62
- value: "refactor",
63
- title: "Code Refactoring",
64
- description: "A code change that neither fixes a bug nor adds a feature",
65
- emoji: "\u{1F4E6}"
66
- },
67
- {
68
- value: "revert",
69
- title: "Reverts",
70
- description: "Reverts a previous commit",
71
- emoji: "\u{1F5D1}"
72
- },
73
- {
74
- value: "style",
75
- title: "Styles",
76
- description: "Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",
77
- emoji: "\u{1F48E}"
78
- },
79
- {
80
- value: "test",
81
- title: "Tests",
82
- description: "Adding missing tests or correcting existing tests",
83
- emoji: "\u{1F6A8}"
84
- }
85
- ];
86
- var DEFAULT_TYPES = DEFAULT_COMMIT_TYPES.map((type) => type.value);
87
- var DEFAULT_PROMPT_SCOPE_DESCRIPTION = "What is the scope of this change (e.g. component or file name)";
88
- var DEFAULT_PROMPT_TYPE_DESCRIPTION = "Select the type of change that you're committing";
89
- var DEFAULT_PROMPT_SUBJECT_DESCRIPTION = "Write a short, imperative tense description of the change";
90
- var DEFAULT_PROMPT_BODY_DESCRIPTION = "Provide a longer description of the change";
91
- var DEFAULT_PROMPT_IS_BREAKING_DESCRIPTION = "Are there any breaking changes?";
92
- var DEFAULT_PROMPT_BREAKING_BODY_DESCRIPTION = "A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself";
93
- var DEFAULT_PROMPT_BREAKING_DESCRIPTION = "Describe the breaking changes";
94
- var DEFAULT_PROMPT_IS_ISSUE_AFFECTED_DESCRIPTION = "Does this change affect any open issues?";
95
- var DEFAULT_PROMPT_ISSUES_BODY_DESCRIPTION = "If issues are closed, the commit requires a body. Please enter a longer description of the commit itself";
96
- var DEFAULT_PROMPT_ISSUES_DESCRIPTION = 'Add issue references (e.g. "fix #123", "re #123".)';
97
4
  var DEFAULT_EXTENDS = ["@commitlint/config-conventional"];
98
-
99
- // src/utils.ts
100
- function toArray(value) {
5
+ var DEFAULT_PARSER_PRESET = "conventional-changelog-conventionalcommits";
6
+ function asArray(value) {
101
7
  if (value === void 0) {
102
8
  return [];
103
9
  }
104
10
  return Array.isArray(value) ? value : [value];
105
11
  }
106
- function unique(values) {
12
+ function mergeUnique(values) {
107
13
  const seen = /* @__PURE__ */ new Set();
108
14
  const result = [];
109
15
  for (const value of values) {
16
+ if (value === void 0 || value === null) {
17
+ continue;
18
+ }
110
19
  if (!seen.has(value)) {
111
20
  seen.add(value);
112
21
  result.push(value);
@@ -114,279 +23,189 @@ function unique(values) {
114
23
  }
115
24
  return result;
116
25
  }
117
- function toTitleCase(value) {
118
- return value.split(/[-_/]/g).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join(" ");
119
- }
120
- function createDefaultCommitTypeDefinition(value) {
26
+ function resolveBaseTypeRule() {
27
+ const rule = _optionalChain([_configconventional2.default, 'access', _ => _.rules, 'optionalAccess', _2 => _2["type-enum"]]);
28
+ if (Array.isArray(rule)) {
29
+ const severity = _nullishCoalesce(rule[0], () => ( _types.RuleConfigSeverity.Error));
30
+ const condition = _nullishCoalesce(rule[1], () => ( "always"));
31
+ const values = _nullishCoalesce(rule[2], () => ( []));
32
+ return {
33
+ severity,
34
+ condition,
35
+ values: [...values]
36
+ };
37
+ }
121
38
  return {
122
- value,
123
- title: toTitleCase(value),
124
- description: "Custom change type"
39
+ severity: _types.RuleConfigSeverity.Error,
40
+ condition: "always",
41
+ values: []
125
42
  };
126
43
  }
127
- function mergeTypeDefinitions(defaults, overrides = []) {
128
- const map = /* @__PURE__ */ new Map();
129
- for (const definition of defaults) {
130
- map.set(definition.value, definition);
131
- }
132
- for (const definition of overrides) {
133
- map.set(definition.value, definition);
44
+ function buildTypesConfig(options) {
45
+ if (!options) {
46
+ return {};
134
47
  }
135
- return map;
136
- }
137
- function isPlainObject(value) {
138
- return Boolean(
139
- value && typeof value === "object" && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]"
140
- );
141
- }
142
- function mergeDeep(base, override) {
143
- if (!override) {
144
- return base;
48
+ const baseRule = resolveBaseTypeRule();
49
+ const additional = mergeUnique([
50
+ ...baseRule.values,
51
+ ...mergeUnique(_nullishCoalesce(options.add, () => ( []))),
52
+ ...mergeUnique((_nullishCoalesce(options.definitions, () => ( []))).map((definition) => definition.value))
53
+ ]);
54
+ let rule;
55
+ if (additional.length > 0) {
56
+ rule = [
57
+ _nullishCoalesce(options.severity, () => ( baseRule.severity)),
58
+ _nullishCoalesce(options.condition, () => ( baseRule.condition)),
59
+ additional
60
+ ];
61
+ }
62
+ if (!_optionalChain([options, 'access', _3 => _3.definitions, 'optionalAccess', _4 => _4.length])) {
63
+ return { rule };
64
+ }
65
+ const basePromptType = _optionalChain([_configconventional2.default, 'access', _5 => _5.prompt, 'optionalAccess', _6 => _6.questions, 'optionalAccess', _7 => _7.type]);
66
+ const mergedEnum = {
67
+ ..._nullishCoalesce(_optionalChain([basePromptType, 'optionalAccess', _8 => _8.enum]), () => ( {}))
68
+ };
69
+ for (const definition of options.definitions) {
70
+ const { value, title, description, emoji } = definition;
71
+ mergedEnum[value] = {
72
+ ..._nullishCoalesce(mergedEnum[value], () => ( {})),
73
+ title,
74
+ description,
75
+ emoji
76
+ };
145
77
  }
146
- const output = { ...base };
147
- for (const [key, value] of Object.entries(override)) {
148
- if (value === void 0) {
149
- continue;
150
- }
151
- const baseValue = output[key];
152
- if (isPlainObject(baseValue) && isPlainObject(value)) {
153
- output[key] = mergeDeep(baseValue, value);
154
- continue;
155
- }
156
- if (Array.isArray(value)) {
157
- output[key] = [...value];
158
- continue;
78
+ const prompt = {
79
+ ..._nullishCoalesce(_configconventional2.default.prompt, () => ( {})),
80
+ questions: {
81
+ ..._nullishCoalesce(_optionalChain([_configconventional2.default, 'access', _9 => _9.prompt, 'optionalAccess', _10 => _10.questions]), () => ( {})),
82
+ type: {
83
+ ..._nullishCoalesce(basePromptType, () => ( {})),
84
+ enum: mergedEnum
85
+ }
159
86
  }
160
- output[key] = value;
161
- }
162
- return output;
163
- }
164
- function removeUndefined(value) {
165
- const entries = Object.entries(value).filter(([, item]) => item !== void 0);
166
- return Object.fromEntries(entries);
167
- }
168
-
169
- // src/config.ts
170
- function resolveExtends(entries) {
171
- if (!entries) {
172
- return [...DEFAULT_EXTENDS];
173
- }
174
- const values = toArray(entries);
175
- return unique([...DEFAULT_EXTENDS, ...values]);
87
+ };
88
+ return { rule, prompt };
176
89
  }
177
- function resolveTypeSettings(options) {
178
- let severity = _types.RuleConfigSeverity.Error;
179
- let condition = "always";
180
- let overrides = [];
181
- let values;
90
+ function buildScopeRules(options) {
182
91
  if (!options) {
183
- values = [...DEFAULT_TYPES];
184
- } else if (Array.isArray(options)) {
185
- values = unique(options);
186
- } else {
187
- severity = _nullishCoalesce(options.severity, () => ( severity));
188
- condition = _nullishCoalesce(options.condition, () => ( condition));
189
- overrides = _nullishCoalesce(options.definitions, () => ( []));
190
- const base = options.values ? toArray(options.values) : DEFAULT_TYPES;
191
- const additions = options.add ? toArray(options.add) : [];
192
- values = unique([...base, ...additions]);
92
+ return {};
193
93
  }
194
- if (values.length === 0) {
195
- return {
196
- definitions: [],
197
- rule: [_types.RuleConfigSeverity.Disabled]
198
- };
94
+ const rules = {};
95
+ const severity = _nullishCoalesce(options.severity, () => ( _types.RuleConfigSeverity.Error));
96
+ const scopeValues = mergeUnique(asArray(options.values));
97
+ if (scopeValues.length > 0) {
98
+ rules["scope-enum"] = [severity, "always", scopeValues];
99
+ }
100
+ if (options.required !== void 0) {
101
+ if (options.required) {
102
+ rules["scope-empty"] = [severity, "never"];
103
+ } else {
104
+ rules["scope-empty"] = [_types.RuleConfigSeverity.Disabled];
105
+ }
199
106
  }
200
- const definitionsMap = mergeTypeDefinitions(DEFAULT_COMMIT_TYPES, overrides);
201
- const definitions = values.map(
202
- (value) => _nullishCoalesce(definitionsMap.get(value), () => ( createDefaultCommitTypeDefinition(value)))
203
- );
204
- return {
205
- definitions,
206
- rule: [severity, condition, values]
207
- };
208
- }
209
- function asCaseArray(value) {
210
- if (!value) {
211
- return [];
107
+ const scopeCases = mergeUnique(asArray(options.case));
108
+ if (scopeCases.length > 0) {
109
+ rules["scope-case"] = [severity, "always", scopeCases];
212
110
  }
213
- return toArray(value);
111
+ return rules;
214
112
  }
215
- function resolveScopeRules(options) {
113
+ function buildSubjectRules(options) {
216
114
  if (!options) {
217
115
  return {};
218
116
  }
219
117
  const rules = {};
220
- const values = Array.isArray(options) ? unique(options) : unique([
221
- ...toArray(_nullishCoalesce(options.values, () => ( []))),
222
- ...toArray(_nullishCoalesce(options.add, () => ( [])))
223
- ]);
224
- const baseSeverity = !Array.isArray(options) ? _nullishCoalesce(options.severity, () => ( _types.RuleConfigSeverity.Error)) : _types.RuleConfigSeverity.Error;
225
- if (values.length > 0) {
226
- rules["scope-enum"] = [baseSeverity, "always", values];
227
- }
228
- const allowEmpty = Array.isArray(options) ? true : _nullishCoalesce(options.allowEmpty, () => ( !options.required));
229
- if (allowEmpty) {
230
- rules["scope-empty"] = [_types.RuleConfigSeverity.Disabled];
231
- } else {
232
- rules["scope-empty"] = [baseSeverity, "never"];
118
+ const forbiddenCases = mergeUnique(asArray(options.forbidden));
119
+ if (forbiddenCases.length > 0) {
120
+ rules["subject-case"] = [
121
+ _nullishCoalesce(options.caseSeverity, () => ( _types.RuleConfigSeverity.Error)),
122
+ _nullishCoalesce(options.caseCondition, () => ( "never")),
123
+ forbiddenCases
124
+ ];
125
+ }
126
+ if (options.allowEmpty !== void 0) {
127
+ if (options.allowEmpty) {
128
+ rules["subject-empty"] = [_types.RuleConfigSeverity.Disabled];
129
+ } else {
130
+ rules["subject-empty"] = [
131
+ _nullishCoalesce(options.allowEmptySeverity, () => ( _types.RuleConfigSeverity.Error)),
132
+ "never"
133
+ ];
134
+ }
233
135
  }
234
- if (!Array.isArray(options) && options.case) {
235
- const scopeCaseValues = asCaseArray(options.case);
236
- if (scopeCaseValues.length > 0) {
237
- const caseSeverity = _nullishCoalesce(options.caseSeverity, () => ( baseSeverity));
238
- rules["scope-case"] = [caseSeverity, "always", scopeCaseValues];
136
+ if (options.fullStop !== void 0) {
137
+ if (options.fullStop) {
138
+ rules["subject-full-stop"] = [
139
+ _nullishCoalesce(options.fullStopSeverity, () => ( _types.RuleConfigSeverity.Error)),
140
+ "always",
141
+ _nullishCoalesce(options.fullStopCharacter, () => ( "."))
142
+ ];
143
+ } else {
144
+ rules["subject-full-stop"] = [_types.RuleConfigSeverity.Disabled];
239
145
  }
240
146
  }
241
147
  return rules;
242
148
  }
243
- function resolveSubjectRules(options) {
244
- const rules = {};
245
- const forbiddenCases = asCaseArray(_optionalChain([options, 'optionalAccess', _ => _.forbidden]));
246
- const subjectCases = forbiddenCases.length > 0 ? forbiddenCases : DEFAULT_SUBJECT_FORBIDDEN_CASES;
247
- const caseSeverity = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.caseSeverity]), () => ( _types.RuleConfigSeverity.Error));
248
- rules["subject-case"] = [caseSeverity, "never", subjectCases];
249
- if (_optionalChain([options, 'optionalAccess', _3 => _3.allowEmpty])) {
250
- rules["subject-empty"] = [_types.RuleConfigSeverity.Disabled];
251
- } else {
252
- const emptySeverity = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _4 => _4.emptySeverity]), () => ( _types.RuleConfigSeverity.Error));
253
- rules["subject-empty"] = [emptySeverity, "never"];
149
+ function buildHeaderRules(options) {
150
+ if (!options) {
151
+ return {};
254
152
  }
255
- if (_optionalChain([options, 'optionalAccess', _5 => _5.fullStop]) === false) {
256
- rules["subject-full-stop"] = [_types.RuleConfigSeverity.Disabled];
257
- } else {
258
- const fullStopSeverity = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _6 => _6.fullStopSeverity]), () => ( _types.RuleConfigSeverity.Error));
259
- const fullStop = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _7 => _7.fullStop]), () => ( DEFAULT_FULL_STOP));
260
- rules["subject-full-stop"] = [fullStopSeverity, "never", fullStop];
153
+ const rules = {};
154
+ const severity = _nullishCoalesce(options.severity, () => ( _types.RuleConfigSeverity.Error));
155
+ const condition = _nullishCoalesce(options.condition, () => ( "always"));
156
+ if (options.maxLength !== void 0) {
157
+ rules["header-max-length"] = [severity, condition, options.maxLength];
261
158
  }
262
159
  return rules;
263
160
  }
264
- function resolveHeaderRules(options) {
265
- const severity = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _8 => _8.severity]), () => ( _types.RuleConfigSeverity.Error));
266
- const maxLength = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.maxLength]), () => ( DEFAULT_HEADER_MAX_LENGTH));
267
- return {
268
- "header-max-length": [severity, "always", maxLength]
269
- };
270
- }
271
- function createBaseRules() {
272
- return {
273
- "body-leading-blank": [_types.RuleConfigSeverity.Warning, "always"],
274
- "body-max-line-length": [
275
- _types.RuleConfigSeverity.Error,
276
- "always",
277
- DEFAULT_BODY_MAX_LINE_LENGTH
278
- ],
279
- "footer-leading-blank": [_types.RuleConfigSeverity.Warning, "always"],
280
- "footer-max-line-length": [
281
- _types.RuleConfigSeverity.Error,
282
- "always",
283
- DEFAULT_FOOTER_MAX_LINE_LENGTH
284
- ],
285
- "header-trim": [_types.RuleConfigSeverity.Error, "always"],
286
- "type-case": [_types.RuleConfigSeverity.Error, "always", "lower-case"],
287
- "type-empty": [_types.RuleConfigSeverity.Error, "never"]
288
- };
289
- }
290
- function buildTypeEnum(definitions) {
291
- return definitions.reduce(
292
- (accumulator, definition) => {
293
- accumulator[definition.value] = {
294
- description: definition.description,
295
- title: definition.title,
296
- emoji: definition.emoji
297
- };
298
- return accumulator;
299
- },
300
- {}
301
- );
302
- }
303
- function createBasePrompt(definitions) {
161
+ function mergePrompts(base, override) {
162
+ if (!base && !override) {
163
+ return void 0;
164
+ }
165
+ if (!base) {
166
+ return override;
167
+ }
168
+ if (!override) {
169
+ return base;
170
+ }
304
171
  return {
172
+ ...base,
173
+ ...override,
305
174
  questions: {
306
- type: {
307
- description: DEFAULT_PROMPT_TYPE_DESCRIPTION,
308
- enum: buildTypeEnum(definitions)
309
- },
310
- scope: {
311
- description: DEFAULT_PROMPT_SCOPE_DESCRIPTION
312
- },
313
- subject: {
314
- description: DEFAULT_PROMPT_SUBJECT_DESCRIPTION
315
- },
316
- body: {
317
- description: DEFAULT_PROMPT_BODY_DESCRIPTION
318
- },
319
- isBreaking: {
320
- description: DEFAULT_PROMPT_IS_BREAKING_DESCRIPTION
321
- },
322
- breakingBody: {
323
- description: DEFAULT_PROMPT_BREAKING_BODY_DESCRIPTION
324
- },
325
- breaking: {
326
- description: DEFAULT_PROMPT_BREAKING_DESCRIPTION
327
- },
328
- isIssueAffected: {
329
- description: DEFAULT_PROMPT_IS_ISSUE_AFFECTED_DESCRIPTION
330
- },
331
- issuesBody: {
332
- description: DEFAULT_PROMPT_ISSUES_BODY_DESCRIPTION
333
- },
334
- issues: {
335
- description: DEFAULT_PROMPT_ISSUES_DESCRIPTION
336
- }
175
+ ..._nullishCoalesce(base.questions, () => ( {})),
176
+ ..._nullishCoalesce(override.questions, () => ( {}))
337
177
  }
338
178
  };
339
179
  }
340
- function resolvePrompt(definitions, overrides) {
341
- const base = createBasePrompt(definitions);
342
- return mergeDeep(base, overrides);
343
- }
344
180
  function createIcebreakerCommitlintConfig(options = {}) {
345
- const extendsField = resolveExtends(options.extends);
346
- const typeSettings = resolveTypeSettings(options.types);
347
- const scopeRules = resolveScopeRules(options.scopes);
348
- const subjectRules = resolveSubjectRules(options.subject);
349
- const headerRules = resolveHeaderRules(options.header);
350
- const baseRules = createBaseRules();
181
+ const { types, scopes, subject, header } = options;
182
+ const extendsList = mergeUnique([
183
+ ...DEFAULT_EXTENDS,
184
+ ...mergeUnique(_nullishCoalesce(options.extends, () => ( [])))
185
+ ]);
351
186
  const rules = {
352
- ...baseRules,
353
- "type-enum": typeSettings.rule,
354
- ...scopeRules,
355
- ...subjectRules,
356
- ...headerRules,
357
- ...options.rules
187
+ ...buildScopeRules(scopes),
188
+ ...buildSubjectRules(subject),
189
+ ...buildHeaderRules(header)
190
+ };
191
+ const typesConfig = buildTypesConfig(types);
192
+ if (typesConfig.rule) {
193
+ rules["type-enum"] = typesConfig.rule;
194
+ }
195
+ const mergedRules = {
196
+ ...rules,
197
+ ..._nullishCoalesce(options.rules, () => ( {}))
198
+ };
199
+ const hasRules = Object.keys(mergedRules).length > 0;
200
+ const prompt = mergePrompts(typesConfig.prompt, options.prompt);
201
+ return {
202
+ extends: extendsList,
203
+ parserPreset: DEFAULT_PARSER_PRESET,
204
+ ...hasRules ? { rules: mergedRules } : {},
205
+ ...prompt ? { prompt } : {}
358
206
  };
359
- const prompt = resolvePrompt(typeSettings.definitions, options.prompt);
360
- return removeUndefined({
361
- extends: extendsField,
362
- formatter: options.formatter,
363
- parserPreset: _nullishCoalesce(options.parserPreset, () => ( DEFAULT_PARSER_PRESET)),
364
- rules,
365
- ignores: options.ignores,
366
- defaultIgnores: options.defaultIgnores,
367
- plugins: options.plugins,
368
- helpUrl: options.helpUrl,
369
- prompt
370
- });
371
- }
372
-
373
- // src/index.ts
374
-
375
- function createCommitlintConfig(options) {
376
- return createIcebreakerCommitlintConfig(options);
377
- }
378
- function icebreaker(options) {
379
- return createIcebreakerCommitlintConfig(options);
380
207
  }
381
208
 
382
209
 
383
210
 
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
-
392
- exports.DEFAULT_COMMIT_TYPES = DEFAULT_COMMIT_TYPES; exports.DEFAULT_EXTENDS = DEFAULT_EXTENDS; exports.DEFAULT_SUBJECT_FORBIDDEN_CASES = DEFAULT_SUBJECT_FORBIDDEN_CASES; exports.DEFAULT_TYPES = DEFAULT_TYPES; exports.RuleConfigCondition = _types.RuleConfigCondition; exports.RuleConfigSeverity = _types.RuleConfigSeverity; exports.TargetCaseType = _types.TargetCaseType; exports.createCommitlintConfig = createCommitlintConfig; exports.createIcebreakerCommitlintConfig = createIcebreakerCommitlintConfig; exports.icebreaker = icebreaker;
211
+ exports.RuleConfigSeverity = _types.RuleConfigSeverity; exports.createIcebreakerCommitlintConfig = createIcebreakerCommitlintConfig;
package/dist/index.d.cts CHANGED
@@ -1,82 +1,48 @@
1
- import { RuleConfigSeverity, RuleConfigCondition, TargetCaseType, UserConfig, UserPromptConfig } from '@commitlint/types';
2
- export { RuleConfigCondition, RuleConfigSeverity, TargetCaseType } from '@commitlint/types';
1
+ import { RuleConfigCondition, RuleConfigSeverity, TargetCaseType, RulesConfig, UserPromptConfig, UserConfig } from '@commitlint/types';
2
+ export { UserConfig as CommitlintUserConfig, RuleConfigSeverity } from '@commitlint/types';
3
3
 
4
4
  interface CommitTypeDefinition {
5
5
  value: string;
6
- title: string;
7
- description: string;
6
+ title?: string;
7
+ description?: string;
8
8
  emoji?: string;
9
9
  }
10
- interface TypeRuleOptions {
11
- /**
12
- * Replace the default set of commit types.
13
- */
14
- values?: string | string[];
15
- /**
16
- * Extend the existing commit types without replacing them.
17
- */
18
- add?: string | string[];
19
- /**
20
- * Provide metadata for commit types, primarily used by the prompt.
21
- */
10
+ interface CommitTypesOptions {
11
+ add?: string[];
22
12
  definitions?: CommitTypeDefinition[];
23
- severity?: RuleConfigSeverity;
24
13
  condition?: RuleConfigCondition;
14
+ severity?: RuleConfigSeverity;
25
15
  }
26
- interface ScopeRuleOptions {
27
- values?: string | string[];
28
- add?: string | string[];
29
- case?: TargetCaseType | TargetCaseType[];
30
- /**
31
- * Require scopes on every commit message. Equivalent to disallowing empty scopes.
32
- */
16
+ interface CommitScopeOptions {
17
+ values?: string[];
33
18
  required?: boolean;
34
- /**
35
- * Explicitly allow empty scopes. Takes precedence over `required` when set.
36
- */
37
- allowEmpty?: boolean;
19
+ case?: TargetCaseType | TargetCaseType[];
38
20
  severity?: RuleConfigSeverity;
39
- caseSeverity?: RuleConfigSeverity;
40
21
  }
41
- interface SubjectRuleOptions {
22
+ interface CommitSubjectOptions {
42
23
  forbidden?: TargetCaseType | TargetCaseType[];
24
+ caseCondition?: RuleConfigCondition;
43
25
  caseSeverity?: RuleConfigSeverity;
44
- /**
45
- * Control the trailing character check. Set to `false` to disable the rule entirely.
46
- */
47
- fullStop?: string | false;
48
- fullStopSeverity?: RuleConfigSeverity;
49
26
  allowEmpty?: boolean;
50
- emptySeverity?: RuleConfigSeverity;
27
+ allowEmptySeverity?: RuleConfigSeverity;
28
+ fullStop?: boolean;
29
+ fullStopSeverity?: RuleConfigSeverity;
30
+ fullStopCharacter?: string;
51
31
  }
52
- interface HeaderRuleOptions {
32
+ interface CommitHeaderOptions {
53
33
  maxLength?: number;
34
+ condition?: RuleConfigCondition;
54
35
  severity?: RuleConfigSeverity;
55
36
  }
56
37
  interface IcebreakerCommitlintOptions {
57
- extends?: string | string[];
58
- types?: TypeRuleOptions | string[];
59
- scopes?: ScopeRuleOptions | string[];
60
- subject?: SubjectRuleOptions;
61
- header?: HeaderRuleOptions;
62
- rules?: UserConfig['rules'];
63
- parserPreset?: UserConfig['parserPreset'];
64
- formatter?: UserConfig['formatter'];
65
- ignores?: UserConfig['ignores'];
66
- defaultIgnores?: UserConfig['defaultIgnores'];
67
- plugins?: UserConfig['plugins'];
68
- helpUrl?: UserConfig['helpUrl'];
38
+ extends?: string[];
39
+ rules?: Partial<RulesConfig>;
40
+ types?: CommitTypesOptions;
41
+ scopes?: CommitScopeOptions;
42
+ subject?: CommitSubjectOptions;
43
+ header?: CommitHeaderOptions;
69
44
  prompt?: UserPromptConfig;
70
45
  }
71
-
72
46
  declare function createIcebreakerCommitlintConfig(options?: IcebreakerCommitlintOptions): UserConfig;
73
47
 
74
- declare const DEFAULT_SUBJECT_FORBIDDEN_CASES: TargetCaseType[];
75
- declare const DEFAULT_COMMIT_TYPES: CommitTypeDefinition[];
76
- declare const DEFAULT_TYPES: string[];
77
- declare const DEFAULT_EXTENDS: string[];
78
-
79
- declare function createCommitlintConfig(options?: IcebreakerCommitlintOptions): UserConfig;
80
- declare function icebreaker(options?: IcebreakerCommitlintOptions): UserConfig;
81
-
82
- export { type CommitTypeDefinition, DEFAULT_COMMIT_TYPES, DEFAULT_EXTENDS, DEFAULT_SUBJECT_FORBIDDEN_CASES, DEFAULT_TYPES, type HeaderRuleOptions, type IcebreakerCommitlintOptions, type ScopeRuleOptions, type SubjectRuleOptions, type TypeRuleOptions, createCommitlintConfig, createIcebreakerCommitlintConfig, icebreaker };
48
+ export { type CommitHeaderOptions, type CommitScopeOptions, type CommitSubjectOptions, type CommitTypeDefinition, type CommitTypesOptions, type IcebreakerCommitlintOptions, createIcebreakerCommitlintConfig };
package/dist/index.d.ts CHANGED
@@ -1,82 +1,48 @@
1
- import { RuleConfigSeverity, RuleConfigCondition, TargetCaseType, UserConfig, UserPromptConfig } from '@commitlint/types';
2
- export { RuleConfigCondition, RuleConfigSeverity, TargetCaseType } from '@commitlint/types';
1
+ import { RuleConfigCondition, RuleConfigSeverity, TargetCaseType, RulesConfig, UserPromptConfig, UserConfig } from '@commitlint/types';
2
+ export { UserConfig as CommitlintUserConfig, RuleConfigSeverity } from '@commitlint/types';
3
3
 
4
4
  interface CommitTypeDefinition {
5
5
  value: string;
6
- title: string;
7
- description: string;
6
+ title?: string;
7
+ description?: string;
8
8
  emoji?: string;
9
9
  }
10
- interface TypeRuleOptions {
11
- /**
12
- * Replace the default set of commit types.
13
- */
14
- values?: string | string[];
15
- /**
16
- * Extend the existing commit types without replacing them.
17
- */
18
- add?: string | string[];
19
- /**
20
- * Provide metadata for commit types, primarily used by the prompt.
21
- */
10
+ interface CommitTypesOptions {
11
+ add?: string[];
22
12
  definitions?: CommitTypeDefinition[];
23
- severity?: RuleConfigSeverity;
24
13
  condition?: RuleConfigCondition;
14
+ severity?: RuleConfigSeverity;
25
15
  }
26
- interface ScopeRuleOptions {
27
- values?: string | string[];
28
- add?: string | string[];
29
- case?: TargetCaseType | TargetCaseType[];
30
- /**
31
- * Require scopes on every commit message. Equivalent to disallowing empty scopes.
32
- */
16
+ interface CommitScopeOptions {
17
+ values?: string[];
33
18
  required?: boolean;
34
- /**
35
- * Explicitly allow empty scopes. Takes precedence over `required` when set.
36
- */
37
- allowEmpty?: boolean;
19
+ case?: TargetCaseType | TargetCaseType[];
38
20
  severity?: RuleConfigSeverity;
39
- caseSeverity?: RuleConfigSeverity;
40
21
  }
41
- interface SubjectRuleOptions {
22
+ interface CommitSubjectOptions {
42
23
  forbidden?: TargetCaseType | TargetCaseType[];
24
+ caseCondition?: RuleConfigCondition;
43
25
  caseSeverity?: RuleConfigSeverity;
44
- /**
45
- * Control the trailing character check. Set to `false` to disable the rule entirely.
46
- */
47
- fullStop?: string | false;
48
- fullStopSeverity?: RuleConfigSeverity;
49
26
  allowEmpty?: boolean;
50
- emptySeverity?: RuleConfigSeverity;
27
+ allowEmptySeverity?: RuleConfigSeverity;
28
+ fullStop?: boolean;
29
+ fullStopSeverity?: RuleConfigSeverity;
30
+ fullStopCharacter?: string;
51
31
  }
52
- interface HeaderRuleOptions {
32
+ interface CommitHeaderOptions {
53
33
  maxLength?: number;
34
+ condition?: RuleConfigCondition;
54
35
  severity?: RuleConfigSeverity;
55
36
  }
56
37
  interface IcebreakerCommitlintOptions {
57
- extends?: string | string[];
58
- types?: TypeRuleOptions | string[];
59
- scopes?: ScopeRuleOptions | string[];
60
- subject?: SubjectRuleOptions;
61
- header?: HeaderRuleOptions;
62
- rules?: UserConfig['rules'];
63
- parserPreset?: UserConfig['parserPreset'];
64
- formatter?: UserConfig['formatter'];
65
- ignores?: UserConfig['ignores'];
66
- defaultIgnores?: UserConfig['defaultIgnores'];
67
- plugins?: UserConfig['plugins'];
68
- helpUrl?: UserConfig['helpUrl'];
38
+ extends?: string[];
39
+ rules?: Partial<RulesConfig>;
40
+ types?: CommitTypesOptions;
41
+ scopes?: CommitScopeOptions;
42
+ subject?: CommitSubjectOptions;
43
+ header?: CommitHeaderOptions;
69
44
  prompt?: UserPromptConfig;
70
45
  }
71
-
72
46
  declare function createIcebreakerCommitlintConfig(options?: IcebreakerCommitlintOptions): UserConfig;
73
47
 
74
- declare const DEFAULT_SUBJECT_FORBIDDEN_CASES: TargetCaseType[];
75
- declare const DEFAULT_COMMIT_TYPES: CommitTypeDefinition[];
76
- declare const DEFAULT_TYPES: string[];
77
- declare const DEFAULT_EXTENDS: string[];
78
-
79
- declare function createCommitlintConfig(options?: IcebreakerCommitlintOptions): UserConfig;
80
- declare function icebreaker(options?: IcebreakerCommitlintOptions): UserConfig;
81
-
82
- export { type CommitTypeDefinition, DEFAULT_COMMIT_TYPES, DEFAULT_EXTENDS, DEFAULT_SUBJECT_FORBIDDEN_CASES, DEFAULT_TYPES, type HeaderRuleOptions, type IcebreakerCommitlintOptions, type ScopeRuleOptions, type SubjectRuleOptions, type TypeRuleOptions, createCommitlintConfig, createIcebreakerCommitlintConfig, icebreaker };
48
+ export { type CommitHeaderOptions, type CommitScopeOptions, type CommitSubjectOptions, type CommitTypeDefinition, type CommitTypesOptions, type IcebreakerCommitlintOptions, createIcebreakerCommitlintConfig };
package/dist/index.mjs CHANGED
@@ -1,112 +1,21 @@
1
- // src/config.ts
2
- import {
3
- RuleConfigSeverity
4
- } from "@commitlint/types";
5
-
6
- // src/constants.ts
7
- var DEFAULT_PARSER_PRESET = "conventional-changelog-conventionalcommits";
8
- var DEFAULT_HEADER_MAX_LENGTH = 100;
9
- var DEFAULT_BODY_MAX_LINE_LENGTH = 100;
10
- var DEFAULT_FOOTER_MAX_LINE_LENGTH = 100;
11
- var DEFAULT_FULL_STOP = ".";
12
- var DEFAULT_SUBJECT_FORBIDDEN_CASES = [
13
- "sentence-case",
14
- "start-case",
15
- "pascal-case",
16
- "upper-case"
17
- ];
18
- var DEFAULT_COMMIT_TYPES = [
19
- {
20
- value: "build",
21
- title: "Builds",
22
- description: "Changes that affect the build system or external dependencies (example scopes: pnpm, webpack, docker)",
23
- emoji: "\u{1F6E0}"
24
- },
25
- {
26
- value: "chore",
27
- title: "Chores",
28
- description: "Other changes that don't modify src or test files",
29
- emoji: "\u267B\uFE0F"
30
- },
31
- {
32
- value: "ci",
33
- title: "Continuous Integrations",
34
- description: "Changes to our CI configuration files and scripts (example scopes: GitHub Actions, Travis, Circle)",
35
- emoji: "\u2699\uFE0F"
36
- },
37
- {
38
- value: "docs",
39
- title: "Documentation",
40
- description: "Documentation only changes",
41
- emoji: "\u{1F4DA}"
42
- },
43
- {
44
- value: "feat",
45
- title: "Features",
46
- description: "A new feature",
47
- emoji: "\u2728"
48
- },
49
- {
50
- value: "fix",
51
- title: "Bug Fixes",
52
- description: "A bug fix",
53
- emoji: "\u{1F41B}"
54
- },
55
- {
56
- value: "perf",
57
- title: "Performance Improvements",
58
- description: "A code change that improves performance",
59
- emoji: "\u{1F680}"
60
- },
61
- {
62
- value: "refactor",
63
- title: "Code Refactoring",
64
- description: "A code change that neither fixes a bug nor adds a feature",
65
- emoji: "\u{1F4E6}"
66
- },
67
- {
68
- value: "revert",
69
- title: "Reverts",
70
- description: "Reverts a previous commit",
71
- emoji: "\u{1F5D1}"
72
- },
73
- {
74
- value: "style",
75
- title: "Styles",
76
- description: "Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",
77
- emoji: "\u{1F48E}"
78
- },
79
- {
80
- value: "test",
81
- title: "Tests",
82
- description: "Adding missing tests or correcting existing tests",
83
- emoji: "\u{1F6A8}"
84
- }
85
- ];
86
- var DEFAULT_TYPES = DEFAULT_COMMIT_TYPES.map((type) => type.value);
87
- var DEFAULT_PROMPT_SCOPE_DESCRIPTION = "What is the scope of this change (e.g. component or file name)";
88
- var DEFAULT_PROMPT_TYPE_DESCRIPTION = "Select the type of change that you're committing";
89
- var DEFAULT_PROMPT_SUBJECT_DESCRIPTION = "Write a short, imperative tense description of the change";
90
- var DEFAULT_PROMPT_BODY_DESCRIPTION = "Provide a longer description of the change";
91
- var DEFAULT_PROMPT_IS_BREAKING_DESCRIPTION = "Are there any breaking changes?";
92
- var DEFAULT_PROMPT_BREAKING_BODY_DESCRIPTION = "A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself";
93
- var DEFAULT_PROMPT_BREAKING_DESCRIPTION = "Describe the breaking changes";
94
- var DEFAULT_PROMPT_IS_ISSUE_AFFECTED_DESCRIPTION = "Does this change affect any open issues?";
95
- var DEFAULT_PROMPT_ISSUES_BODY_DESCRIPTION = "If issues are closed, the commit requires a body. Please enter a longer description of the commit itself";
96
- var DEFAULT_PROMPT_ISSUES_DESCRIPTION = 'Add issue references (e.g. "fix #123", "re #123".)';
1
+ // src/index.ts
2
+ import conventionalConfig from "@commitlint/config-conventional";
3
+ import { RuleConfigSeverity } from "@commitlint/types";
97
4
  var DEFAULT_EXTENDS = ["@commitlint/config-conventional"];
98
-
99
- // src/utils.ts
100
- function toArray(value) {
5
+ var DEFAULT_PARSER_PRESET = "conventional-changelog-conventionalcommits";
6
+ function asArray(value) {
101
7
  if (value === void 0) {
102
8
  return [];
103
9
  }
104
10
  return Array.isArray(value) ? value : [value];
105
11
  }
106
- function unique(values) {
12
+ function mergeUnique(values) {
107
13
  const seen = /* @__PURE__ */ new Set();
108
14
  const result = [];
109
15
  for (const value of values) {
16
+ if (value === void 0 || value === null) {
17
+ continue;
18
+ }
110
19
  if (!seen.has(value)) {
111
20
  seen.add(value);
112
21
  result.push(value);
@@ -114,279 +23,189 @@ function unique(values) {
114
23
  }
115
24
  return result;
116
25
  }
117
- function toTitleCase(value) {
118
- return value.split(/[-_/]/g).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join(" ");
119
- }
120
- function createDefaultCommitTypeDefinition(value) {
26
+ function resolveBaseTypeRule() {
27
+ const rule = conventionalConfig.rules?.["type-enum"];
28
+ if (Array.isArray(rule)) {
29
+ const severity = rule[0] ?? RuleConfigSeverity.Error;
30
+ const condition = rule[1] ?? "always";
31
+ const values = rule[2] ?? [];
32
+ return {
33
+ severity,
34
+ condition,
35
+ values: [...values]
36
+ };
37
+ }
121
38
  return {
122
- value,
123
- title: toTitleCase(value),
124
- description: "Custom change type"
39
+ severity: RuleConfigSeverity.Error,
40
+ condition: "always",
41
+ values: []
125
42
  };
126
43
  }
127
- function mergeTypeDefinitions(defaults, overrides = []) {
128
- const map = /* @__PURE__ */ new Map();
129
- for (const definition of defaults) {
130
- map.set(definition.value, definition);
131
- }
132
- for (const definition of overrides) {
133
- map.set(definition.value, definition);
44
+ function buildTypesConfig(options) {
45
+ if (!options) {
46
+ return {};
134
47
  }
135
- return map;
136
- }
137
- function isPlainObject(value) {
138
- return Boolean(
139
- value && typeof value === "object" && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]"
140
- );
141
- }
142
- function mergeDeep(base, override) {
143
- if (!override) {
144
- return base;
48
+ const baseRule = resolveBaseTypeRule();
49
+ const additional = mergeUnique([
50
+ ...baseRule.values,
51
+ ...mergeUnique(options.add ?? []),
52
+ ...mergeUnique((options.definitions ?? []).map((definition) => definition.value))
53
+ ]);
54
+ let rule;
55
+ if (additional.length > 0) {
56
+ rule = [
57
+ options.severity ?? baseRule.severity,
58
+ options.condition ?? baseRule.condition,
59
+ additional
60
+ ];
61
+ }
62
+ if (!options.definitions?.length) {
63
+ return { rule };
64
+ }
65
+ const basePromptType = conventionalConfig.prompt?.questions?.type;
66
+ const mergedEnum = {
67
+ ...basePromptType?.enum ?? {}
68
+ };
69
+ for (const definition of options.definitions) {
70
+ const { value, title, description, emoji } = definition;
71
+ mergedEnum[value] = {
72
+ ...mergedEnum[value] ?? {},
73
+ title,
74
+ description,
75
+ emoji
76
+ };
145
77
  }
146
- const output = { ...base };
147
- for (const [key, value] of Object.entries(override)) {
148
- if (value === void 0) {
149
- continue;
150
- }
151
- const baseValue = output[key];
152
- if (isPlainObject(baseValue) && isPlainObject(value)) {
153
- output[key] = mergeDeep(baseValue, value);
154
- continue;
155
- }
156
- if (Array.isArray(value)) {
157
- output[key] = [...value];
158
- continue;
78
+ const prompt = {
79
+ ...conventionalConfig.prompt ?? {},
80
+ questions: {
81
+ ...conventionalConfig.prompt?.questions ?? {},
82
+ type: {
83
+ ...basePromptType ?? {},
84
+ enum: mergedEnum
85
+ }
159
86
  }
160
- output[key] = value;
161
- }
162
- return output;
163
- }
164
- function removeUndefined(value) {
165
- const entries = Object.entries(value).filter(([, item]) => item !== void 0);
166
- return Object.fromEntries(entries);
167
- }
168
-
169
- // src/config.ts
170
- function resolveExtends(entries) {
171
- if (!entries) {
172
- return [...DEFAULT_EXTENDS];
173
- }
174
- const values = toArray(entries);
175
- return unique([...DEFAULT_EXTENDS, ...values]);
87
+ };
88
+ return { rule, prompt };
176
89
  }
177
- function resolveTypeSettings(options) {
178
- let severity = RuleConfigSeverity.Error;
179
- let condition = "always";
180
- let overrides = [];
181
- let values;
90
+ function buildScopeRules(options) {
182
91
  if (!options) {
183
- values = [...DEFAULT_TYPES];
184
- } else if (Array.isArray(options)) {
185
- values = unique(options);
186
- } else {
187
- severity = options.severity ?? severity;
188
- condition = options.condition ?? condition;
189
- overrides = options.definitions ?? [];
190
- const base = options.values ? toArray(options.values) : DEFAULT_TYPES;
191
- const additions = options.add ? toArray(options.add) : [];
192
- values = unique([...base, ...additions]);
92
+ return {};
193
93
  }
194
- if (values.length === 0) {
195
- return {
196
- definitions: [],
197
- rule: [RuleConfigSeverity.Disabled]
198
- };
94
+ const rules = {};
95
+ const severity = options.severity ?? RuleConfigSeverity.Error;
96
+ const scopeValues = mergeUnique(asArray(options.values));
97
+ if (scopeValues.length > 0) {
98
+ rules["scope-enum"] = [severity, "always", scopeValues];
99
+ }
100
+ if (options.required !== void 0) {
101
+ if (options.required) {
102
+ rules["scope-empty"] = [severity, "never"];
103
+ } else {
104
+ rules["scope-empty"] = [RuleConfigSeverity.Disabled];
105
+ }
199
106
  }
200
- const definitionsMap = mergeTypeDefinitions(DEFAULT_COMMIT_TYPES, overrides);
201
- const definitions = values.map(
202
- (value) => definitionsMap.get(value) ?? createDefaultCommitTypeDefinition(value)
203
- );
204
- return {
205
- definitions,
206
- rule: [severity, condition, values]
207
- };
208
- }
209
- function asCaseArray(value) {
210
- if (!value) {
211
- return [];
107
+ const scopeCases = mergeUnique(asArray(options.case));
108
+ if (scopeCases.length > 0) {
109
+ rules["scope-case"] = [severity, "always", scopeCases];
212
110
  }
213
- return toArray(value);
111
+ return rules;
214
112
  }
215
- function resolveScopeRules(options) {
113
+ function buildSubjectRules(options) {
216
114
  if (!options) {
217
115
  return {};
218
116
  }
219
117
  const rules = {};
220
- const values = Array.isArray(options) ? unique(options) : unique([
221
- ...toArray(options.values ?? []),
222
- ...toArray(options.add ?? [])
223
- ]);
224
- const baseSeverity = !Array.isArray(options) ? options.severity ?? RuleConfigSeverity.Error : RuleConfigSeverity.Error;
225
- if (values.length > 0) {
226
- rules["scope-enum"] = [baseSeverity, "always", values];
227
- }
228
- const allowEmpty = Array.isArray(options) ? true : options.allowEmpty ?? !options.required;
229
- if (allowEmpty) {
230
- rules["scope-empty"] = [RuleConfigSeverity.Disabled];
231
- } else {
232
- rules["scope-empty"] = [baseSeverity, "never"];
118
+ const forbiddenCases = mergeUnique(asArray(options.forbidden));
119
+ if (forbiddenCases.length > 0) {
120
+ rules["subject-case"] = [
121
+ options.caseSeverity ?? RuleConfigSeverity.Error,
122
+ options.caseCondition ?? "never",
123
+ forbiddenCases
124
+ ];
125
+ }
126
+ if (options.allowEmpty !== void 0) {
127
+ if (options.allowEmpty) {
128
+ rules["subject-empty"] = [RuleConfigSeverity.Disabled];
129
+ } else {
130
+ rules["subject-empty"] = [
131
+ options.allowEmptySeverity ?? RuleConfigSeverity.Error,
132
+ "never"
133
+ ];
134
+ }
233
135
  }
234
- if (!Array.isArray(options) && options.case) {
235
- const scopeCaseValues = asCaseArray(options.case);
236
- if (scopeCaseValues.length > 0) {
237
- const caseSeverity = options.caseSeverity ?? baseSeverity;
238
- rules["scope-case"] = [caseSeverity, "always", scopeCaseValues];
136
+ if (options.fullStop !== void 0) {
137
+ if (options.fullStop) {
138
+ rules["subject-full-stop"] = [
139
+ options.fullStopSeverity ?? RuleConfigSeverity.Error,
140
+ "always",
141
+ options.fullStopCharacter ?? "."
142
+ ];
143
+ } else {
144
+ rules["subject-full-stop"] = [RuleConfigSeverity.Disabled];
239
145
  }
240
146
  }
241
147
  return rules;
242
148
  }
243
- function resolveSubjectRules(options) {
244
- const rules = {};
245
- const forbiddenCases = asCaseArray(options?.forbidden);
246
- const subjectCases = forbiddenCases.length > 0 ? forbiddenCases : DEFAULT_SUBJECT_FORBIDDEN_CASES;
247
- const caseSeverity = options?.caseSeverity ?? RuleConfigSeverity.Error;
248
- rules["subject-case"] = [caseSeverity, "never", subjectCases];
249
- if (options?.allowEmpty) {
250
- rules["subject-empty"] = [RuleConfigSeverity.Disabled];
251
- } else {
252
- const emptySeverity = options?.emptySeverity ?? RuleConfigSeverity.Error;
253
- rules["subject-empty"] = [emptySeverity, "never"];
149
+ function buildHeaderRules(options) {
150
+ if (!options) {
151
+ return {};
254
152
  }
255
- if (options?.fullStop === false) {
256
- rules["subject-full-stop"] = [RuleConfigSeverity.Disabled];
257
- } else {
258
- const fullStopSeverity = options?.fullStopSeverity ?? RuleConfigSeverity.Error;
259
- const fullStop = options?.fullStop ?? DEFAULT_FULL_STOP;
260
- rules["subject-full-stop"] = [fullStopSeverity, "never", fullStop];
153
+ const rules = {};
154
+ const severity = options.severity ?? RuleConfigSeverity.Error;
155
+ const condition = options.condition ?? "always";
156
+ if (options.maxLength !== void 0) {
157
+ rules["header-max-length"] = [severity, condition, options.maxLength];
261
158
  }
262
159
  return rules;
263
160
  }
264
- function resolveHeaderRules(options) {
265
- const severity = options?.severity ?? RuleConfigSeverity.Error;
266
- const maxLength = options?.maxLength ?? DEFAULT_HEADER_MAX_LENGTH;
267
- return {
268
- "header-max-length": [severity, "always", maxLength]
269
- };
270
- }
271
- function createBaseRules() {
272
- return {
273
- "body-leading-blank": [RuleConfigSeverity.Warning, "always"],
274
- "body-max-line-length": [
275
- RuleConfigSeverity.Error,
276
- "always",
277
- DEFAULT_BODY_MAX_LINE_LENGTH
278
- ],
279
- "footer-leading-blank": [RuleConfigSeverity.Warning, "always"],
280
- "footer-max-line-length": [
281
- RuleConfigSeverity.Error,
282
- "always",
283
- DEFAULT_FOOTER_MAX_LINE_LENGTH
284
- ],
285
- "header-trim": [RuleConfigSeverity.Error, "always"],
286
- "type-case": [RuleConfigSeverity.Error, "always", "lower-case"],
287
- "type-empty": [RuleConfigSeverity.Error, "never"]
288
- };
289
- }
290
- function buildTypeEnum(definitions) {
291
- return definitions.reduce(
292
- (accumulator, definition) => {
293
- accumulator[definition.value] = {
294
- description: definition.description,
295
- title: definition.title,
296
- emoji: definition.emoji
297
- };
298
- return accumulator;
299
- },
300
- {}
301
- );
302
- }
303
- function createBasePrompt(definitions) {
161
+ function mergePrompts(base, override) {
162
+ if (!base && !override) {
163
+ return void 0;
164
+ }
165
+ if (!base) {
166
+ return override;
167
+ }
168
+ if (!override) {
169
+ return base;
170
+ }
304
171
  return {
172
+ ...base,
173
+ ...override,
305
174
  questions: {
306
- type: {
307
- description: DEFAULT_PROMPT_TYPE_DESCRIPTION,
308
- enum: buildTypeEnum(definitions)
309
- },
310
- scope: {
311
- description: DEFAULT_PROMPT_SCOPE_DESCRIPTION
312
- },
313
- subject: {
314
- description: DEFAULT_PROMPT_SUBJECT_DESCRIPTION
315
- },
316
- body: {
317
- description: DEFAULT_PROMPT_BODY_DESCRIPTION
318
- },
319
- isBreaking: {
320
- description: DEFAULT_PROMPT_IS_BREAKING_DESCRIPTION
321
- },
322
- breakingBody: {
323
- description: DEFAULT_PROMPT_BREAKING_BODY_DESCRIPTION
324
- },
325
- breaking: {
326
- description: DEFAULT_PROMPT_BREAKING_DESCRIPTION
327
- },
328
- isIssueAffected: {
329
- description: DEFAULT_PROMPT_IS_ISSUE_AFFECTED_DESCRIPTION
330
- },
331
- issuesBody: {
332
- description: DEFAULT_PROMPT_ISSUES_BODY_DESCRIPTION
333
- },
334
- issues: {
335
- description: DEFAULT_PROMPT_ISSUES_DESCRIPTION
336
- }
175
+ ...base.questions ?? {},
176
+ ...override.questions ?? {}
337
177
  }
338
178
  };
339
179
  }
340
- function resolvePrompt(definitions, overrides) {
341
- const base = createBasePrompt(definitions);
342
- return mergeDeep(base, overrides);
343
- }
344
180
  function createIcebreakerCommitlintConfig(options = {}) {
345
- const extendsField = resolveExtends(options.extends);
346
- const typeSettings = resolveTypeSettings(options.types);
347
- const scopeRules = resolveScopeRules(options.scopes);
348
- const subjectRules = resolveSubjectRules(options.subject);
349
- const headerRules = resolveHeaderRules(options.header);
350
- const baseRules = createBaseRules();
181
+ const { types, scopes, subject, header } = options;
182
+ const extendsList = mergeUnique([
183
+ ...DEFAULT_EXTENDS,
184
+ ...mergeUnique(options.extends ?? [])
185
+ ]);
351
186
  const rules = {
352
- ...baseRules,
353
- "type-enum": typeSettings.rule,
354
- ...scopeRules,
355
- ...subjectRules,
356
- ...headerRules,
357
- ...options.rules
187
+ ...buildScopeRules(scopes),
188
+ ...buildSubjectRules(subject),
189
+ ...buildHeaderRules(header)
190
+ };
191
+ const typesConfig = buildTypesConfig(types);
192
+ if (typesConfig.rule) {
193
+ rules["type-enum"] = typesConfig.rule;
194
+ }
195
+ const mergedRules = {
196
+ ...rules,
197
+ ...options.rules ?? {}
198
+ };
199
+ const hasRules = Object.keys(mergedRules).length > 0;
200
+ const prompt = mergePrompts(typesConfig.prompt, options.prompt);
201
+ return {
202
+ extends: extendsList,
203
+ parserPreset: DEFAULT_PARSER_PRESET,
204
+ ...hasRules ? { rules: mergedRules } : {},
205
+ ...prompt ? { prompt } : {}
358
206
  };
359
- const prompt = resolvePrompt(typeSettings.definitions, options.prompt);
360
- return removeUndefined({
361
- extends: extendsField,
362
- formatter: options.formatter,
363
- parserPreset: options.parserPreset ?? DEFAULT_PARSER_PRESET,
364
- rules,
365
- ignores: options.ignores,
366
- defaultIgnores: options.defaultIgnores,
367
- plugins: options.plugins,
368
- helpUrl: options.helpUrl,
369
- prompt
370
- });
371
- }
372
-
373
- // src/index.ts
374
- import { RuleConfigCondition, RuleConfigSeverity as RuleConfigSeverity2, TargetCaseType } from "@commitlint/types";
375
- function createCommitlintConfig(options) {
376
- return createIcebreakerCommitlintConfig(options);
377
- }
378
- function icebreaker(options) {
379
- return createIcebreakerCommitlintConfig(options);
380
207
  }
381
208
  export {
382
- DEFAULT_COMMIT_TYPES,
383
- DEFAULT_EXTENDS,
384
- DEFAULT_SUBJECT_FORBIDDEN_CASES,
385
- DEFAULT_TYPES,
386
- RuleConfigCondition,
387
- RuleConfigSeverity2 as RuleConfigSeverity,
388
- TargetCaseType,
389
- createCommitlintConfig,
390
- createIcebreakerCommitlintConfig,
391
- icebreaker
209
+ RuleConfigSeverity,
210
+ createIcebreakerCommitlintConfig
392
211
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@icebreakers/commitlint-config",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "description": "icebreaker's commitlint config",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",