example.dartdart
// Test cases for binary-expression-operand-order rule
// All lines with violations should have an expectation annotation
void compareWithLiterals() {
if (5 == x) {}
if (null == value) {}
if (true == isActive) {}
if ("test" == name) {}
}
void assertLiteralsFirst() {
assert(42 < count);
assert(0 <= index);
assert(100 > percentage);
}
bool checkValues(int x, String s, bool flag) {
return 10 == x || "hello" == s || false == flag;
}
void testInequality() {
if (5 != x) {}
if (null != value) {}
}
class Validator {
bool isValid(int age, String email) {
return 18 <= age && "example" == email;
}
}
void whileCondition(int count) {
while (0 < count) {
count--;
}
}
int getValue() {
return 5 == null ? 0 : 1;
}
void multipleComparisons(int a, int b, int c) {
if (1 < a && 2 < b && 3 < c) {}
}
Avoid placing literal or constant operand on the left side of a binary expression
4void compareWithLiterals() {
5 if (5 == x) {}
∙
Avoid placing literal or constant operand on the left side of a binary expression
5 if (5 == x) {}
6 if (null == value) {}
∙
Avoid placing literal or constant operand on the left side of a binary expression
6 if (null == value) {}
7 if (true == isActive) {}
∙
Avoid placing literal or constant operand on the left side of a binary expression
7 if (true == isActive) {}
8 if ("test" == name) {}
∙
Avoid placing literal or constant operand on the left side of a binary expression
11void assertLiteralsFirst() {
12 assert(42 < count);
∙
Avoid placing literal or constant operand on the left side of a binary expression
12 assert(42 < count);
13 assert(0 <= index);
∙
Avoid placing literal or constant operand on the left side of a binary expression
13 assert(0 <= index);
14 assert(100 > percentage);
∙
Avoid placing literal or constant operand on the left side of a binary expression
17bool checkValues(int x, String s, bool flag) {
18 return 10 == x || "hello" == s || false == flag;
∙
Avoid placing literal or constant operand on the left side of a binary expression
17bool checkValues(int x, String s, bool flag) {
18 return 10 == x || "hello" == s || false == flag;
∙
Avoid placing literal or constant operand on the left side of a binary expression
17bool checkValues(int x, String s, bool flag) {
18 return 10 == x || "hello" == s || false == flag;
∙
Avoid placing literal or constant operand on the left side of a binary expression
21void testInequality() {
22 if (5 != x) {}
∙
Avoid placing literal or constant operand on the left side of a binary expression
22 if (5 != x) {}
23 if (null != value) {}
∙
Avoid placing literal or constant operand on the left side of a binary expression
27 bool isValid(int age, String email) {
28 return 18 <= age && "example" == email;
∙
Avoid placing literal or constant operand on the left side of a binary expression
27 bool isValid(int age, String email) {
28 return 18 <= age && "example" == email;
∙
Avoid placing literal or constant operand on the left side of a binary expression
32void whileCondition(int count) {
33 while (0 < count) {
∙
Avoid placing literal or constant operand on the left side of a binary expression
38int getValue() {
39 return 5 == null ? 0 : 1;
∙
Avoid placing literal or constant operand on the left side of a binary expression
42void multipleComparisons(int a, int b, int c) {
43 if (1 < a && 2 < b && 3 < c) {}
∙
Avoid placing literal or constant operand on the left side of a binary expression
42void multipleComparisons(int a, int b, int c) {
43 if (1 < a && 2 < b && 3 < c) {}
∙
Avoid placing literal or constant operand on the left side of a binary expression
42void multipleComparisons(int a, int b, int c) {
43 if (1 < a && 2 < b && 3 < c) {}
∙