Modify rule S100: LaYC format

This commit is contained in:
Amélie Renard 2023-06-06 17:27:22 +02:00 committed by GitHub
parent a315e5de4c
commit aa331b9b5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 196 additions and 112 deletions

View File

@ -1,4 +1,5 @@
{
"title": "Method names should comply with a naming convention",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "30min"

View File

@ -1,19 +1,19 @@
== Why is this an issue?
include::../description.adoc[]
Shared naming conventions allow teams to collaborate efficiently.
=== Noncompliant code example
This rule raises an issue when a method name does not match a provided regular expression.
With default provided regular expression ``++^([A-Z0-9_]*|[a-z0-9_]*)$++``:
For example, with the default provided regular expression `++^([A-Z0-9_]*|[a-z0-9_]*)$++`, the method:
[source,abap]
----
METHOD MyMethod
METHOD MyMethod "Noncompliant
...
ENDMETHOD.
----
=== Compliant solution
should be renamed to
[source,abap]
----

View File

@ -1,17 +1,13 @@
== Why is this an issue?
include::../rule.adoc[]
include::../description.adoc[]
=== Noncompliant code example
With provided regular expression ``++^[a-z][a-zA-Z0-9_]*$++``:
For example, with the default provided regular expression ``++^[a-z][a-zA-Z0-9_]*$++``, the function:
[source,apex]
----
public void DoSomething(){...}
public void DoSomething(){...} // Noncompliant
----
=== Compliant solution
should be renamed to
[source,apex]
----
@ -26,6 +22,19 @@ ifdef::env-github,rspecator-view[]
include::../message.adoc[]
=== Parameters
.format
****
_STRING_
----
^[a-z][a-zA-Z0-9]*$
----
Regular expression used to check the function names against
****
'''
== Comments And Links
(visible only on this page)

View File

@ -1,6 +1,4 @@
{
"title": "Function names should comply with a naming convention",
"defaultQualityProfiles": [
]
}

View File

@ -1,23 +1,34 @@
== Why is this an issue?
include::../rule.adoc[]
include::../description.adoc[]
=== Noncompliant code example
With default provided regular expression: ``++^[a-z][a-zA-Z0-9]*$++``:
For example, with the default provided regular expression: ``++^[a-z][a-zA-Z0-9]*$++``, the function:
[source,cpp]
----
void DoSomething (void);
void DoSomething(); // Noncompliant
----
=== Compliant solution
should be renamed to
[source,cpp]
----
void doSomething (void);
void doSomething();
----
=== Exceptions
The rule ignores the names of:
* Overriding methods
* Template specializations
* When an interface expects a specific name (e.g., `begin` or `end` for range-based loops, `get<N>` for structural binding, etc.)
* Coroutines (S6193 covers them)
== Resources
=== Related rules
* S6193 - Coroutine names should comply with a naming convention
ifdef::env-github,rspecator-view[]
'''

View File

@ -1,15 +1,17 @@
== Why is this an issue?
Shared naming conventions allow teams to collaborate efficiently. This rule checks whether or not method and property names are PascalCased. To reduce noise, two consecutive upper case characters are allowed unless they form the whole name. So, ``++MyXMethod++`` is compliant, but ``++XM++`` on its own is not.
Shared naming conventions allow teams to collaborate efficiently.
=== Noncompliant code example
This rule raises an issue when a method or a property name is not PascalCased.
For example, the method
[source,csharp]
----
public int doSomething() {...}
public int doSomething() {...} // Noncompliant
----
=== Compliant solution
should be renamed to
[source,csharp]
----
@ -18,19 +20,22 @@ public int DoSomething() {...}
=== Exceptions
* The rule ignores members in types that are marked with ``++ComImportAttribute++`` or ``++InterfaceTypeAttribute++``.
* The rule ignores ``++extern++`` methods.
* The rule allows for two-letter acronyms in which both letters are capitalized, as shown in the following identifier: ``++ExecuteOnUIThread++``.
* Furthermore, when ``++'_'++`` character is found in a name, the camel casing is not enforced.
* The rule ignores members in types marked with `ComImportAttribute` or `InterfaceTypeAttribute`.
* The rule ignores `extern` methods.
* To reduce noise, two consecutive upper-case characters are allowed unless they form the full name. So, `MyXMethod` is compliant, but `XM` is not.
* The camel casing is not enforced when a name contains the ``++'_'++`` character.
[source,csharp]
----
void My_method(){...} // valid
void My_method_(){...} // invalid, leading and trailing underscores are reported
void My_method_(){...} // Noncompliant, leading and trailing underscores are reported
void My_method(){...} // Compliant by exception
----
== Resources
=== Documentation
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/capitalization-conventions[Microsoft Capitalization Conventions]
ifdef::env-github,rspecator-view[]

View File

@ -1 +0,0 @@
Shared naming conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

View File

@ -1,3 +1,2 @@
{
"title": "Function names should comply with a naming convention"
}

View File

@ -1,21 +1,17 @@
== Why is this an issue?
include::../rule.adoc[]
include::../description.adoc[]
=== Noncompliant code example
With default provided regular expression: ^[a-z][a-zA-Z0-9]*$
For example, with the default provided regular expression ``++^[a-z][a-zA-Z0-9]*$++``, the function:
[source,flex]
----
function DoSomething(){...}
function DoSomething(){...} /* Noncompliant */
----
=== Compliant solution
should be renamed to
[source,flex]
----
function doSomething(){...}
function doSomething(){...}
----
ifdef::env-github,rspecator-view[]

View File

@ -1,3 +1,3 @@
{
"title": "Function and method names should comply with a naming convention"
}

View File

@ -1,10 +1,6 @@
== Why is this an issue?
include::../rule.adoc[]
include::../description.adoc[]
=== Noncompliant code example
With default provided regular expression: ``++^(_|[a-zA-Z0-9]+)$++``:
For example, with the default provided regular expression ``++^(_|[a-zA-Z0-9]+)$++``, the function:
[source,go]
----
@ -13,7 +9,7 @@ func execute_all() {
}
----
=== Compliant solution
should be renamed to
[source,go]
----

View File

@ -1,3 +1,3 @@
{
"title": "Method names should comply with a naming convention"
}

View File

@ -1,17 +1,15 @@
== Why is this an issue?
Shared naming conventions allow teams to collaborate efficiently.
Shared naming conventions allow teams to collaborate efficiently. This rule checks that all method names match a provided regular expression.
This rule raises an issue when a method name does not match a provided regular expression.
=== Noncompliant code example
With default provided regular expression ``++^[a-z][a-zA-Z0-9]*$++``:
For example, with the default provided regular expression ``++^[a-z][a-zA-Z0-9]*$++``, the method:
[source,java]
----
public int DoSomething(){...}
public int DoSomething(){...} // Noncompliant
----
=== Compliant solution
should be renamed to
[source,java]
----
@ -20,12 +18,12 @@ public int doSomething(){...}
=== Exceptions
Overriding methods are excluded.
Overriding methods are excluded.
[source,java]
----
@Override
public int Do_Something(){...}
@Override
public int Do_Something(){...} // Compliant by exception
----
ifdef::env-github,rspecator-view[]

View File

@ -1,17 +1,15 @@
== Why is this an issue?
Shared naming conventions allow teams to collaborate efficiently.
include::../description.adoc[]
This rule raises an issue when a function or a method name does not match a provided regular expression.
=== Noncompliant code example
With the default regular expression ``++^[a-z][a-zA-Z0-9]*$++``:
For example, with the default regular expression ``++^[a-z][a-zA-Z0-9]*$++``, the function:
[source,javascript]
----
function DoSomething(){...} // Noncompliant
----
=== Compliant solution
should be renamed to
[source,javascript]
----
@ -20,12 +18,11 @@ function doSomething(){...}
=== Exceptions
This rule ignores React Functional Components, which are JavaScript functions named with a capital letter and returning a React element (JSX syntax).
This rule ignores React Functional Components, JavaScript functions named with a capital letter and returning a React element (JSX syntax).
[source,javascript]
----
function Welcome() {
function Welcome() { // Compliant by exception
const greeting = 'Hello, World!';
// ...

View File

@ -1,3 +1,2 @@
{
}

View File

@ -1,5 +1,19 @@
include::../rule.adoc[]
For example, with the default provided regular expression ``++^[a-zA-Z][a-zA-Z0-9]*$++``, the function:
[source,kotlin]
----
fun _DoSomething() {...} // Noncompliant
----
should be renamed to
[source,kotlin]
----
fun DoSomething() {...}
----
ifdef::env-github,rspecator-view[]
'''
@ -8,6 +22,19 @@ ifdef::env-github,rspecator-view[]
include::../message.adoc[]
=== Parameters
.format
****
_STRING_
----
^[a-zA-Z][a-zA-Z0-9]*$
----
Regular expression used to check the function names against
****
'''
== Comments And Links
(visible only on this page)

View File

@ -1,5 +1,5 @@
{
"title": "Method names should comply with a naming convention",
"title": "Function names should comply with a naming convention",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {

View File

@ -1,6 +1,3 @@
{
"title": "Method and function names should comply with a naming convention",
"defaultQualityProfiles": [
"Sonar way"
]
}

View File

@ -1,21 +1,21 @@
== Why is this an issue?
include::../rule.adoc[]
include::../description.adoc[]
=== Noncompliant code example
With default provided regular expression: ``++^[a-z][a-zA-Z0-9]*$++``:
For example, with the default provided regular expression ``++^[a-z][a-zA-Z0-9]*$++``, the function:
[source,php]
----
function DoSomething(){...}
function DoSomething(){ // Noncompliant
// ...
}
----
=== Compliant solution
should be renamed to
[source,php]
----
function doSomething(){...}
function doSomething(){
// ...
}
----
=== Exceptions
@ -25,13 +25,13 @@ Methods with an ``++@inheritdoc++`` annotation, as well as magic methods (``++__
[source,php]
----
function __construct(){...}
function __destruct(){...}
function __construct(){...} // Compliant by exception
function __destruct(){...} // Compliant by exception
/**
* {@inheritdoc}
*/
function myFunc(){...}
function myFunc(){...} // Compliant by exception
----
ifdef::env-github,rspecator-view[]

View File

@ -1,3 +1,3 @@
{
"title": "Method names should comply with a naming convention"
}

View File

@ -1,19 +1,19 @@
== Why is this an issue?
Sharing some naming conventions is a key point to make it possible for a team to efficiently collaborate. This rule allows to check that all method names match a provided regular expression.
Shared naming conventions allow teams to collaborate efficiently.
=== Noncompliant code example
This rule raises an issue when a method name does not match a provided regular expression.
With default provided regular expression: ``++^[a-z_][a-z0-9_]*$++``
For example, with the default provided regular expression ``++^[a-z_][a-z0-9_]*$++``, the method:
[source,python]
----
class MyClass:
def MyMethod(a,b):
def MyMethod(a,b): # Noncompliant
...
----
=== Compliant solution
should be renamed to
[source,python]
----

View File

@ -1,10 +1,10 @@
== Why is this an issue?
Sharing some naming conventions is a key point to make it possible for a team to efficiently collaborate. This rule allows to check that all subroutine names match a provided regular expression.
Shared naming conventions allow teams to collaborate efficiently.
=== Noncompliant code example
This rule raises an issue when a subroutine name does not match a provided regular expression.
With default provided regular expression ``++^SR[a-zA-Z0-9]*$++``:
For example, with the default provided regular expression ``++^SR[a-zA-Z0-9]*$++``, the following subroutines:
[source,rpg]
----
@ -21,7 +21,7 @@ C ENDSR
/end-free{code}
----
=== Compliant solution
should be renamed to
[source,rpg]
----

View File

@ -1,3 +1,3 @@
{
"title": "Method names should comply with a naming convention"
}

View File

@ -1,4 +1,27 @@
include::../rule.adoc[]
== Why is this an issue?
Shared naming conventions allow teams to collaborate efficiently.
This rule raises an issue when a method name does not match a provided regular expression.
For example, with the default provided regular expression, the following method:
[source,ruby]
----
def methodName # Noncompliant
expr..
end
----
should be renamed to
[source,ruby]
----
def method_name
expr..
end
----
ifdef::env-github,rspecator-view[]
@ -15,7 +38,7 @@ include::../message.adoc[]
_STRING_
----
[a-z_][a-z0-9_]\{2,}$
^(@{0,2}[\da-z_]+[!?=]?)|([*+-/%=!><~]+)|(\[]=?)$
----
Regular expression used to check the function

View File

@ -1,3 +1,5 @@
== Why is this an issue?
include::description.adoc[]
Shared naming conventions allow teams to collaborate efficiently.
This rule raises an issue when a function name does not match a provided regular expression.

View File

@ -1,10 +1,6 @@
== Why is this an issue?
include::../rule.adoc[]
include::../description.adoc[]
=== Noncompliant code example
With default provided regular expression:
For example, with the default provided regular expression ``++^([a-z][a-zA-Z0-9]*+(_[^a-zA-Z0-9]++)?+|[^a-zA-Z0-9]++)$++``, the function:
[source,scala]
----
@ -13,7 +9,7 @@ def DoSomething( ) : Unit = { // Noncompliant
}
----
=== Compliant solution
should be renamed to
[source,scala]
----
@ -30,6 +26,19 @@ ifdef::env-github,rspecator-view[]
include::../message.adoc[]
=== Parameters
.format
****
_STRING_
----
^([a-z][a-zA-Z0-9]*+(_[^a-zA-Z0-9]++)?+|[^a-zA-Z0-9]++)
----
Regular expression used to check the function names against
****
'''
== Comments And Links
(visible only on this page)

View File

@ -1,5 +1,23 @@
include::../rule.adoc[]
For example, with the default provided regular expression ``++^[a-z][a-zA-Z0-9]*$++``, the function:
[source,swift]
----
func DoSomething() { // Noncompliant
// ...
}
----
should be renamed to
[source,swift]
----
func doSomething() {
// ...
}
----
ifdef::env-github,rspecator-view[]
'''