Skip to content

Commit

Permalink
feat: support references-empty rule.(fix #17)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyiso committed Sep 9, 2023
1 parent ca161c9 commit 7b4ce74
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/ensure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool ensureEmpty(dynamic raw) {
if (raw is String) {
return raw.isEmpty;
}
if (raw is Iterable<String>) {
if (raw is Iterable) {
return raw.isEmpty;
}
return false;
Expand Down
1 change: 1 addition & 0 deletions lib/src/rules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Map<String, RuleFunction> get supportedRules => {
'footer-max-length': maxLengthRule(CommitComponent.footer),
'footer-max-line-length': maxLineLengthRule(CommitComponent.footer),
'footer-min-length': minLengthRule(CommitComponent.footer),
'references-empty': emptyRule(CommitComponent.references),
};

/// Build full stop rule for commit component.
Expand Down
3 changes: 3 additions & 0 deletions lib/src/types/commit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Commit {
return body as T?;
case CommitComponent.footer:
return footer as T?;
case CommitComponent.references:
return references as T?;
}
}
}
Expand All @@ -64,6 +66,7 @@ enum CommitComponent {
header,
body,
footer,
references,
}

/// Commit Note
Expand Down
20 changes: 20 additions & 0 deletions test/lint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ void main() {
throwsRangeError);
});

test('succeds for issue', () async {
final result = await lint('somehting #1', {
'references-empty': Rule(
severity: RuleSeverity.error,
condition: RuleCondition.never,
),
});
expect(result.valid, true);
});

test('fails for issue', () async {
final result = await lint('somehting #1', {
'references-empty': Rule(
severity: RuleSeverity.error,
condition: RuleCondition.always,
),
});
expect(result.valid, false);
});

test('positive on multi-line body message', () async {
final message = '''chore(deps): bump commitlint_cli from 0.5.0 to 0.6.0
Bumps [commitlint_cli](https://github.com/hyiso/commitlint) from 0.5.0 to 0.6.0.
Expand Down

0 comments on commit 7b4ce74

Please sign in to comment.