-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into rule/add-RSPEC-S7091
- Loading branch information
Showing
11 changed files
with
382 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"title": "Non-constant names should comply with a naming convention", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "2min" | ||
}, | ||
"tags": [ | ||
"convention" | ||
], | ||
"defaultSeverity": "Minor", | ||
"ruleSpecification": "RSPEC-7075", | ||
"sqKey": "S7075", | ||
"scope": "All", | ||
"defaultQualityProfiles": ["Sonar way"], | ||
"quickfix": "unknown", | ||
"code": { | ||
"impacts": { | ||
"MAINTAINABILITY": "LOW" | ||
}, | ||
"attribute": "IDENTIFIABLE" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
Non-constant identifiers should be in https://en.wikipedia.org/wiki/Camel_case[lowerCamelCase]. | ||
|
||
== Why is this an issue? | ||
|
||
A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes. | ||
|
||
The goal of a naming convention is to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project. | ||
|
||
Dart recommends using lowerCamelCase for all non-constant identifiers: | ||
|
||
* members of classes and mixins, such as constructors, methods, fields and properties | ||
* top-level functions and variables | ||
* parameters of functions and methods | ||
|
||
This means that the first letter of the identifier is lowercase, and the first letter of each subsequent word is capitalized, using no separators such as `_`. | ||
|
||
The rule doesn't check `enum` values. Those are implicitly defined as constants, but treated separately | ||
|
||
=== What is the potential impact? | ||
|
||
Using the wrong casing can lead to confusion and wrong assumptions about the code. For example naming a top-level function in Pascal Case may mislead the reader to think it's a type, like a class or a mixin. | ||
|
||
== How to fix it | ||
|
||
Rename the identifier to use camel case. | ||
|
||
=== Code examples | ||
|
||
==== Noncompliant code example | ||
|
||
[source,dart,diff-id=1,diff-type=noncompliant] | ||
---- | ||
var ATopLevelVariable = 42; // Noncompliant | ||
void ATopLevelFunction() {} // Noncompliant | ||
class AClass { | ||
void AMemberFunction() {} // Noncompliant | ||
} | ||
---- | ||
|
||
==== Compliant solution | ||
|
||
[source,dart,diff-id=1,diff-type=compliant] | ||
---- | ||
var aTopLevelVariable = 42; | ||
void aTopLevelFunction() {} | ||
class AClass { | ||
void aMemberFunction() {} | ||
} | ||
---- | ||
|
||
== Resources | ||
|
||
=== Documentation | ||
|
||
* Dart Docs - https://dart.dev/tools/linter-rules/non_constant_identifier_names[Linter rules - non_constant_identifier_names] | ||
* Wikipedia - https://en.wikipedia.org/wiki/Camel_case[Camel case] | ||
|
||
=== Related rules | ||
|
||
* S101 - Class names should comply with a naming convention | ||
* S7046 - Extension identifiers should comply with a naming convention | ||
|
||
|
||
ifdef::env-github,rspecator-view[] | ||
|
||
''' | ||
== Implementation Specification | ||
(visible only on this page) | ||
|
||
=== Message | ||
|
||
* The variable name '<identifierName>' isn't a lowerCamelCase identifier. | ||
|
||
=== Highlighting | ||
|
||
The identifier name. If a generic method, the name doesn't include the type parameters. | ||
|
||
''' | ||
== Comments And Links | ||
(visible only on this page) | ||
|
||
endif::env-github,rspecator-view[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"title": "Initialization formals shouldn't be unnecessarily type annotated", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
], | ||
"defaultSeverity": "Minor", | ||
"ruleSpecification": "RSPEC-7096", | ||
"sqKey": "S7096", | ||
"scope": "All", | ||
"defaultQualityProfiles": ["Sonar way"], | ||
"quickfix": "unknown", | ||
"code": { | ||
"impacts": { | ||
"MAINTAINABILITY": "LOW" | ||
}, | ||
"attribute": "CONVENTIONAL" | ||
} | ||
} |
Oops, something went wrong.