You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
packagecom.exampleclassMutableTableContainer {
privatevar_table:Map<String, Int>?=nullval table:Map<String, Int>
get() {
if (_table==null) {
_table= hashMapOf()
}
return_table?:throwAssertionError("Set to null by another thread")
}
}
Diktat 1.2.5 warns:
MutableTableContainer.kt:4:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: _table (diktat-ruleset:identifier-naming)
Probably we should make an exception for backing properties whenever there's an explicit backing field with the corresponding name (xyz → _xyz) and of the same type.
Requirements:
the backing field should be private (or have a lowervisibility than that of the property);
the backing field should have a matching name (xyz → _xyz);
the backing field should have the same type as the property (either convert both types to a simple name, or resolve to a FQN before you compare; nullable subtypes should be permitted: Map<String, Int> → Map<String, Int>?);
the backing field should have no accessors/modifiers of its own;
the property should have at least an accessor, or a modifier, or both.
Describe the bug
Consider this idiomatic example taken directly from https://kotlinlang.org:
Diktat 1.2.5 warns:
Probably we should make an exception for backing properties whenever there's an explicit backing field with the corresponding name (
xyz
→_xyz
) and of the same type.Requirements:
private
(or have a lower visibility than that of the property);xyz
→_xyz
);Map<String, Int>
→Map<String, Int>?
);Related:
CUSTOM_GETTERS_SETTERS
false positive when a property has a backing field #1709Expected behavior
No warning should have been reported.
Observed behavior
A warning was reported.
Steps to Reproduce
Check the above code example with Diktat.
Environment information
The text was updated successfully, but these errors were encountered: