2024-08-27 21:11:28 +02:00
Extension identifier, when present, should be in PascalCase.
== Why is this an issue?
Extensions are a way to add functionality to existing classes. As such, they contain methods, getters, and setters, in the same way classes do.
2024-08-29 18:49:45 +02:00
Therefore, it makes sense to adopt the same naming convention as for classes, which is https://en.wikipedia.org/wiki/Camel_case[PascalCase] (a.k.a. UpperCamelCase).
2024-08-27 21:11:28 +02:00
This makes the code more homogeneous and doesn't mislead developers into thinking that the extension is a variable or a function.
== How to fix it
=== Code examples
==== Noncompliant code example
[source,dart,diff-id=1,diff-type=noncompliant]
----
extension my_extension on String { // lower_snake_case
void myMethod() {
print('Hello');
}
}
----
==== Compliant solution
[source,dart,diff-id=1,diff-type=compliant]
----
extension MyExtension on String { // UpperCamelCase
void myMethod() {
print('Hello');
}
}
----
== Resources
=== Documentation
* Dart Docs - https://dart.dev/tools/linter-rules/camel_case_extensions[Dart Linter rule - camel_case_extensions]
* Dart Docs - https://dart.dev/language/extension-methods[Language - extension methods]
* Wikipedia - https://en.wikipedia.org/wiki/Camel_case[Camel case]
=== Related rules
* S101 - Class names should comply with a naming convention
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* The extension name '<extension identifier>' isn't an UpperCamelCase identifier.
=== Highlighting
* The identifier of the extension.
'''
== Comments And Links
(visible only on this page)
endif::env-github,rspecator-view[]