Add missing links for Dart rules

This commit is contained in:
Marharyta Nedzelska 2024-07-11 15:00:51 +02:00 committed by Marharyta
parent 3f0b1782e7
commit 4d8a4567d6
17 changed files with 102 additions and 66 deletions

View File

@ -12,7 +12,7 @@ The following noncompliant code:
[source,dart,diff-id=1,diff-type=noncompliant] [source,dart,diff-id=1,diff-type=noncompliant]
---- ----
void f(int x) { void doSomething(int x) {
// ... // ...
print('debug: $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/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] * 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]

View File

@ -28,3 +28,4 @@ void foo() {
== Resources == 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://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]

View File

@ -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. 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]

View File

@ -1,17 +1,3 @@
{ {
"tags": [
"based-on-misra",
"cert",
"unused"
],
"defaultQualityProfiles": [
"Sonar way"
],
"securityStandards": {
"CERT": [
"MSC12-C.",
"MSC51-J.",
"EXP15-C."
]
}
} }

View File

@ -6,31 +6,38 @@ include::../description.adoc[]
==== Noncompliant code example ==== Noncompliant code example
[source,cpp,diff-id=1,diff-type=noncompliant] [source,dart,diff-id=1,diff-type=noncompliant]
---- ----
void doSomething() { void doSomething() {
; // Noncompliant - was used as a kind of TODO marker ; // Noncompliant - was used as a kind of TODO marker
} }
----
if (complicated.expression.foo()); // Noncompliant - the condition doesn't make sense [source,dart,diff-id=2,diff-type=noncompliant]
bar(); ----
void f() {
if (complicated.expression.foo()); // Noncompliant - the condition doesn't make sense
bar();
}
---- ----
==== Compliant solution ==== Compliant solution
[source,cpp,diff-id=1,diff-type=compliant] [source,dart,diff-id=1,diff-type=compliant]
---- ----
void doSomething() { void doSomething() {
} }
----
if (complicated.expression.foo()) { [source,dart,diff-id=2,diff-type=compliant]
bar(); ----
void f() {
if (complicated.expression.foo()) {
bar();
}
} }
---- ----
== Resources == Resources
=== Documentation * https://dart.dev/tools/linter-rules/empty_statements[Dart Lint rule]
* 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

View File

@ -23,3 +23,7 @@ will be removed on or after the 4.0.0 release.
""") """)
void oldFunction(arg1, arg2) {} void oldFunction(arg1, arg2) {}
---- ----
== Resources
* https://dart.dev/tools/linter-rules/provide_deprecation_message[Dart Lint rule]

View File

@ -37,6 +37,8 @@ void main(List<String> arguments) {
== Resources == 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 === Related rules
* S1481 - Unused local variables should be removed * S1481 - Unused local variables should be removed

View File

@ -10,51 +10,54 @@ This rule raises an issue when a jump statement (``++break++``, ``++continue++``
[source,dart] [source,dart]
---- ----
class BadReturn { class ReturnInFinally {
double nonCompliantMethod() { int nonCompliantMethod(int n) {
try { for (int i = 0; i < n; ++i) {
return 1 / 0; try {
} catch (e) { functionThrowingException(i);
print(e); } catch (e) {
} finally { print(e);
return 1.0; // Noncompliant } finally {
return 1; // Noncompliant
}
} }
return 0;
} }
} }
---- ----
[source,dart] [source,dart]
---- ----
class BadContinue { class ContinueInFinally {
double nonCompliantMethod() { int nonCompliantMethod(int n) {
for (var o in [1, 2]) { for (int i = 0; i < n; ++i) {
try { try {
print(o / 0); functionThrowingException(i);
} catch (e) { } catch (e) {
print(e); print(e);
} finally { } finally {
continue; // Noncompliant continue; // Noncompliant
} }
} }
return 1.0; return 0;
} }
} }
---- ----
[source,dart] [source,dart]
---- ----
class BadBreak { class BreakInFinally {
double nonCompliantMethod() { int nonCompliantMethod(int n) {
for (var o in [1, 2]) { for (int i = 0; i < n; ++i) {
try { try {
print(o / 0); functionThrowingException(i);
} catch (e) { } catch (e) {
print(e); print(e);
} finally { } finally {
break; // Noncompliant break; // Noncompliant
} }
} }
return 1.0; return 0;
} }
} }
---- ----
@ -65,14 +68,16 @@ class BadBreak {
[source,dart] [source,dart]
---- ----
class Ok { class Ok {
double compliantMethod() { int nonCompliantMethod(int n) {
var i = 5; for (int i = 0; i < n; ++i) {
try { try {
i = 1 / 0; functionThrowingException(i);
} catch (e) { } catch (e) {
log(e); print(e);
return 1;
}
} }
return i; return 0;
} }
} }
---- ----
@ -80,5 +85,6 @@ class Ok {
== Resources == 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] * 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 * https://wiki.sei.cmu.edu/confluence/x/BTdGBQ[CERT, ERR04-J.] - Do not complete abruptly from a finally block

View File

@ -28,3 +28,7 @@ class FirstChildClass extends ParentClass {
bool doSomething(){/*...*/} // Compliant bool doSomething(){/*...*/} // Compliant
} }
---- ----
== Resources
* https://dart.dev/tools/linter-rules/annotate_overrides[Dart Lint rule]

View File

@ -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] [source,dart,diff-id=1,diff-type=noncompliant]
---- ----
class A extends B { class Child extends Parent {
@override @override
void foo() { void foo() {
super.foo(); super.foo();
@ -27,10 +27,14 @@ class A extends B {
[source,dart,diff-id=1,diff-type=compliant] [source,dart,diff-id=1,diff-type=compliant]
---- ----
class A extends B { class Child extends Parent {
@override @override
void foo() { void foo() {
doSomethingElse(); bar();
} }
} }
---- ----
== Resources
* https://dart.dev/tools/linter-rules/unnecessary_overrides[Dart Linter rule]

View File

@ -11,12 +11,12 @@ By overriding only one of the two methods with a non-trivial implementation, thi
[source,dart] [source,dart]
---- ----
class Bad { class A {
final int value; final int value;
Bad(this.value); A(this.value);
@override @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] [source,dart]
---- ----
class Better { class A {
final int value; final int value;
Better(this.value); A(this.value);
@override @override
bool operator ==(Object other) => bool operator ==(Object other) => other is A && other.value == value;
other is Better &&
other.runtimeType == runtimeType &&
other.value == value;
@override @override
int get hashCode => value.hashCode; int get hashCode => value.hashCode;
} }
---- ----
== Resources
* https://dart.dev/tools/linter-rules/unnecessary_overrides[Dart Lint rule]

View File

@ -1 +1,5 @@
include::../rule.adoc[] include::../rule.adoc[]
== Resources
* https://dart.dev/tools/linter-rules/curly_braces_in_flow_control_structures[Dart Lint rule]

View File

@ -22,3 +22,7 @@ int numberOfMinutes(int hours) {
return hours * 60; return hours * 60;
} }
---- ----
== Resources
* https://dart.dev/tools/linter-rules/curly_braces_in_flow_control_structures[Dart compiler diagnostic]

View File

@ -17,3 +17,5 @@ oldFunction() // Noncompliant: "oldFunction is deprecated"
---- ----
include::../see.adoc[] include::../see.adoc[]
* https://dart.dev/tools/linter-rules/curly_braces_in_flow_control_structures[Dart Compiler diagnostic]

View File

@ -32,7 +32,7 @@ an unexpected compile-time type.
---- ----
void types(num n) { void types(num n) {
if (n is int) { 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) { void types(num n) {
if (n is int) { if (n is int) {
n.isEven; n.isOdd;
} }
} }
---- ----
@ -63,6 +63,9 @@ bool f<T>(T a) => a is Object;
=== Documentation === Documentation
* https://dart.dev/language/type-system[Dart type system] * 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 === Articles & blog posts

View File

@ -1,3 +1,3 @@
{ {
"quickfix": "covered"
} }

View File

@ -29,3 +29,8 @@ const hello = 'Hello, world!';
const string1 = 'this string contains 2 "double quotes"'; const string1 = 'this string contains 2 "double quotes"';
const string2 = "this string contains 2 'single quotes'"; const string2 = "this string contains 2 'single quotes'";
---- ----
== Resources
* https://dart.dev/tools/linter-rules/unnecessary_string_escapes[Dart Lint rule]