Skip to content

Commit

Permalink
fix: parserOptions not passed to lint(fix #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyky committed Nov 13, 2024
1 parent 3cee793 commit 0651e59
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/src/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ class CommitLintRunner extends CommandRunner {
final messages =
fromStdin ? await _stdin() : await read(from: from, to: to, edit: edit);
final config = await load(topLevelResults['config']);
final results = (await Future.wait(messages.map((message) async =>
await lint(message, config.rules,
defaultIgnores: config.defaultIgnores, ignores: config.ignores))));
final results =
(await Future.wait(messages.map((message) async => await lint(
message,
config.rules,
parserOptions: config.parser,
defaultIgnores: config.defaultIgnores,
ignores: config.ignores,
))));
if (config.rules.isEmpty) {
String input = '';
if (results.isNotEmpty) {
Expand Down
34 changes: 34 additions & 0 deletions test/__fixtures__/parser-options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# https://github.com/hyiso/commitlint/blob/main/lib/commitlint.yaml
include: package:commitlint_cli/commitlint.yaml

# https://github.com/hyiso/commitlint/pull/22
parser:
issuePrefixes:
- "sv-"

# https://hyiso.github.io/commitlint/#/references-rules
rules:
type-enum:
- 2
- always
- - build
- chore
- docs
- feat
- fix
- refactor
- revert
- style
- test
scope-enum:
- 2
- always
- - domain
- infrastructures
- use_cases
- interfaces
- lib
- root
references-empty:
- 2
- never
11 changes: 11 additions & 0 deletions test/lint_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:commitlint_cli/src/lint.dart';
import 'package:commitlint_cli/src/load.dart';
import 'package:commitlint_cli/src/types/rule.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -138,4 +139,14 @@ Signed-off-by: dependabot[bot] <[email protected]>
expect(result.valid, true);
expect(result.input, equals(message));
});

test('should use custom parser options with custom issuePrefixes', () async {
final config = await load('test/__fixtures__/parser-options.yaml');
final result = await lint(
'fix(root): fix commitlint config sv-1',
config.rules,
parserOptions: config.parser,
);
expect(result.valid, true);
});
}
5 changes: 5 additions & 0 deletions test/load_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ void main() {
expect(config.defaultIgnores, equals(null));
expect(config.ignores, equals(["r'^fixup'"]));
});
test('custom parser options should work', () async {
final config = await load('test/__fixtures__/parser-options.yaml');
expect(config.parser, isNotNull);
expect(config.parser!.issuePrefixes, equals(['sv-']));
});
}

0 comments on commit 0651e59

Please sign in to comment.