Skip to content

Commit 6d3dc43

Browse files
committed
feat: use ansi,verbose and remove some deps
1 parent eca1333 commit 6d3dc43

File tree

7 files changed

+31
-37
lines changed

7 files changed

+31
-37
lines changed

Diff for: .husky/commit-msg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
DEBUG=true dart bin/commitlint_cli.dart --edit "$1" --config lib/commitlint.yaml
4+
VERBOSE=true dart bin/commitlint_cli.dart --edit "$1" --config lib/commitlint.yaml

Diff for: README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ echo 'foo: bar' | dart run commitlint_cli
4646
✖ found 1 errors, 0 warnings
4747
```
4848

49+
**Note: output on successful commit will be omitted, you can use the `VERBOSE=true` env to get positive output.** (Functionality of [verbose](https://pub.dev/packages/verbose))
50+
4951
```bash
50-
# Lint last commit from history
51-
commitlint --from=HEAD~1
52+
# Output on successful commit will be omitted
53+
echo 'feat: test message' | dart run commitlint_cli
54+
# Verbse Output on successful commit
55+
echo 'feat: test message' | VERBOSE=true dart run commitlint_cli
5256
```
5357
## Setup git hook
5458

Diff for: bin/commitlint_cli.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:commitlint_cli/commitlint.dart';
1+
import 'package:commitlint_cli/src/runner.dart';
22

33
Future<void> main(List<String> args) async {
44
await CommitLintRunner().run(args);

Diff for: lib/commitlint.dart

-1
This file was deleted.

Diff for: lib/src/format.dart

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import 'dart:io';
2-
3-
import 'package:colorize/colorize.dart';
1+
import 'package:ansi/ansi.dart';
2+
import 'package:verbose/verbose.dart';
43
import 'types/format.dart';
54
import 'types/lint.dart';
65

76
const _kDefaultSigns = [' ', '⚠', '✖'];
8-
final _defaultColors = [Styles.WHITE, Styles.YELLOW, Styles.RED];
9-
final isDebug = Platform.environment['DEBUG'] == 'true';
7+
final _defaultColors = [ansi.white, ansi.yellow, ansi.red];
108

119
///
1210
/// Format commitlint [report] to formatted output message.
@@ -24,30 +22,32 @@ String format({
2422

2523
List<String> _formatInput(LintOutcome result) {
2624
final sign = '⧗';
27-
final decoration = Colorize(sign).darkGray();
25+
final decoration = ansi.gray(sign);
2826
final commitText =
2927
result.errors.isNotEmpty ? result.input : result.input.split('\n').first;
30-
final decoratedInput = Colorize(commitText).bold();
28+
final decoratedInput = ansi.bold(commitText);
3129
final hasProblem = result.errors.isNotEmpty || result.warnings.isNotEmpty;
32-
return hasProblem || isDebug ? ['$decoration input: $decoratedInput'] : [];
30+
return hasProblem || Verbose.enabled
31+
? ['$decoration input: $decoratedInput']
32+
: [];
3333
}
3434

3535
List<String> _formatResult(LintOutcome result) {
3636
final problems = [...result.errors, ...result.warnings].map((problem) {
3737
final sign = _kDefaultSigns[problem.level.index];
3838
final color = _defaultColors[problem.level.index];
39-
final decoration = Colorize().apply(color, sign);
40-
final name = Colorize(problem.name).darkGray();
39+
final decoration = color(sign);
40+
final name = ansi.gray(problem.name);
4141
return '$decoration ${problem.message} $name';
4242
});
4343

4444
final sign = _selectSign(result);
4545
final color = _selectColor(result);
46-
final decoration = Colorize().apply(color, sign);
47-
final summary = problems.isNotEmpty || isDebug
46+
final decoration = color(sign);
47+
final summary = problems.isNotEmpty || Verbose.enabled
4848
? '$decoration found ${result.errors.length} error(s), ${result.warnings.length} warning(s)'
4949
: '';
50-
final fmtSummary = summary.isNotEmpty ? Colorize(summary).bold() : summary;
50+
final fmtSummary = summary.isNotEmpty ? ansi.bold(summary) : summary;
5151
return [
5252
...problems,
5353
if (problems.isNotEmpty) '',
@@ -63,9 +63,9 @@ String _selectSign(LintOutcome result) {
6363
return result.warnings.isNotEmpty ? '⚠' : '✔';
6464
}
6565

66-
Styles _selectColor(LintOutcome result) {
66+
String Function(String) _selectColor(LintOutcome result) {
6767
if (result.errors.isNotEmpty) {
68-
return Styles.RED;
68+
return ansi.red;
6969
}
70-
return result.warnings.isNotEmpty ? Styles.YELLOW : Styles.GREEN;
70+
return result.warnings.isNotEmpty ? ansi.yellow : ansi.green;
7171
}

Diff for: pubspec.yaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ environment:
88
sdk: '>=2.12.0 <3.0.0'
99

1010
dependencies:
11+
ansi: ^0.2.2
1112
args: ^2.3.1
1213
change_case: ^1.0.0+3
13-
colorize: ^3.0.0
1414
path: ^1.8.0
15+
verbose: ^0.1.0
1516
yaml: ^3.1.1
1617

1718
dev_dependencies:
18-
husky: ^0.1.4+2
19-
lint_staged: ^0.2.0-dev.0
19+
husky: ^0.1.6
20+
lint_staged: ^0.2.0
2021
lints: ^2.0.0
2122
test: ^1.21.0
2223
uuid: ^3.0.7
2324

2425
lint_staged:
25-
'lib/**.dart': dart fix --apply && dart format --fix
26+
'**.dart': dart fix --apply && dart format --fix

Diff for: test/utils.dart

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
import 'dart:io';
22
import 'package:path/path.dart';
3-
import 'package:uuid/uuid.dart';
43

5-
var uuid = Uuid();
6-
7-
String tmp({
8-
String prefix = 'tmp',
9-
String? suffix,
10-
}) {
11-
final tmp = Directory.systemTemp.path;
12-
final uid = uuid.v4().replaceAll('-', '');
13-
return join(tmp, prefix, uid,
14-
DateTime.now().millisecondsSinceEpoch.toString(), suffix);
15-
}
4+
String tmp() => join(Directory.systemTemp.path, 'tmp',
5+
'commitlint_test_${DateTime.now().millisecondsSinceEpoch}');
166

177
Future<String> bootstrap([String? fixture, String? directory]) async {
188
final dir = tmp();

0 commit comments

Comments
 (0)