diff --git a/README.md b/README.md index ae22e80..36ff414 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,28 @@ dart pub add --dev commitlint_cli ### Configuration ```bash -# Configure commitlint to use conventional config +# Simply use configuration of a package echo "include: package:commitlint_cli/commitlint.yaml" > commitlint.yaml ``` +You can also customize your configuration in `commitlint.yaml` +```yaml +# Inherit configuration of a package +include: package:commitlint_cli/commitlint.yaml + +# Custom rules +rules: + type-case: + - 2 + - always + - 'upper-case' + +# Whether commitlint uses the default ignore rules. +defaultIgnores: true +# Pattern that matches commit message if commitlint should ignore the given message. +ignores: + - r'^fixup' +``` + ### Test diff --git a/lib/src/is_ignored.dart b/lib/src/is_ignored.dart new file mode 100644 index 0000000..71c64f6 --- /dev/null +++ b/lib/src/is_ignored.dart @@ -0,0 +1,22 @@ +bool isIgnored(String message, + {bool? defaultIgnores, Iterable? ignores}) { + final base = defaultIgnores == false ? [] : wildcards; + return [...base, ...?ignores?.map(ignore)].any((mathcer) => mathcer(message)); +} + +final wildcards = [ + ignore( + r'((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)'), + ignore(r'(Merge tag (.*?))(?:\r?\n)*$'), + ignore(r'(R|r)evert (.*)'), + ignore(r'(fixup|squash)!'), + ignore(r'(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))'), + ignore(r'Merge remote-tracking branch(\s*)(.*)'), + ignore(r'Automatic merge(.*)'), + ignore(r'Auto-merged (.*?) into (.*)'), +]; + +Matcher ignore(String pattern) => + (String message) => RegExp(pattern).hasMatch(message); + +typedef Matcher = bool Function(String); diff --git a/lib/src/lint.dart b/lib/src/lint.dart index bf6d134..77873d7 100644 --- a/lib/src/lint.dart +++ b/lib/src/lint.dart @@ -1,3 +1,4 @@ +import 'is_ignored.dart'; import 'parse.dart'; import 'rules.dart'; import 'types/commit.dart'; @@ -7,12 +8,18 @@ import 'types/rule.dart'; /// /// Lint commit [message] with configured [rules] /// -Future lint(String message, Map rules) async { - // Parse the commit message +Future lint(String message, Map rules, + {bool? defaultIgnores, Iterable? ignores}) async { + /// Found a wildcard match, skip + if (isIgnored(message, defaultIgnores: defaultIgnores, ignores: ignores)) { + return LintOutcome(input: message, valid: true, errors: [], warnings: []); + } + + /// Parse the commit message final commit = message.isEmpty ? Commit.empty() : parse(message); if (commit.header.isEmpty && commit.body == null && commit.footer == null) { - // Commit is empty, skip + /// Commit is empty, skip return LintOutcome(input: message, valid: true, errors: [], warnings: []); } final allRules = Map.of(supportedRules); @@ -22,13 +29,13 @@ Future lint(String message, Map rules) async { if (missing.isNotEmpty) { final names = [...allRules.keys]; throw RangeError( - 'Found invalid rule names: ${missing.join(', ')}. Supported rule names are: ${names.join(', ')}'); + 'Found invalid rule names: ${missing.join(', ')}. \nSupported rule names are: ${names.join(', ')}'); } /// Validate against all rules final results = rules.entries // Level 0 rules are ignored - .where((entry) => entry.value.severity != RuleConfigSeverity.ignore) + .where((entry) => entry.value.severity != RuleSeverity.ignore) .map((entry) { final name = entry.key; final config = entry.value; @@ -49,9 +56,9 @@ Future lint(String message, Map rules) async { .where((outcome) => !outcome.valid) .toList(); final errors = - results.where((element) => element.level == RuleConfigSeverity.error); + results.where((element) => element.level == RuleSeverity.error); final warnings = - results.where((element) => element.level == RuleConfigSeverity.warning); + results.where((element) => element.level == RuleSeverity.warning); return LintOutcome( input: message, valid: errors.isEmpty, diff --git a/lib/src/load.dart b/lib/src/load.dart index 13e5316..307fd2f 100644 --- a/lib/src/load.dart +++ b/lib/src/load.dart @@ -5,50 +5,47 @@ import 'package:path/path.dart'; import 'package:yaml/yaml.dart'; import 'types/case.dart'; +import 'types/commitlint.dart'; import 'types/rule.dart'; /// -/// Load configured rules in given [file] from given [dir]. +/// Load configured rules in given [path] from given [directory]. /// -Future> load({ - required String file, - String? dir, +Future load( + String path, { + Directory? directory, }) async { - Map rules = {}; - Uri? uri; - if (!file.startsWith('package:')) { - uri = toUri(join(dir ?? Directory.current.path, file)); - dir = dirname(uri.path); + File? file; + if (!path.startsWith('package:')) { + final uri = toUri(join(directory?.path ?? Directory.current.path, path)); + file = File.fromUri(uri); } else { - uri = await Isolate.resolvePackageUri(Uri.parse(file)); - dir = uri?.path.split('/lib/').first; + final uri = await Isolate.resolvePackageUri(Uri.parse(path)); + if (uri != null) { + file = File.fromUri(uri); + } } - if (uri != null) { - final file = File.fromUri(uri); - if (await file.exists()) { - final yaml = loadYaml(await file.readAsString()); - final include = yaml?['include'] as String?; - final rulesMap = yaml?['rules'] as Map?; - if (rulesMap != null) { - for (var entry in rulesMap.entries) { - rules[entry.key] = _extractRuleConfig(entry.value); - } - } - if (include != null) { - final upstream = await load(dir: dir, file: include); - if (upstream.isNotEmpty) { - rules = { - ...upstream, - ...rules, - }; - } - } + if (file != null && file.existsSync()) { + final yaml = loadYaml(await file.readAsString()); + final include = yaml?['include'] as String?; + final rules = yaml?['rules'] as YamlMap?; + final ignores = yaml?['ignores'] as YamlList?; + final defaultIgnores = yaml?['defaultIgnores'] as bool?; + final config = CommitLint( + rules: rules?.map((key, value) => MapEntry(key, _extractRule(value))) ?? + {}, + ignores: ignores?.cast(), + defaultIgnores: defaultIgnores); + if (include != null) { + final upstream = await load(include, directory: file.parent); + return config.inherit(upstream); } + return config; } - return rules; + return CommitLint(); } -RuleConfig _extractRuleConfig(dynamic config) { +Rule _extractRule(dynamic config) { if (config is! List) { throw Exception('rule config must be list, but get $config'); } @@ -56,17 +53,17 @@ RuleConfig _extractRuleConfig(dynamic config) { throw Exception( 'rule config must contain at least two, at most three items.'); } - final severity = _extractRuleConfigSeverity(config.first as int); - final condition = _extractRuleConfigCondition(config.elementAt(1) as String); + final severity = _extractRuleSeverity(config.first as int); + final condition = _extractRuleCondition(config.elementAt(1) as String); dynamic value; if (config.length == 3) { value = config.last; } if (value == null) { - return RuleConfig(severity: severity, condition: condition); + return Rule(severity: severity, condition: condition); } if (value is num) { - return LengthRuleConfig( + return LengthRule( severity: severity, condition: condition, length: value, @@ -74,13 +71,13 @@ RuleConfig _extractRuleConfig(dynamic config) { } if (value is String) { if (value.endsWith('-case')) { - return CaseRuleConfig( + return CaseRule( severity: severity, condition: condition, type: _extractCase(value), ); } else { - return ValueRuleConfig( + return ValueRule( severity: severity, condition: condition, value: value, @@ -88,34 +85,34 @@ RuleConfig _extractRuleConfig(dynamic config) { } } if (value is List) { - return EnumRuleConfig( + return EnumRule( severity: severity, condition: condition, allowed: value.cast(), ); } - return ValueRuleConfig( + return ValueRule( severity: severity, condition: condition, value: value, ); } -RuleConfigSeverity _extractRuleConfigSeverity(int severity) { - if (severity < 0 || severity > RuleConfigSeverity.values.length - 1) { +RuleSeverity _extractRuleSeverity(int severity) { + if (severity < 0 || severity > RuleSeverity.values.length - 1) { throw Exception( - 'rule severity can only be 0..${RuleConfigSeverity.values.length - 1}'); + 'rule severity can only be 0..${RuleSeverity.values.length - 1}'); } - return RuleConfigSeverity.values[severity]; + return RuleSeverity.values[severity]; } -RuleConfigCondition _extractRuleConfigCondition(String condition) { - var allowed = RuleConfigCondition.values.map((e) => e.name).toList(); +RuleCondition _extractRuleCondition(String condition) { + var allowed = RuleCondition.values.map((e) => e.name).toList(); final index = allowed.indexOf(condition); if (index == -1) { throw Exception('rule condition can only one of $allowed'); } - return RuleConfigCondition.values[index]; + return RuleCondition.values[index]; } Case _extractCase(String name) { diff --git a/lib/src/rules.dart b/lib/src/rules.dart index da7b392..8134d02 100644 --- a/lib/src/rules.dart +++ b/lib/src/rules.dart @@ -3,7 +3,7 @@ import 'types/case.dart'; import 'types/commit.dart'; import 'types/rule.dart'; -Map get supportedRules => { +Map get supportedRules => { 'type-case': caseRule(CommitComponent.type), 'type-empty': emptyRule(CommitComponent.type), 'type-enum': enumRule(CommitComponent.type), @@ -39,14 +39,14 @@ Map get supportedRules => { }; /// Build full stop rule for commit component. -Rule fullStopRule(CommitComponent component) { - return (Commit commit, RuleConfig config) { - if (config is! ValueRuleConfig) { +RuleFunction fullStopRule(CommitComponent component) { + return (Commit commit, Rule config) { + if (config is! ValueRule) { throw Exception('$config is not ValueRuleConfig'); } final raw = commit.componentRaw(component); final result = raw != null && ensureFullStop(raw, config.value); - final negated = config.condition == RuleConfigCondition.never; + final negated = config.condition == RuleCondition.never; return RuleOutcome( valid: negated ? !result : result, message: [ @@ -59,11 +59,11 @@ Rule fullStopRule(CommitComponent component) { } /// Build leanding blank rule for commit component. -Rule leadingBlankRule(CommitComponent component) { - return (Commit commit, RuleConfig config) { +RuleFunction leadingBlankRule(CommitComponent component) { + return (Commit commit, Rule config) { final raw = commit.componentRaw(component); final result = raw != null && ensureLeadingBlank(raw); - final negated = config.condition == RuleConfigCondition.never; + final negated = config.condition == RuleCondition.never; return RuleOutcome( valid: negated ? !result : result, message: [ @@ -76,11 +76,11 @@ Rule leadingBlankRule(CommitComponent component) { } /// Build leanding blank rule for commit component. -Rule emptyRule(CommitComponent component) { - return (Commit commit, RuleConfig config) { +RuleFunction emptyRule(CommitComponent component) { + return (Commit commit, Rule config) { final raw = commit.componentRaw(component); final result = ensureEmpty(raw); - final negated = config.condition == RuleConfigCondition.never; + final negated = config.condition == RuleCondition.never; return RuleOutcome( valid: negated ? !result : result, message: @@ -90,14 +90,14 @@ Rule emptyRule(CommitComponent component) { } /// Build case rule for commit component. -Rule caseRule(CommitComponent component) { - return (Commit commit, RuleConfig config) { - if (config is! CaseRuleConfig) { +RuleFunction caseRule(CommitComponent component) { + return (Commit commit, Rule config) { + if (config is! CaseRule) { throw Exception('$config is not CaseRuleConfig'); } final raw = commit.componentRaw(component); final result = raw != null && ensureCase(raw, config.type); - final negated = config.condition == RuleConfigCondition.never; + final negated = config.condition == RuleCondition.never; return RuleOutcome( valid: negated ? !result : result, message: [ @@ -110,14 +110,14 @@ Rule caseRule(CommitComponent component) { } /// Build max length rule for commit component. -Rule maxLengthRule(CommitComponent component) { - return (Commit commit, RuleConfig config) { - if (config is! LengthRuleConfig) { +RuleFunction maxLengthRule(CommitComponent component) { + return (Commit commit, Rule config) { + if (config is! LengthRule) { throw Exception('$config is not LengthRuleConfig'); } final raw = commit.componentRaw(component); final result = raw != null && ensureMaxLength(raw, config.length); - final negated = config.condition == RuleConfigCondition.never; + final negated = config.condition == RuleCondition.never; return RuleOutcome( valid: negated ? !result : result, message: [ @@ -130,14 +130,14 @@ Rule maxLengthRule(CommitComponent component) { } /// Build max line length rule for commit component. -Rule maxLineLengthRule(CommitComponent component) { - return (Commit commit, RuleConfig config) { - if (config is! LengthRuleConfig) { +RuleFunction maxLineLengthRule(CommitComponent component) { + return (Commit commit, Rule config) { + if (config is! LengthRule) { throw Exception('$config is not LengthRuleConfig'); } final raw = commit.componentRaw(component); final result = raw != null && ensureMaxLineLength(raw, config.length); - final negated = config.condition == RuleConfigCondition.never; + final negated = config.condition == RuleCondition.never; return RuleOutcome( valid: negated ? !result : result, message: [ @@ -150,14 +150,14 @@ Rule maxLineLengthRule(CommitComponent component) { } /// Build min length rule for commit component. -Rule minLengthRule(CommitComponent component) { - return (Commit commit, RuleConfig config) { - if (config is! LengthRuleConfig) { +RuleFunction minLengthRule(CommitComponent component) { + return (Commit commit, Rule config) { + if (config is! LengthRule) { throw Exception('$config is not LengthRuleConfig'); } final raw = commit.componentRaw(component); final result = raw != null && ensureMinLength(raw, config.length); - final negated = config.condition == RuleConfigCondition.never; + final negated = config.condition == RuleCondition.never; return RuleOutcome( valid: negated ? !result : result, message: [ @@ -169,14 +169,14 @@ Rule minLengthRule(CommitComponent component) { }; } -Rule enumRule(CommitComponent component) { - return (Commit commit, RuleConfig config) { - if (config is! EnumRuleConfig) { +RuleFunction enumRule(CommitComponent component) { + return (Commit commit, Rule config) { + if (config is! EnumRule) { throw Exception('$config is not EnumRuleConfig'); } final raw = commit.componentRaw(component); final result = ensureEnum(raw, config.allowed); - final negated = config.condition == RuleConfigCondition.never; + final negated = config.condition == RuleCondition.never; return RuleOutcome( valid: negated ? !result : result, message: [ diff --git a/lib/src/runner.dart b/lib/src/runner.dart index 51202aa..0dfd5c8 100644 --- a/lib/src/runner.dart +++ b/lib/src/runner.dart @@ -44,10 +44,11 @@ class CommitLintRunner extends CommandRunner { bool fromStdin = from == null && to == null && edit == null; final messages = fromStdin ? await _stdin() : await read(from: from, to: to, edit: edit); - final rules = await load(file: topLevelResults['config']); - final results = (await Future.wait( - messages.map((message) async => await lint(message, rules)))); - if (rules.isEmpty) { + 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)))); + if (config.rules.isEmpty) { String input = ''; if (results.isNotEmpty) { input = results.first.input; @@ -58,7 +59,7 @@ class CommitLintRunner extends CommandRunner { valid: false, errors: [ LintRuleOutcome( - level: RuleConfigSeverity.error, + level: RuleSeverity.error, valid: false, name: 'empty-rules', message: [ diff --git a/lib/src/types/commitlint.dart b/lib/src/types/commitlint.dart new file mode 100644 index 0000000..24d351b --- /dev/null +++ b/lib/src/types/commitlint.dart @@ -0,0 +1,25 @@ +import 'rule.dart'; + +class CommitLint { + CommitLint({this.rules = const {}, this.defaultIgnores, this.ignores}); + + final Map rules; + + final bool? defaultIgnores; + + final Iterable? ignores; + + CommitLint inherit(CommitLint other) { + return CommitLint( + rules: { + ...other.rules, + ...rules, + }, + defaultIgnores: defaultIgnores ?? other.defaultIgnores, + ignores: [ + ...?other.ignores, + ...?ignores, + ], + ); + } +} diff --git a/lib/src/types/lint.dart b/lib/src/types/lint.dart index d87f12f..04ac6ec 100644 --- a/lib/src/types/lint.dart +++ b/lib/src/types/lint.dart @@ -26,7 +26,7 @@ class LintRuleOutcome { final bool valid; /// The "severity" of the rule (0 = ignore, 1 = warning, 2 = error) - final RuleConfigSeverity level; + final RuleSeverity level; /// The name of the rule final String name; diff --git a/lib/src/types/rule.dart b/lib/src/types/rule.dart index 902199c..a26ce54 100644 --- a/lib/src/types/rule.dart +++ b/lib/src/types/rule.dart @@ -2,22 +2,22 @@ import 'case.dart'; import 'commit.dart'; /// 0 disables the rule. For 1 it will be considered a warning for 2 an error -enum RuleConfigSeverity { +enum RuleSeverity { ignore, warning, error, } -enum RuleConfigCondition { +enum RuleCondition { always, never, } -class RuleConfig { - final RuleConfigSeverity severity; - final RuleConfigCondition condition; +class Rule { + final RuleSeverity severity; + final RuleCondition condition; - RuleConfig({ + Rule({ required this.severity, required this.condition, }); @@ -30,24 +30,24 @@ class RuleOutcome { RuleOutcome({required this.valid, required this.message}); } -typedef Rule = RuleOutcome Function(Commit, RuleConfig config); +typedef RuleFunction = RuleOutcome Function(Commit, Rule config); -class ValueRuleConfig extends RuleConfig { +class ValueRule extends Rule { final String value; - ValueRuleConfig({ - required RuleConfigSeverity severity, - required RuleConfigCondition condition, + ValueRule({ + required RuleSeverity severity, + required RuleCondition condition, required this.value, }) : super(severity: severity, condition: condition); } -class LengthRuleConfig extends RuleConfig { +class LengthRule extends Rule { final num length; - LengthRuleConfig({ - required RuleConfigSeverity severity, - required RuleConfigCondition condition, + LengthRule({ + required RuleSeverity severity, + required RuleCondition condition, required this.length, }) : super( severity: severity, @@ -55,22 +55,22 @@ class LengthRuleConfig extends RuleConfig { ); } -class EnumRuleConfig extends RuleConfig { +class EnumRule extends Rule { final List allowed; - EnumRuleConfig({ - required RuleConfigSeverity severity, - required RuleConfigCondition condition, + EnumRule({ + required RuleSeverity severity, + required RuleCondition condition, required this.allowed, }) : super(severity: severity, condition: condition); } -class CaseRuleConfig extends RuleConfig { +class CaseRule extends Rule { final Case type; - CaseRuleConfig({ - required RuleConfigSeverity severity, - required RuleConfigCondition condition, + CaseRule({ + required RuleSeverity severity, + required RuleCondition condition, required this.type, }) : super(severity: severity, condition: condition); } diff --git a/test/__fixtures__/include-package.yaml b/test/__fixtures__/include-package.yaml index cd516c3..e84fae3 100644 --- a/test/__fixtures__/include-package.yaml +++ b/test/__fixtures__/include-package.yaml @@ -4,4 +4,7 @@ rules: type-case: - 2 - always - - 'upper-case' \ No newline at end of file + - 'upper-case' + +ignores: + - r'^fixup' \ No newline at end of file diff --git a/test/__fixtures__/include-path.yaml b/test/__fixtures__/include-path.yaml index b6ee1b6..188514c 100644 --- a/test/__fixtures__/include-path.yaml +++ b/test/__fixtures__/include-path.yaml @@ -4,4 +4,8 @@ rules: type-case: - 2 - always - - 'upper-case' \ No newline at end of file + - 'upper-case' + +defaultIgnores: false +ignores: + - r'^fixup' \ No newline at end of file diff --git a/test/format_test.dart b/test/format_test.dart index ad95d4e..a48dc4e 100644 --- a/test/format_test.dart +++ b/test/format_test.dart @@ -16,7 +16,7 @@ void main() { errors: [ LintRuleOutcome( valid: false, - level: RuleConfigSeverity.error, + level: RuleSeverity.error, name: 'error-name', message: 'There was an error', ), @@ -31,7 +31,7 @@ void main() { warnings: [ LintRuleOutcome( valid: false, - level: RuleConfigSeverity.warning, + level: RuleSeverity.warning, name: 'warning-name', message: 'There was a problem', ), diff --git a/test/lint_test.dart b/test/lint_test.dart index 3121b33..debac20 100644 --- a/test/lint_test.dart +++ b/test/lint_test.dart @@ -18,9 +18,9 @@ void main() { test('positive on stub message and adhered rule', () async { final result = await lint('foo: bar', { - 'type-enum': EnumRuleConfig( - severity: RuleConfigSeverity.error, - condition: RuleConfigCondition.always, + 'type-enum': EnumRule( + severity: RuleSeverity.error, + condition: RuleCondition.always, allowed: ['foo'], ), }); @@ -29,9 +29,9 @@ void main() { test('negative on stub message and broken rule', () async { final result = await lint('foo: bar', { - 'type-enum': EnumRuleConfig( - severity: RuleConfigSeverity.error, - condition: RuleConfigCondition.never, + 'type-enum': EnumRule( + severity: RuleSeverity.error, + condition: RuleCondition.never, allowed: ['foo'], ), }); @@ -40,23 +40,55 @@ void main() { test('positive on ignored message and broken rule', () async { final result = await lint('Revert "some bogus commit"', { - 'type-empty': RuleConfig( - severity: RuleConfigSeverity.error, - condition: RuleConfigCondition.never, + 'type-empty': Rule( + severity: RuleSeverity.error, + condition: RuleCondition.never, ), }); - expect(result.valid, false); + expect(result.valid, true); expect(result.input, equals('Revert "some bogus commit"')); }); test('negative on ignored message, disabled ignored messages and broken rule', () async { - final result = await lint('Revert "some bogus commit"', { - 'type-empty': RuleConfig( - severity: RuleConfigSeverity.error, - condition: RuleConfigCondition.never, - ), - }); + final result = await lint( + 'Revert "some bogus commit"', + { + 'type-empty': Rule( + severity: RuleSeverity.error, + condition: RuleCondition.never, + ), + }, + defaultIgnores: false); expect(result.valid, false); }); + + test('positive on custom ignored message and broken rule', () async { + final ignoredMessage = 'some ignored custom message'; + final result = await lint(ignoredMessage, { + 'type-empty': Rule( + severity: RuleSeverity.error, + condition: RuleCondition.never, + ), + }, ignores: [ + ignoredMessage + ]); + expect(result.valid, true); + expect(result.input, equals(ignoredMessage)); + }); + + test('throws for invalid rule names', () async { + await expectLater( + lint('foo', { + 'foo': Rule( + severity: RuleSeverity.error, + condition: RuleCondition.always, + ), + 'bar': Rule( + severity: RuleSeverity.warning, + condition: RuleCondition.never, + ), + }), + throwsRangeError); + }); } diff --git a/test/load_test.dart b/test/load_test.dart index 07e16c2..c34b837 100644 --- a/test/load_test.dart +++ b/test/load_test.dart @@ -5,33 +5,39 @@ import 'package:test/test.dart'; void main() { test('empty should have no rules', () async { - final rules = await load(file: 'test/__fixtures__/empty.yaml'); - expect(rules.isEmpty, true); + final config = await load('test/__fixtures__/empty.yaml'); + expect(config.rules.isEmpty, true); }); test('only `rules` should work', () async { - final rules = await load(file: 'test/__fixtures__/only-rules.yaml'); - expect(rules.isEmpty, false); - expect(rules.keys.length, equals(2)); - expect(rules['type-case'], isA()); - expect(rules['type-enum'], isA()); - expect((rules['type-case'] as CaseRuleConfig).type, Case.lower); - expect((rules['type-enum'] as EnumRuleConfig).allowed, + final config = await load('test/__fixtures__/only-rules.yaml'); + expect(config.rules.isEmpty, false); + expect(config.rules.keys.length, equals(2)); + expect(config.rules['type-case'], isA()); + expect(config.rules['type-enum'], isA()); + expect((config.rules['type-case'] as CaseRule).type, Case.lower); + expect((config.rules['type-enum'] as EnumRule).allowed, equals(['feat', 'fix', 'docs', 'chore'])); + expect(config.defaultIgnores, equals(null)); + expect(config.ignores, equals(null)); }); test('include relative path should work', () async { - final rules = await load(file: 'test/__fixtures__/include-path.yaml'); - expect(rules.isEmpty, false); - expect(rules.keys.length, greaterThan(1)); - expect(rules['type-case'], isA()); - expect(rules['type-enum'], isA()); - expect((rules['type-case'] as CaseRuleConfig).type, Case.upper); + final config = await load('test/__fixtures__/include-path.yaml'); + expect(config.rules.isEmpty, false); + expect(config.rules.keys.length, greaterThan(1)); + expect(config.rules['type-case'], isA()); + expect(config.rules['type-enum'], isA()); + expect((config.rules['type-case'] as CaseRule).type, Case.upper); + expect(config.defaultIgnores, equals(false)); + expect(config.ignores, equals(["r'^fixup'"])); }); test('include package path should work', () async { - final rules = await load(file: 'test/__fixtures__/include-package.yaml'); - expect(rules.isEmpty, false); - expect(rules.keys.length, greaterThan(1)); - expect(rules['type-case'], isA()); - expect(rules['type-enum'], isA()); - expect((rules['type-case'] as CaseRuleConfig).type, Case.upper); + final config = await load('test/__fixtures__/include-package.yaml'); + expect(config.rules.isEmpty, false); + expect(config.rules.keys.length, greaterThan(1)); + expect(config.rules['type-case'], isA()); + expect(config.rules['type-enum'], isA()); + expect((config.rules['type-case'] as CaseRule).type, Case.upper); + expect(config.defaultIgnores, equals(null)); + expect(config.ignores, equals(["r'^fixup'"])); }); }