Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 85f3e5b

Browse files
committedJul 15, 2023
feat!: support ignores commit messages
1 parent d6fada9 commit 85f3e5b

11 files changed

+210
-152
lines changed
 

‎lib/src/is_ignored.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
bool isIgnored(String message,
2+
{bool? defaultIgnores, Iterable<String>? ignores}) {
3+
final base = defaultIgnores == false ? [] : wildcards;
4+
return [...base, ...?ignores?.map(ignore)].any((mathcer) => mathcer(message));
5+
}
6+
7+
final wildcards = [
8+
ignore(
9+
r'((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)'),
10+
ignore(r'(Merge tag (.*?))(?:\r?\n)*$'),
11+
ignore(r'(R|r)evert (.*)'),
12+
ignore(r'(fixup|squash)!'),
13+
ignore(r'(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))'),
14+
ignore(r'Merge remote-tracking branch(\s*)(.*)'),
15+
ignore(r'Automatic merge(.*)'),
16+
ignore(r'Auto-merged (.*?) into (.*)'),
17+
];
18+
19+
Matcher ignore(String pattern) =>
20+
(String message) => RegExp(pattern).hasMatch(message);
21+
22+
typedef Matcher = bool Function(String);

‎lib/src/lint.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'is_ignored.dart';
12
import 'parse.dart';
23
import 'rules.dart';
34
import 'types/commit.dart';
@@ -7,12 +8,18 @@ import 'types/rule.dart';
78
///
89
/// Lint commit [message] with configured [rules]
910
///
10-
Future<LintOutcome> lint(String message, Map<String, RuleConfig> rules) async {
11-
// Parse the commit message
11+
Future<LintOutcome> lint(String message, Map<String, Rule> rules,
12+
{bool? defaultIgnores, Iterable<String>? ignores}) async {
13+
/// Found a wildcard match, skip
14+
if (isIgnored(message, defaultIgnores: defaultIgnores, ignores: ignores)) {
15+
return LintOutcome(input: message, valid: true, errors: [], warnings: []);
16+
}
17+
18+
/// Parse the commit message
1219
final commit = message.isEmpty ? Commit.empty() : parse(message);
1320

1421
if (commit.header.isEmpty && commit.body == null && commit.footer == null) {
15-
// Commit is empty, skip
22+
/// Commit is empty, skip
1623
return LintOutcome(input: message, valid: true, errors: [], warnings: []);
1724
}
1825
final allRules = Map.of(supportedRules);
@@ -28,7 +35,7 @@ Future<LintOutcome> lint(String message, Map<String, RuleConfig> rules) async {
2835
/// Validate against all rules
2936
final results = rules.entries
3037
// Level 0 rules are ignored
31-
.where((entry) => entry.value.severity != RuleConfigSeverity.ignore)
38+
.where((entry) => entry.value.severity != RuleSeverity.ignore)
3239
.map((entry) {
3340
final name = entry.key;
3441
final config = entry.value;
@@ -49,9 +56,9 @@ Future<LintOutcome> lint(String message, Map<String, RuleConfig> rules) async {
4956
.where((outcome) => !outcome.valid)
5057
.toList();
5158
final errors =
52-
results.where((element) => element.level == RuleConfigSeverity.error);
59+
results.where((element) => element.level == RuleSeverity.error);
5360
final warnings =
54-
results.where((element) => element.level == RuleConfigSeverity.warning);
61+
results.where((element) => element.level == RuleSeverity.warning);
5562
return LintOutcome(
5663
input: message,
5764
valid: errors.isEmpty,

‎lib/src/load.dart

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,117 +5,117 @@ import 'package:path/path.dart';
55
import 'package:yaml/yaml.dart';
66

77
import 'types/case.dart';
8+
import 'types/commitlint.dart';
89
import 'types/rule.dart';
910

1011
///
11-
/// Load configured rules in given [file] from given [dir].
12+
/// Load configured rules in given [path] from given [directory].
1213
///
13-
Future<Map<String, RuleConfig>> load({
14-
required String file,
15-
String? dir,
14+
Future<CommitLint> load(
15+
String path, {
16+
Directory? directory,
1617
}) async {
17-
Map<String, RuleConfig> rules = {};
18-
Uri? uri;
19-
if (!file.startsWith('package:')) {
20-
uri = toUri(join(dir ?? Directory.current.path, file));
21-
dir = dirname(uri.path);
18+
File? file;
19+
if (!path.startsWith('package:')) {
20+
final uri = toUri(join(directory?.path ?? Directory.current.path, path));
21+
file = File.fromUri(uri);
2222
} else {
23-
uri = await Isolate.resolvePackageUri(Uri.parse(file));
24-
dir = uri?.path.split('/lib/').first;
23+
final uri = await Isolate.resolvePackageUri(Uri.parse(path));
24+
if (uri != null) {
25+
file = File.fromUri(uri);
26+
}
2527
}
26-
if (uri != null) {
27-
final file = File.fromUri(uri);
28-
if (await file.exists()) {
29-
final yaml = loadYaml(await file.readAsString());
30-
final include = yaml?['include'] as String?;
31-
final rulesMap = yaml?['rules'] as Map?;
32-
if (rulesMap != null) {
33-
for (var entry in rulesMap.entries) {
34-
rules[entry.key] = _extractRuleConfig(entry.value);
35-
}
36-
}
37-
if (include != null) {
38-
final upstream = await load(dir: dir, file: include);
39-
if (upstream.isNotEmpty) {
40-
rules = {
41-
...upstream,
42-
...rules,
43-
};
44-
}
28+
if (file != null && file.existsSync()) {
29+
final yaml = loadYaml(await file.readAsString());
30+
final include = yaml?['include'] as String?;
31+
final rulesMap = yaml?['rules'] as Map?;
32+
Map<String, Rule> rules = {};
33+
if (rulesMap != null) {
34+
for (var entry in rulesMap.entries) {
35+
rules[entry.key] = _extractRule(entry.value);
4536
}
4637
}
38+
final config = CommitLint(
39+
rules: rules,
40+
deafultIgnores: yaml?['deafultIgnores'] as bool?,
41+
ignores: yaml?['ignores'] as Iterable<String>?);
42+
if (include != null) {
43+
final upstream = await load(include, directory: file.parent);
44+
return config.inherit(upstream);
45+
}
46+
return config;
4747
}
48-
return rules;
48+
return CommitLint();
4949
}
5050

51-
RuleConfig _extractRuleConfig(dynamic config) {
51+
Rule _extractRule(dynamic config) {
5252
if (config is! List) {
5353
throw Exception('rule config must be list, but get $config');
5454
}
5555
if (config.isEmpty || config.length < 2 || config.length > 3) {
5656
throw Exception(
5757
'rule config must contain at least two, at most three items.');
5858
}
59-
final severity = _extractRuleConfigSeverity(config.first as int);
60-
final condition = _extractRuleConfigCondition(config.elementAt(1) as String);
59+
final severity = _extractRuleSeverity(config.first as int);
60+
final condition = _extractRuleCondition(config.elementAt(1) as String);
6161
dynamic value;
6262
if (config.length == 3) {
6363
value = config.last;
6464
}
6565
if (value == null) {
66-
return RuleConfig(severity: severity, condition: condition);
66+
return Rule(severity: severity, condition: condition);
6767
}
6868
if (value is num) {
69-
return LengthRuleConfig(
69+
return LengthRule(
7070
severity: severity,
7171
condition: condition,
7272
length: value,
7373
);
7474
}
7575
if (value is String) {
7676
if (value.endsWith('-case')) {
77-
return CaseRuleConfig(
77+
return CaseRule(
7878
severity: severity,
7979
condition: condition,
8080
type: _extractCase(value),
8181
);
8282
} else {
83-
return ValueRuleConfig(
83+
return ValueRule(
8484
severity: severity,
8585
condition: condition,
8686
value: value,
8787
);
8888
}
8989
}
9090
if (value is List) {
91-
return EnumRuleConfig(
91+
return EnumRule(
9292
severity: severity,
9393
condition: condition,
9494
allowed: value.cast(),
9595
);
9696
}
97-
return ValueRuleConfig(
97+
return ValueRule(
9898
severity: severity,
9999
condition: condition,
100100
value: value,
101101
);
102102
}
103103

104-
RuleConfigSeverity _extractRuleConfigSeverity(int severity) {
105-
if (severity < 0 || severity > RuleConfigSeverity.values.length - 1) {
104+
RuleSeverity _extractRuleSeverity(int severity) {
105+
if (severity < 0 || severity > RuleSeverity.values.length - 1) {
106106
throw Exception(
107-
'rule severity can only be 0..${RuleConfigSeverity.values.length - 1}');
107+
'rule severity can only be 0..${RuleSeverity.values.length - 1}');
108108
}
109-
return RuleConfigSeverity.values[severity];
109+
return RuleSeverity.values[severity];
110110
}
111111

112-
RuleConfigCondition _extractRuleConfigCondition(String condition) {
113-
var allowed = RuleConfigCondition.values.map((e) => e.name).toList();
112+
RuleCondition _extractRuleCondition(String condition) {
113+
var allowed = RuleCondition.values.map((e) => e.name).toList();
114114
final index = allowed.indexOf(condition);
115115
if (index == -1) {
116116
throw Exception('rule condition can only one of $allowed');
117117
}
118-
return RuleConfigCondition.values[index];
118+
return RuleCondition.values[index];
119119
}
120120

121121
Case _extractCase(String name) {

‎lib/src/rules.dart

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'types/case.dart';
33
import 'types/commit.dart';
44
import 'types/rule.dart';
55

6-
Map<String, Rule> get supportedRules => {
6+
Map<String, RuleFunction> get supportedRules => {
77
'type-case': caseRule(CommitComponent.type),
88
'type-empty': emptyRule(CommitComponent.type),
99
'type-enum': enumRule(CommitComponent.type),
@@ -39,14 +39,14 @@ Map<String, Rule> get supportedRules => {
3939
};
4040

4141
/// Build full stop rule for commit component.
42-
Rule fullStopRule(CommitComponent component) {
43-
return (Commit commit, RuleConfig config) {
44-
if (config is! ValueRuleConfig) {
42+
RuleFunction fullStopRule(CommitComponent component) {
43+
return (Commit commit, Rule config) {
44+
if (config is! ValueRule) {
4545
throw Exception('$config is not ValueRuleConfig<String>');
4646
}
4747
final raw = commit.componentRaw(component);
4848
final result = raw != null && ensureFullStop(raw, config.value);
49-
final negated = config.condition == RuleConfigCondition.never;
49+
final negated = config.condition == RuleCondition.never;
5050
return RuleOutcome(
5151
valid: negated ? !result : result,
5252
message: [
@@ -59,11 +59,11 @@ Rule fullStopRule(CommitComponent component) {
5959
}
6060

6161
/// Build leanding blank rule for commit component.
62-
Rule leadingBlankRule(CommitComponent component) {
63-
return (Commit commit, RuleConfig config) {
62+
RuleFunction leadingBlankRule(CommitComponent component) {
63+
return (Commit commit, Rule config) {
6464
final raw = commit.componentRaw(component);
6565
final result = raw != null && ensureLeadingBlank(raw);
66-
final negated = config.condition == RuleConfigCondition.never;
66+
final negated = config.condition == RuleCondition.never;
6767
return RuleOutcome(
6868
valid: negated ? !result : result,
6969
message: [
@@ -76,11 +76,11 @@ Rule leadingBlankRule(CommitComponent component) {
7676
}
7777

7878
/// Build leanding blank rule for commit component.
79-
Rule emptyRule(CommitComponent component) {
80-
return (Commit commit, RuleConfig config) {
79+
RuleFunction emptyRule(CommitComponent component) {
80+
return (Commit commit, Rule config) {
8181
final raw = commit.componentRaw(component);
8282
final result = ensureEmpty(raw);
83-
final negated = config.condition == RuleConfigCondition.never;
83+
final negated = config.condition == RuleCondition.never;
8484
return RuleOutcome(
8585
valid: negated ? !result : result,
8686
message:
@@ -90,14 +90,14 @@ Rule emptyRule(CommitComponent component) {
9090
}
9191

9292
/// Build case rule for commit component.
93-
Rule caseRule(CommitComponent component) {
94-
return (Commit commit, RuleConfig config) {
95-
if (config is! CaseRuleConfig) {
93+
RuleFunction caseRule(CommitComponent component) {
94+
return (Commit commit, Rule config) {
95+
if (config is! CaseRule) {
9696
throw Exception('$config is not CaseRuleConfig');
9797
}
9898
final raw = commit.componentRaw(component);
9999
final result = raw != null && ensureCase(raw, config.type);
100-
final negated = config.condition == RuleConfigCondition.never;
100+
final negated = config.condition == RuleCondition.never;
101101
return RuleOutcome(
102102
valid: negated ? !result : result,
103103
message: [
@@ -110,14 +110,14 @@ Rule caseRule(CommitComponent component) {
110110
}
111111

112112
/// Build max length rule for commit component.
113-
Rule maxLengthRule(CommitComponent component) {
114-
return (Commit commit, RuleConfig config) {
115-
if (config is! LengthRuleConfig) {
113+
RuleFunction maxLengthRule(CommitComponent component) {
114+
return (Commit commit, Rule config) {
115+
if (config is! LengthRule) {
116116
throw Exception('$config is not LengthRuleConfig');
117117
}
118118
final raw = commit.componentRaw(component);
119119
final result = raw != null && ensureMaxLength(raw, config.length);
120-
final negated = config.condition == RuleConfigCondition.never;
120+
final negated = config.condition == RuleCondition.never;
121121
return RuleOutcome(
122122
valid: negated ? !result : result,
123123
message: [
@@ -130,14 +130,14 @@ Rule maxLengthRule(CommitComponent component) {
130130
}
131131

132132
/// Build max line length rule for commit component.
133-
Rule maxLineLengthRule(CommitComponent component) {
134-
return (Commit commit, RuleConfig config) {
135-
if (config is! LengthRuleConfig) {
133+
RuleFunction maxLineLengthRule(CommitComponent component) {
134+
return (Commit commit, Rule config) {
135+
if (config is! LengthRule) {
136136
throw Exception('$config is not LengthRuleConfig');
137137
}
138138
final raw = commit.componentRaw(component);
139139
final result = raw != null && ensureMaxLineLength(raw, config.length);
140-
final negated = config.condition == RuleConfigCondition.never;
140+
final negated = config.condition == RuleCondition.never;
141141
return RuleOutcome(
142142
valid: negated ? !result : result,
143143
message: [
@@ -150,14 +150,14 @@ Rule maxLineLengthRule(CommitComponent component) {
150150
}
151151

152152
/// Build min length rule for commit component.
153-
Rule minLengthRule(CommitComponent component) {
154-
return (Commit commit, RuleConfig config) {
155-
if (config is! LengthRuleConfig) {
153+
RuleFunction minLengthRule(CommitComponent component) {
154+
return (Commit commit, Rule config) {
155+
if (config is! LengthRule) {
156156
throw Exception('$config is not LengthRuleConfig');
157157
}
158158
final raw = commit.componentRaw(component);
159159
final result = raw != null && ensureMinLength(raw, config.length);
160-
final negated = config.condition == RuleConfigCondition.never;
160+
final negated = config.condition == RuleCondition.never;
161161
return RuleOutcome(
162162
valid: negated ? !result : result,
163163
message: [
@@ -169,14 +169,14 @@ Rule minLengthRule(CommitComponent component) {
169169
};
170170
}
171171

172-
Rule enumRule(CommitComponent component) {
173-
return (Commit commit, RuleConfig config) {
174-
if (config is! EnumRuleConfig) {
172+
RuleFunction enumRule(CommitComponent component) {
173+
return (Commit commit, Rule config) {
174+
if (config is! EnumRule) {
175175
throw Exception('$config is not EnumRuleConfig');
176176
}
177177
final raw = commit.componentRaw(component);
178178
final result = ensureEnum(raw, config.allowed);
179-
final negated = config.condition == RuleConfigCondition.never;
179+
final negated = config.condition == RuleCondition.never;
180180
return RuleOutcome(
181181
valid: negated ? !result : result,
182182
message: [

‎lib/src/runner.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ class CommitLintRunner extends CommandRunner {
4444
bool fromStdin = from == null && to == null && edit == null;
4545
final messages =
4646
fromStdin ? await _stdin() : await read(from: from, to: to, edit: edit);
47-
final rules = await load(file: topLevelResults['config']);
48-
final results = (await Future.wait(
49-
messages.map((message) async => await lint(message, rules))));
50-
if (rules.isEmpty) {
47+
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.deafultIgnores, ignores: config.ignores))));
51+
if (config.rules.isEmpty) {
5152
String input = '';
5253
if (results.isNotEmpty) {
5354
input = results.first.input;
@@ -58,7 +59,7 @@ class CommitLintRunner extends CommandRunner {
5859
valid: false,
5960
errors: [
6061
LintRuleOutcome(
61-
level: RuleConfigSeverity.error,
62+
level: RuleSeverity.error,
6263
valid: false,
6364
name: 'empty-rules',
6465
message: [

‎lib/src/types/commitlint.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'rule.dart';
2+
3+
class CommitLint {
4+
CommitLint({this.rules = const {}, this.deafultIgnores, this.ignores});
5+
6+
final Map<String, Rule> rules;
7+
8+
final bool? deafultIgnores;
9+
10+
final Iterable<String>? ignores;
11+
12+
CommitLint inherit(CommitLint other) {
13+
return CommitLint(
14+
rules: {
15+
...other.rules,
16+
...rules,
17+
},
18+
deafultIgnores: other.deafultIgnores ?? deafultIgnores,
19+
ignores: [
20+
...?other.ignores,
21+
...?ignores,
22+
],
23+
);
24+
}
25+
}

‎lib/src/types/lint.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class LintRuleOutcome {
2626
final bool valid;
2727

2828
/// The "severity" of the rule (0 = ignore, 1 = warning, 2 = error)
29-
final RuleConfigSeverity level;
29+
final RuleSeverity level;
3030

3131
/// The name of the rule
3232
final String name;

‎lib/src/types/rule.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ import 'case.dart';
22
import 'commit.dart';
33

44
/// 0 disables the rule. For 1 it will be considered a warning for 2 an error
5-
enum RuleConfigSeverity {
5+
enum RuleSeverity {
66
ignore,
77
warning,
88
error,
99
}
1010

11-
enum RuleConfigCondition {
11+
enum RuleCondition {
1212
always,
1313
never,
1414
}
1515

16-
class RuleConfig {
17-
final RuleConfigSeverity severity;
18-
final RuleConfigCondition condition;
16+
class Rule {
17+
final RuleSeverity severity;
18+
final RuleCondition condition;
1919

20-
RuleConfig({
20+
Rule({
2121
required this.severity,
2222
required this.condition,
2323
});
@@ -30,47 +30,47 @@ class RuleOutcome {
3030
RuleOutcome({required this.valid, required this.message});
3131
}
3232

33-
typedef Rule = RuleOutcome Function(Commit, RuleConfig config);
33+
typedef RuleFunction = RuleOutcome Function(Commit, Rule config);
3434

35-
class ValueRuleConfig extends RuleConfig {
35+
class ValueRule extends Rule {
3636
final String value;
3737

38-
ValueRuleConfig({
39-
required RuleConfigSeverity severity,
40-
required RuleConfigCondition condition,
38+
ValueRule({
39+
required RuleSeverity severity,
40+
required RuleCondition condition,
4141
required this.value,
4242
}) : super(severity: severity, condition: condition);
4343
}
4444

45-
class LengthRuleConfig extends RuleConfig {
45+
class LengthRule extends Rule {
4646
final num length;
4747

48-
LengthRuleConfig({
49-
required RuleConfigSeverity severity,
50-
required RuleConfigCondition condition,
48+
LengthRule({
49+
required RuleSeverity severity,
50+
required RuleCondition condition,
5151
required this.length,
5252
}) : super(
5353
severity: severity,
5454
condition: condition,
5555
);
5656
}
5757

58-
class EnumRuleConfig extends RuleConfig {
58+
class EnumRule extends Rule {
5959
final List<String> allowed;
6060

61-
EnumRuleConfig({
62-
required RuleConfigSeverity severity,
63-
required RuleConfigCondition condition,
61+
EnumRule({
62+
required RuleSeverity severity,
63+
required RuleCondition condition,
6464
required this.allowed,
6565
}) : super(severity: severity, condition: condition);
6666
}
6767

68-
class CaseRuleConfig extends RuleConfig {
68+
class CaseRule extends Rule {
6969
final Case type;
7070

71-
CaseRuleConfig({
72-
required RuleConfigSeverity severity,
73-
required RuleConfigCondition condition,
71+
CaseRule({
72+
required RuleSeverity severity,
73+
required RuleCondition condition,
7474
required this.type,
7575
}) : super(severity: severity, condition: condition);
7676
}

‎test/format_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void main() {
1616
errors: [
1717
LintRuleOutcome(
1818
valid: false,
19-
level: RuleConfigSeverity.error,
19+
level: RuleSeverity.error,
2020
name: 'error-name',
2121
message: 'There was an error',
2222
),
@@ -31,7 +31,7 @@ void main() {
3131
warnings: [
3232
LintRuleOutcome(
3333
valid: false,
34-
level: RuleConfigSeverity.warning,
34+
level: RuleSeverity.warning,
3535
name: 'warning-name',
3636
message: 'There was a problem',
3737
),

‎test/lint_test.dart

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ void main() {
1818

1919
test('positive on stub message and adhered rule', () async {
2020
final result = await lint('foo: bar', {
21-
'type-enum': EnumRuleConfig(
22-
severity: RuleConfigSeverity.error,
23-
condition: RuleConfigCondition.always,
21+
'type-enum': EnumRule(
22+
severity: RuleSeverity.error,
23+
condition: RuleCondition.always,
2424
allowed: ['foo'],
2525
),
2626
});
@@ -29,9 +29,9 @@ void main() {
2929

3030
test('negative on stub message and broken rule', () async {
3131
final result = await lint('foo: bar', {
32-
'type-enum': EnumRuleConfig(
33-
severity: RuleConfigSeverity.error,
34-
condition: RuleConfigCondition.never,
32+
'type-enum': EnumRule(
33+
severity: RuleSeverity.error,
34+
condition: RuleCondition.never,
3535
allowed: ['foo'],
3636
),
3737
});
@@ -40,23 +40,26 @@ void main() {
4040

4141
test('positive on ignored message and broken rule', () async {
4242
final result = await lint('Revert "some bogus commit"', {
43-
'type-empty': RuleConfig(
44-
severity: RuleConfigSeverity.error,
45-
condition: RuleConfigCondition.never,
43+
'type-empty': Rule(
44+
severity: RuleSeverity.error,
45+
condition: RuleCondition.never,
4646
),
4747
});
48-
expect(result.valid, false);
48+
expect(result.valid, true);
4949
expect(result.input, equals('Revert "some bogus commit"'));
5050
});
5151

5252
test('negative on ignored message, disabled ignored messages and broken rule',
5353
() async {
54-
final result = await lint('Revert "some bogus commit"', {
55-
'type-empty': RuleConfig(
56-
severity: RuleConfigSeverity.error,
57-
condition: RuleConfigCondition.never,
58-
),
59-
});
54+
final result = await lint(
55+
'Revert "some bogus commit"',
56+
{
57+
'type-empty': Rule(
58+
severity: RuleSeverity.error,
59+
condition: RuleCondition.never,
60+
),
61+
},
62+
defaultIgnores: false);
6063
expect(result.valid, false);
6164
});
6265
}

‎test/load_test.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@ import 'package:test/test.dart';
55

66
void main() {
77
test('empty should have no rules', () async {
8-
final rules = await load(file: 'test/__fixtures__/empty.yaml');
9-
expect(rules.isEmpty, true);
8+
final config = await load('test/__fixtures__/empty.yaml');
9+
expect(config.rules.isEmpty, true);
1010
});
1111
test('only `rules` should work', () async {
12-
final rules = await load(file: 'test/__fixtures__/only-rules.yaml');
13-
expect(rules.isEmpty, false);
14-
expect(rules.keys.length, equals(2));
15-
expect(rules['type-case'], isA<CaseRuleConfig>());
16-
expect(rules['type-enum'], isA<EnumRuleConfig>());
17-
expect((rules['type-case'] as CaseRuleConfig).type, Case.lower);
18-
expect((rules['type-enum'] as EnumRuleConfig).allowed,
12+
final config = await load('test/__fixtures__/only-rules.yaml');
13+
expect(config.rules.isEmpty, false);
14+
expect(config.rules.keys.length, equals(2));
15+
expect(config.rules['type-case'], isA<CaseRule>());
16+
expect(config.rules['type-enum'], isA<EnumRule>());
17+
expect((config.rules['type-case'] as CaseRule).type, Case.lower);
18+
expect((config.rules['type-enum'] as EnumRule).allowed,
1919
equals(['feat', 'fix', 'docs', 'chore']));
2020
});
2121
test('include relative path should work', () async {
22-
final rules = await load(file: 'test/__fixtures__/include-path.yaml');
23-
expect(rules.isEmpty, false);
24-
expect(rules.keys.length, greaterThan(1));
25-
expect(rules['type-case'], isA<CaseRuleConfig>());
26-
expect(rules['type-enum'], isA<EnumRuleConfig>());
27-
expect((rules['type-case'] as CaseRuleConfig).type, Case.upper);
22+
final config = await load('test/__fixtures__/include-path.yaml');
23+
expect(config.rules.isEmpty, false);
24+
expect(config.rules.keys.length, greaterThan(1));
25+
expect(config.rules['type-case'], isA<CaseRule>());
26+
expect(config.rules['type-enum'], isA<EnumRule>());
27+
expect((config.rules['type-case'] as CaseRule).type, Case.upper);
2828
});
2929
test('include package path should work', () async {
30-
final rules = await load(file: 'test/__fixtures__/include-package.yaml');
31-
expect(rules.isEmpty, false);
32-
expect(rules.keys.length, greaterThan(1));
33-
expect(rules['type-case'], isA<CaseRuleConfig>());
34-
expect(rules['type-enum'], isA<EnumRuleConfig>());
35-
expect((rules['type-case'] as CaseRuleConfig).type, Case.upper);
30+
final config = await load('test/__fixtures__/include-package.yaml');
31+
expect(config.rules.isEmpty, false);
32+
expect(config.rules.keys.length, greaterThan(1));
33+
expect(config.rules['type-case'], isA<CaseRule>());
34+
expect(config.rules['type-enum'], isA<EnumRule>());
35+
expect((config.rules['type-case'] as CaseRule).type, Case.upper);
3636
});
3737
}

0 commit comments

Comments
 (0)
Please sign in to comment.