Add missing links for Dart rules
This commit is contained in:
parent
3f0b1782e7
commit
4d8a4567d6
@ -12,7 +12,7 @@ The following noncompliant code:
|
||||
|
||||
[source,dart,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
void f(int x) {
|
||||
void doSomething(int x) {
|
||||
// ...
|
||||
print('debug: $x');
|
||||
// ...
|
||||
@ -61,3 +61,4 @@ void doSomething(int x)
|
||||
|
||||
* OWASP - https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/[Top 10 2021 Category A9 - Security Logging and Monitoring Failures]
|
||||
* OWASP - https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure[Top 10 2017 Category A3 - Sensitive Data Exposure]
|
||||
* Dart Linter - https://dart.dev/tools/linter-rules/avoid_print[Dart Linter - avoid_print]
|
||||
|
@ -28,3 +28,4 @@ void foo() {
|
||||
== Resources
|
||||
|
||||
* https://wiki.sei.cmu.edu/confluence/x/5dUxBQ[CERT, MSC12-C.] - Detect and remove code that has no effect or is never executed
|
||||
* https://dart.dev/tools/diagnostic-messages?utm_source=dartdev&utm_medium=redir&utm_id=diagcode&utm_content=unnecessary_cast#unused_label[Dart Linter - unused label]
|
@ -17,3 +17,6 @@ If the field isn't needed, then remove it.
|
||||
|
||||
If the field was intended to be used, then add the missing code.
|
||||
|
||||
== Resources
|
||||
|
||||
* https://dart.dev/tools/diagnostic-messages?utm_source=dartdev&utm_medium=redir&utm_id=diagcode&utm_content=unnecessary_cast#unused_field[Dart compiler diagnostic - unused field]
|
||||
|
@ -1,17 +1,3 @@
|
||||
{
|
||||
"tags": [
|
||||
"based-on-misra",
|
||||
"cert",
|
||||
"unused"
|
||||
],
|
||||
"defaultQualityProfiles": [
|
||||
"Sonar way"
|
||||
],
|
||||
"securityStandards": {
|
||||
"CERT": [
|
||||
"MSC12-C.",
|
||||
"MSC51-J.",
|
||||
"EXP15-C."
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,31 +6,38 @@ include::../description.adoc[]
|
||||
|
||||
==== Noncompliant code example
|
||||
|
||||
[source,cpp,diff-id=1,diff-type=noncompliant]
|
||||
[source,dart,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
void doSomething() {
|
||||
; // Noncompliant - was used as a kind of TODO marker
|
||||
}
|
||||
----
|
||||
|
||||
if (complicated.expression.foo()); // Noncompliant - the condition doesn't make sense
|
||||
bar();
|
||||
[source,dart,diff-id=2,diff-type=noncompliant]
|
||||
----
|
||||
void f() {
|
||||
if (complicated.expression.foo()); // Noncompliant - the condition doesn't make sense
|
||||
bar();
|
||||
}
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,cpp,diff-id=1,diff-type=compliant]
|
||||
[source,dart,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
void doSomething() {
|
||||
}
|
||||
----
|
||||
|
||||
if (complicated.expression.foo()) {
|
||||
bar();
|
||||
[source,dart,diff-id=2,diff-type=compliant]
|
||||
----
|
||||
void f() {
|
||||
if (complicated.expression.foo()) {
|
||||
bar();
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
== Resources
|
||||
|
||||
=== Documentation
|
||||
|
||||
* https://wiki.sei.cmu.edu/confluence/x/5dUxBQ[CERT, MSC12-C.] - Detect and remove code that has no effect or is never executed
|
||||
* https://wiki.sei.cmu.edu/confluence/x/WtYxBQ[CERT, EXP15-C.] - Do not place a semicolon on the same line as an if, for, or while statement
|
||||
* https://dart.dev/tools/linter-rules/empty_statements[Dart Lint rule]
|
||||
|
@ -23,3 +23,7 @@ will be removed on or after the 4.0.0 release.
|
||||
""")
|
||||
void oldFunction(arg1, arg2) {}
|
||||
----
|
||||
|
||||
== Resources
|
||||
|
||||
* https://dart.dev/tools/linter-rules/provide_deprecation_message[Dart Lint rule]
|
@ -37,6 +37,8 @@ void main(List<String> arguments) {
|
||||
|
||||
== Resources
|
||||
|
||||
* https://dart.dev/tools/diagnostic-messages?utm_source=dartdev&utm_medium=redir&utm_id=diagcode&utm_content=unnecessary_cast#unused_import[Dart compiler diagnostic]
|
||||
|
||||
=== Related rules
|
||||
|
||||
* S1481 - Unused local variables should be removed
|
||||
|
@ -10,51 +10,54 @@ This rule raises an issue when a jump statement (``++break++``, ``++continue++``
|
||||
|
||||
[source,dart]
|
||||
----
|
||||
class BadReturn {
|
||||
double nonCompliantMethod() {
|
||||
try {
|
||||
return 1 / 0;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
return 1.0; // Noncompliant
|
||||
class ReturnInFinally {
|
||||
int nonCompliantMethod(int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
try {
|
||||
functionThrowingException(i);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
return 1; // Noncompliant
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
[source,dart]
|
||||
----
|
||||
class BadContinue {
|
||||
double nonCompliantMethod() {
|
||||
for (var o in [1, 2]) {
|
||||
class ContinueInFinally {
|
||||
int nonCompliantMethod(int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
try {
|
||||
print(o / 0);
|
||||
functionThrowingException(i);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
continue; // Noncompliant
|
||||
}
|
||||
}
|
||||
return 1.0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
[source,dart]
|
||||
----
|
||||
class BadBreak {
|
||||
double nonCompliantMethod() {
|
||||
for (var o in [1, 2]) {
|
||||
class BreakInFinally {
|
||||
int nonCompliantMethod(int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
try {
|
||||
print(o / 0);
|
||||
functionThrowingException(i);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
break; // Noncompliant
|
||||
}
|
||||
}
|
||||
return 1.0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
----
|
||||
@ -65,14 +68,16 @@ class BadBreak {
|
||||
[source,dart]
|
||||
----
|
||||
class Ok {
|
||||
double compliantMethod() {
|
||||
var i = 5;
|
||||
try {
|
||||
i = 1 / 0;
|
||||
} catch (e) {
|
||||
log(e);
|
||||
int nonCompliantMethod(int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
try {
|
||||
functionThrowingException(i);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
----
|
||||
@ -80,5 +85,6 @@ class Ok {
|
||||
|
||||
== Resources
|
||||
|
||||
* https://dart.dev/tools/linter-rules/control_flow_in_finally[Dart Lint rule]
|
||||
* CWE - https://cwe.mitre.org/data/definitions/584[CWE-584 - Return Inside Finally Block]
|
||||
* https://wiki.sei.cmu.edu/confluence/x/BTdGBQ[CERT, ERR04-J.] - Do not complete abruptly from a finally block
|
||||
|
@ -28,3 +28,7 @@ class FirstChildClass extends ParentClass {
|
||||
bool doSomething(){/*...*/} // Compliant
|
||||
}
|
||||
----
|
||||
|
||||
== Resources
|
||||
|
||||
* https://dart.dev/tools/linter-rules/annotate_overrides[Dart Lint rule]
|
@ -15,7 +15,7 @@ There are cases when it is justified because redeclaring the function allows som
|
||||
|
||||
[source,dart,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
class A extends B {
|
||||
class Child extends Parent {
|
||||
@override
|
||||
void foo() {
|
||||
super.foo();
|
||||
@ -27,10 +27,14 @@ class A extends B {
|
||||
|
||||
[source,dart,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
class A extends B {
|
||||
class Child extends Parent {
|
||||
@override
|
||||
void foo() {
|
||||
doSomethingElse();
|
||||
bar();
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
== Resources
|
||||
|
||||
* https://dart.dev/tools/linter-rules/unnecessary_overrides[Dart Linter rule]
|
||||
|
@ -11,12 +11,12 @@ By overriding only one of the two methods with a non-trivial implementation, thi
|
||||
|
||||
[source,dart]
|
||||
----
|
||||
class Bad {
|
||||
class A {
|
||||
final int value;
|
||||
Bad(this.value);
|
||||
A(this.value);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is Bad && other.value == value;
|
||||
bool operator ==(Object other) => other is A && other.value == value;
|
||||
}
|
||||
----
|
||||
|
||||
@ -24,18 +24,18 @@ class Bad {
|
||||
|
||||
[source,dart]
|
||||
----
|
||||
class Better {
|
||||
class A {
|
||||
final int value;
|
||||
Better(this.value);
|
||||
A(this.value);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is Better &&
|
||||
other.runtimeType == runtimeType &&
|
||||
other.value == value;
|
||||
bool operator ==(Object other) => other is A && other.value == value;
|
||||
|
||||
@override
|
||||
int get hashCode => value.hashCode;
|
||||
}
|
||||
----
|
||||
|
||||
== Resources
|
||||
|
||||
* https://dart.dev/tools/linter-rules/unnecessary_overrides[Dart Lint rule]
|
||||
|
@ -1 +1,5 @@
|
||||
include::../rule.adoc[]
|
||||
|
||||
== Resources
|
||||
|
||||
* https://dart.dev/tools/linter-rules/curly_braces_in_flow_control_structures[Dart Lint rule]
|
||||
|
@ -22,3 +22,7 @@ int numberOfMinutes(int hours) {
|
||||
return hours * 60;
|
||||
}
|
||||
----
|
||||
|
||||
== Resources
|
||||
|
||||
* https://dart.dev/tools/linter-rules/curly_braces_in_flow_control_structures[Dart compiler diagnostic]
|
||||
|
@ -17,3 +17,5 @@ oldFunction() // Noncompliant: "oldFunction is deprecated"
|
||||
----
|
||||
|
||||
include::../see.adoc[]
|
||||
|
||||
* https://dart.dev/tools/linter-rules/curly_braces_in_flow_control_structures[Dart Compiler diagnostic]
|
||||
|
@ -32,7 +32,7 @@ an unexpected compile-time type.
|
||||
----
|
||||
void types(num n) {
|
||||
if (n is int) {
|
||||
(n as int).isEven; // Noncompliant: n is already known to be of type int
|
||||
(n as int).isOdd; // Noncompliant: n is already known to be of type int
|
||||
}
|
||||
}
|
||||
----
|
||||
@ -48,7 +48,7 @@ bool f<T>(T a) => a is Object?; // Noncompliant: the type check is always true
|
||||
----
|
||||
void types(num n) {
|
||||
if (n is int) {
|
||||
n.isEven;
|
||||
n.isOdd;
|
||||
}
|
||||
}
|
||||
----
|
||||
@ -63,6 +63,9 @@ bool f<T>(T a) => a is Object;
|
||||
=== Documentation
|
||||
|
||||
* https://dart.dev/language/type-system[Dart type system]
|
||||
* https://dart.dev/tools/diagnostic-messages?utm_source=dartdev&utm_medium=redir&utm_id=diagcode&utm_content=unnecessary_cast#unnecessary_cast[Unnecessary Cast compiler diagnostic]
|
||||
* https://dart.dev/tools/diagnostic-messages?utm_source=dartdev&utm_medium=redir&utm_id=diagcode&utm_content=unnecessary_cast#unnecessary_type_check[Unnecessary Type Check compiler diagnostic]
|
||||
|
||||
|
||||
=== Articles & blog posts
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"quickfix": "covered"
|
||||
|
||||
}
|
||||
|
@ -29,3 +29,8 @@ const hello = 'Hello, world!';
|
||||
const string1 = 'this string contains 2 "double quotes"';
|
||||
const string2 = "this string contains 2 'single quotes'";
|
||||
----
|
||||
|
||||
|
||||
== Resources
|
||||
|
||||
* https://dart.dev/tools/linter-rules/unnecessary_string_escapes[Dart Lint rule]
|
||||
|
Loading…
x
Reference in New Issue
Block a user