Skip to content

Commit 37b4469

Browse files
committed
fix: pedantic lints
1 parent ef5ef32 commit 37b4469

File tree

8 files changed

+24
-37
lines changed

8 files changed

+24
-37
lines changed

highlight/analysis_options.yaml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
# Defines a default set of lint rules enforced for
2-
# projects at Google. For details and rationale,
3-
# see https://github.com/dart-lang/pedantic#enabled-lints.
41
include: package:pedantic/analysis_options.yaml
52

6-
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
7-
# Uncomment to specify additional rules.
8-
# linter:
9-
# rules:
10-
# - camel_case_types
11-
12-
analyzer:
13-
# exclude:
14-
# - path/to/excluded/files/**
3+
linter:
4+
rules:
5+
prefer_single_quotes: false

highlight/example/highlight.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:highlight/highlight.dart' show highlight;
22

3-
main() {
3+
void main() {
44
var source = '''main() {
55
print("Hello, World!");
66
}

highlight/example/highlight_core.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:highlight/highlight_core.dart' show highlight;
22
import 'package:highlight/languages/dart.dart';
33

4-
main() {
4+
void main() {
55
var source = '''main() {
66
print("Hello, World!");
77
}

highlight/lib/src/highlight.dart

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import 'mode.dart';
55
import 'result.dart';
66

77
class Highlight {
8-
Map<String, Mode> _languages = {};
9-
Map<String, String> _aliases = {};
8+
final _languages = {}.cast<String, Mode>();
9+
final _aliases = {}.cast<String, String>();
1010
Mode _languageMode;
1111

1212
bool _classNameExists(String className) {
@@ -34,7 +34,7 @@ class Highlight {
3434
);
3535
}
3636

37-
_joinRe(List<String> regexps, String separator) {
37+
String _joinRe(List<String> regexps, String separator) {
3838
var backreferenceRe = r'\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\.';
3939
var numCaptures = 0;
4040
var ret = '';
@@ -73,7 +73,7 @@ class Highlight {
7373
mode.keywords = mode.keywords ?? mode.beginKeywords;
7474

7575
if (mode.keywords != null) {
76-
Map<String, dynamic> compiledKeywords = {};
76+
var compiledKeywords = {}.cast<String, dynamic>();
7777

7878
void _flatten(String className, String str) {
7979
if (_languageMode.case_insensitive == true) {
@@ -107,7 +107,7 @@ class Highlight {
107107
if (mode.beginKeywords != null) {
108108
mode.begin = '\\b(' + mode.beginKeywords.split(' ').join('|') + ')\\b';
109109
}
110-
if (mode.begin == null) mode.begin = r'\B|\b';
110+
mode.begin ??= r'\B|\b';
111111
mode.beginRe = _langRe(mode.begin);
112112
if (mode.endSameAsBegin == true) mode.end = mode.begin;
113113
if (mode.end == null && mode.endsWithParent != true) mode.end = r'\B|\b';
@@ -119,10 +119,8 @@ class Highlight {
119119
}
120120
}
121121
if (mode.illegal != null) mode.illegalRe = _langRe(mode.illegal);
122-
if (mode.relevance == null) mode.relevance = 1;
123-
if (mode.contains == null) {
124-
mode.contains = [];
125-
}
122+
mode.relevance ??= 1;
123+
mode.contains ??= [];
126124

127125
Mode _pointToRef(Mode m) {
128126
if (m.ref != null) {
@@ -141,7 +139,7 @@ class Highlight {
141139
mode.starts = _pointToRef(mode.starts);
142140
}
143141

144-
List<Mode> contains = [];
142+
var contains = [].cast<Mode>();
145143
mode.contains.forEach((c) {
146144
contains.addAll(_expandMode(c.self == true ? mode : c));
147145
});
@@ -273,7 +271,7 @@ class Highlight {
273271
// }
274272

275273
// FIXME: Move inside highlight to use lang reference
276-
_keywordMatch(Mode mode, RegExpMatch match) {
274+
dynamic _keywordMatch(Mode mode, RegExpMatch match) {
277275
var match_str =
278276
langMode.case_insensitive == true ? match[0].toLowerCase() : match[0];
279277
return mode.keywords[match_str];
@@ -282,10 +280,10 @@ class Highlight {
282280
_compileMode(_languageMode);
283281

284282
var top = continuation ?? _languageMode;
285-
Map<String, Mode> continuations = {};
286-
List<Node> children = [];
283+
var continuations = {}.cast<String, Mode>();
284+
var children = [].cast<Node>();
287285
var currentChildren = children;
288-
List<List<Node>> stack = [];
286+
var stack = [].cast<List<Node>>();
289287

290288
void _pop() {
291289
currentChildren = stack.isEmpty ? children : stack.removeLast();
@@ -320,8 +318,8 @@ class Highlight {
320318

321319
var keyword_match;
322320
RegExpMatch match;
323-
List<Node> result = [];
324-
int last_index = 0;
321+
var result = [].cast<Node>();
322+
var last_index = 0;
325323

326324
match = top.lexemesRe.firstMatch(mode_buffer);
327325

@@ -449,7 +447,7 @@ class Highlight {
449447
try {
450448
RegExpMatch match;
451449
int count;
452-
int index = 0;
450+
var index = 0;
453451
// print(value);
454452
while (true) {
455453
match = top.terminators

highlight/lib/src/mode.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Mode {
7373
});
7474

7575
static Mode inherit(Mode a, [Mode b]) {
76-
if (b == null) b = Mode();
76+
b ??= Mode();
7777
return Mode()
7878
..aliases = b.aliases ?? a.aliases
7979
..keywords = b.keywords ?? a.keywords

highlight/lib/src/result.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Result {
2626
String toHtml() {
2727
var str = '';
2828

29-
_traverse(Node node) {
29+
void _traverse(Node node) {
3030
final shouldAddSpan = node.className != null &&
3131
((node.value != null && node.value.isNotEmpty) ||
3232
(node.children != null && node.children.isNotEmpty));

highlight/lib/src/utils.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
///
33
/// RangeError: Value not in range
44
String substring(String input, int startIndex, [int endIndex]) {
5-
if (endIndex == null) {
6-
endIndex = input.length;
7-
}
5+
endIndex ??= input.length;
86

97
if (startIndex > endIndex) {
108
var tmp = startIndex;

highlight/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ environment:
88
sdk: ">=2.3.0 <3.0.0"
99

1010
dev_dependencies:
11-
pedantic: ^1.7.0
11+
pedantic: ^1.9.0
1212
test: ^1.6.0
1313
path: ^1.6.0

0 commit comments

Comments
 (0)