From 0651e593fdd3f9b623bb238f9d15a1899d316c3b Mon Sep 17 00:00:00 2001 From: hyiso Date: Wed, 13 Nov 2024 18:46:23 +0800 Subject: [PATCH] fix: `parserOptions` not passed to `lint`(fix #23) --- lib/src/runner.dart | 11 ++++++--- test/__fixtures__/parser-options.yaml | 34 +++++++++++++++++++++++++++ test/lint_test.dart | 11 +++++++++ test/load_test.dart | 5 ++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 test/__fixtures__/parser-options.yaml diff --git a/lib/src/runner.dart b/lib/src/runner.dart index 0dfd5c8..2ca24f6 100644 --- a/lib/src/runner.dart +++ b/lib/src/runner.dart @@ -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) { diff --git a/test/__fixtures__/parser-options.yaml b/test/__fixtures__/parser-options.yaml new file mode 100644 index 0000000..b0157b4 --- /dev/null +++ b/test/__fixtures__/parser-options.yaml @@ -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 \ No newline at end of file diff --git a/test/lint_test.dart b/test/lint_test.dart index c8b6237..72388c3 100644 --- a/test/lint_test.dart +++ b/test/lint_test.dart @@ -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'; @@ -138,4 +139,14 @@ Signed-off-by: dependabot[bot] 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); + }); } diff --git a/test/load_test.dart b/test/load_test.dart index c34b837..5700365 100644 --- a/test/load_test.dart +++ b/test/load_test.dart @@ -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-'])); + }); }