example.dartdart
// Test cases for double-literal-format rule
// All violations are marked inline below.
// Missing leading zero: `.5` should be `0.5`.
void testMissingLeadingZero() {
final opacity = .5;
final scale = .75;
final threshold = .001;
final value = .999;
}
// Redundant trailing zero: the fractional part has a non-"0" digit, so the
// trailing zero is pure noise (`1.50` → `1.5`), and stripping it keeps a double.
void testRedundantTrailingZero() {
const half = 1.50;
const tenth = 0.50;
final long = 1.230;
final doubled = 1.00;
}
class Animation {
final double speed = .5;
final double curve = .25;
final double trailing = 2.50;
}
double calculateOpacity() {
return .8;
}
void processValues() {
final list = [.1, .2, .3];
final map = {
'x': .5,
'y': 1.50,
};
}
void mathOperations() {
final result = .5 + .25;
final product = 2.50 * .75;
}
bool validateRange(double value) {
return value > .0;
}
void mixedFormats() {
final a = .5;
final c = .125;
}
Double literal shouldn't begin with '.'.
5void testMissingLeadingZero() {
6 final opacity = .5;
∙
Double literal shouldn't begin with '.'.
6 final opacity = .5;
7 final scale = .75;
∙
Double literal shouldn't begin with '.'.
7 final scale = .75;
8 final threshold = .001;
∙
Double literal shouldn't begin with '.'.
8 final threshold = .001;
9 final value = .999;
∙
Double literal shouldn't have a trailing '0'.
14void testRedundantTrailingZero() {
15 const half = 1.50;
∙
Double literal shouldn't have a trailing '0'.
15 const half = 1.50;
16 const tenth = 0.50;
∙
Double literal shouldn't have a trailing '0'.
16 const tenth = 0.50;
17 final long = 1.230;
∙
Double literal shouldn't have a trailing '0'.
17 final long = 1.230;
18 final doubled = 1.00;
∙
Double literal shouldn't begin with '.'.
21class Animation {
22 final double speed = .5;
∙
Double literal shouldn't begin with '.'.
22 final double speed = .5;
23 final double curve = .25;
∙
Double literal shouldn't have a trailing '0'.
23 final double curve = .25;
24 final double trailing = 2.50;
∙
Double literal shouldn't begin with '.'.
27double calculateOpacity() {
28 return .8;
∙
Double literal shouldn't begin with '.'.
31void processValues() {
32 final list = [.1, .2, .3];
∙
Double literal shouldn't begin with '.'.
31void processValues() {
32 final list = [.1, .2, .3];
∙
Double literal shouldn't begin with '.'.
31void processValues() {
32 final list = [.1, .2, .3];
∙
Double literal shouldn't begin with '.'.
33 final map = {
34 'x': .5,
∙
Double literal shouldn't have a trailing '0'.
34 'x': .5,
35 'y': 1.50,
∙
Double literal shouldn't begin with '.'.
39void mathOperations() {
40 final result = .5 + .25;
∙
Double literal shouldn't begin with '.'.
39void mathOperations() {
40 final result = .5 + .25;
∙
Double literal shouldn't have a trailing '0'.
40 final result = .5 + .25;
41 final product = 2.50 * .75;
∙
Double literal shouldn't begin with '.'.
40 final result = .5 + .25;
41 final product = 2.50 * .75;
∙
Double literal shouldn't begin with '.'.
44bool validateRange(double value) {
45 return value > .0;
∙
Double literal shouldn't begin with '.'.
48void mixedFormats() {
49 final a = .5;
∙
Double literal shouldn't begin with '.'.
49 final a = .5;
50 final c = .125;
∙