Skip to content

Commit 3044918

Browse files
authored
Use const where possible (#68)
1 parent 2b4de41 commit 3044918

10 files changed

+26
-19
lines changed

Diff for: analysis_options.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ linter:
33
rules:
44
- sort_constructors_first
55
- sort_unnamed_constructors_first
6+
- prefer_const_constructors
7+
- prefer_const_declarations
8+
- unnecessary_const

Diff for: lib/src/expression/nodes.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:maybe_just_nothing/maybe_just_nothing.dart';
44
typedef Nodes = Iterable<Node>;
55

66
extension NodesExt on Nodes {
7-
Maybe get asValue => length == 1 ? Just(single.value) : Nothing();
7+
Maybe get asValue => length == 1 ? Just(single.value) : const Nothing();
88

99
bool get asLogical => isNotEmpty;
1010
}

Diff for: lib/src/fun/extra/reverse.dart

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:json_path/fun_sdk.dart';
22

33
/// Reverses the string.
44
class Reverse implements Fun1<Maybe, Maybe> {
5+
const Reverse();
56
@override
67
final name = 'reverse';
78

Diff for: lib/src/fun/extra/siblings.dart

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:json_path/fun_sdk.dart';
22

33
/// Returns all siblings of the given nodes.
44
class Siblings implements Fun1<Nodes, Nodes> {
5+
const Siblings();
56
@override
67
final name = 'siblings';
78

Diff for: lib/src/fun/extra/xor.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'package:json_path/fun_sdk.dart';
22

33
class Xor implements Fun2<bool, bool, bool> {
4+
const Xor();
5+
46
@override
57
final name = 'xor';
68

Diff for: test/cases_test.dart

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ void main() {
88
runTestsInDirectory('test/cases/standard');
99
runTestsInDirectory('test/cases/extra',
1010
parser: JsonPathParser(functions: [
11-
IsArray(),
12-
IsBoolean(),
13-
IsNumber(),
14-
IsObject(),
15-
IsString(),
16-
Reverse(),
17-
Siblings(),
18-
Xor(),
11+
const IsArray(),
12+
const IsBoolean(),
13+
const IsNumber(),
14+
const IsObject(),
15+
const IsString(),
16+
const Reverse(),
17+
const Siblings(),
18+
const Xor(),
1919
]));
2020
}

Diff for: test/expression_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void main() {
99
group('Expression', () {
1010
group('Static', () {
1111
final node = Node('foo');
12-
final s = StaticExpression(Just('bar'));
12+
final s = StaticExpression(const Just('bar'));
1313
final d = Expression((Node n) => Just(n.value));
1414
test('map()', () {
1515
expect(s.map((v) => v.map((v) => '$v!').or('oops')).call(node), 'bar!');

Diff for: test/functions_test.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import 'package:test/test.dart';
88
void main() {
99
final store = jsonDecode(File('test/store.json').readAsStringSync());
1010
final parser = JsonPathParser(functions: [
11-
Reverse(),
12-
Siblings(),
13-
Xor(),
11+
const Reverse(),
12+
const Siblings(),
13+
const Xor(),
1414
]);
1515
group('User-defined functions', () {
1616
test('Fun<Nodes> in Nodes context', () {

Diff for: test/json_path_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:test/test.dart';
44
void main() {
55
group('JSONPath', () {
66
test('toString()', () {
7-
final expr = r'$.foo.bar';
7+
const expr = r'$.foo.bar';
88
expect('${JsonPath(expr)}', equals(expr));
99
});
1010
});

Diff for: test/parser_test.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import 'package:test/test.dart';
1313

1414
void main() {
1515
final parser = JsonPathGrammarDefinition(FunFactory(<Fun>[
16-
Length(),
17-
Count(),
18-
Match(),
19-
Search(),
20-
Value(),
16+
const Length(),
17+
const Count(),
18+
const Match(),
19+
const Search(),
20+
const Value(),
2121
])).build();
2222

2323
group('Parser', () {

0 commit comments

Comments
 (0)