Local variables and function parameters should be named consistently to communicate intent and improve maintainability. Rename your local variable or function parameter to follow your project’s naming convention to address this issue.
A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local
variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily
recognizable pattern.
Adhering to a consistent naming convention helps 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.
This rule checks that local variable and function parameter names match a provided regular expression.
The rule does not raise an issue on the usages of the blank identifier $_ or the root context $.
Inconsistent naming of local variables and function parameters can lead to several issues in your code:
In summary, not adhering to a naming convention for local variables and function parameters can lead to confusion, errors, and inefficiencies, making the code harder to read, understand, and maintain.
First, familiarize yourself with the particular naming convention of the project in question. Then, update the name to match the convention, as well as all usages of the name. For many IDEs, you can use built-in renaming and refactoring features to update all usages at once.
As a default, we suggest using the camelCase naming convention, as this is widely adopted for variables in Helm.
With the default regular expression ^\$[a-z][a-zA-Z0-9]*$:
{{- $my_Variable := .Values.myVariableValue -}} # Noncompliant
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
{{- range $KeyNc, $VAL_NC := .Values.favorite }} # Noncompliant
{{ $KeyNc }}: {{ $VAL_NC | quote }}
{{- end }}
{{- $myVariable := .Values.myVariableValue -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
{{- range $keyC, $valC := .Values.favorite }}
{{ $keyC }}: {{ $valC | quote }}
{{- end }}
# Usage of blank identifier
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className -}}
# Usage of root context
{{- $ := . -}}