Skip to content

Commit 0651e59

Browse files
committed
fix: parserOptions not passed to lint(fix #23)
1 parent 3cee793 commit 0651e59

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

lib/src/runner.dart

+8-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ class CommitLintRunner extends CommandRunner {
4545
final messages =
4646
fromStdin ? await _stdin() : await read(from: from, to: to, edit: edit);
4747
final config = await load(topLevelResults['config']);
48-
final results = (await Future.wait(messages.map((message) async =>
49-
await lint(message, config.rules,
50-
defaultIgnores: config.defaultIgnores, ignores: config.ignores))));
48+
final results =
49+
(await Future.wait(messages.map((message) async => await lint(
50+
message,
51+
config.rules,
52+
parserOptions: config.parser,
53+
defaultIgnores: config.defaultIgnores,
54+
ignores: config.ignores,
55+
))));
5156
if (config.rules.isEmpty) {
5257
String input = '';
5358
if (results.isNotEmpty) {

test/__fixtures__/parser-options.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# https://github.com/hyiso/commitlint/blob/main/lib/commitlint.yaml
2+
include: package:commitlint_cli/commitlint.yaml
3+
4+
# https://github.com/hyiso/commitlint/pull/22
5+
parser:
6+
issuePrefixes:
7+
- "sv-"
8+
9+
# https://hyiso.github.io/commitlint/#/references-rules
10+
rules:
11+
type-enum:
12+
- 2
13+
- always
14+
- - build
15+
- chore
16+
- docs
17+
- feat
18+
- fix
19+
- refactor
20+
- revert
21+
- style
22+
- test
23+
scope-enum:
24+
- 2
25+
- always
26+
- - domain
27+
- infrastructures
28+
- use_cases
29+
- interfaces
30+
- lib
31+
- root
32+
references-empty:
33+
- 2
34+
- never

test/lint_test.dart

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:commitlint_cli/src/lint.dart';
2+
import 'package:commitlint_cli/src/load.dart';
23
import 'package:commitlint_cli/src/types/rule.dart';
34
import 'package:test/test.dart';
45

@@ -138,4 +139,14 @@ Signed-off-by: dependabot[bot] <support@github.com>
138139
expect(result.valid, true);
139140
expect(result.input, equals(message));
140141
});
142+
143+
test('should use custom parser options with custom issuePrefixes', () async {
144+
final config = await load('test/__fixtures__/parser-options.yaml');
145+
final result = await lint(
146+
'fix(root): fix commitlint config sv-1',
147+
config.rules,
148+
parserOptions: config.parser,
149+
);
150+
expect(result.valid, true);
151+
});
141152
}

test/load_test.dart

+5
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ void main() {
4040
expect(config.defaultIgnores, equals(null));
4141
expect(config.ignores, equals(["r'^fixup'"]));
4242
});
43+
test('custom parser options should work', () async {
44+
final config = await load('test/__fixtures__/parser-options.yaml');
45+
expect(config.parser, isNotNull);
46+
expect(config.parser!.issuePrefixes, equals(['sv-']));
47+
});
4348
}

0 commit comments

Comments
 (0)