Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

name[casing]: now applies only to scripts supporting uppercase #2347

Merged
merged 1 commit into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/playbooks/task-name-lowercase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
- name: this task has a name is not correctly capitalized
ansible.builtin.command: echo "Hello World"
changed_when: false
- name: 测试 should not trigger name[case] rule!
ansible.builtin.command: echo "Hello World"
changed_when: false
18 changes: 11 additions & 7 deletions src/ansiblelint/rules/name.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
## name

This rule identifies several problems related to naming of tasks and plays.
This is important because these names are the primary way to identify executed
operations on console, logs or web interface. Their role is also to document
what Ansible is supposed to do.
This rule identifies several problems related to the naming of tasks and plays.
This is important because these names are the primary way to **identify** and
**document** executed operations on console, logs or web interface.

This rule can produce messages such:

- `name[casing]` - All names should start with an uppercase letter.
- `name[casing]` - All names should start with an uppercase letter for
languages that support it.
- `name[missing]` - All tasks should be named.
- `name[play]` - All plays should be named.

If you want to ignore some of the messages above, you can add any of them to
the `ignore_list`.

### Problematic code

```yaml
---
- hosts: localhost
- hosts: localhost # <-- playbook missing a name key
tasks:
- ansible.builtin.command: touch /tmp/.placeholder
- name: create placefolder file # <-- not starting with a capital letter
ansible.builtin.command: touch /tmp/.placeholder
```

### Correct code
Expand Down
5 changes: 4 additions & 1 deletion src/ansiblelint/rules/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def matchtask(
def _check_name(
self, name: str, lintable: Lintable | None, linenumber: int
) -> MatchError | None:
if not name[0].isupper():
# This rules applies only to scripts that do have uppercase and
# lowercase letter, so we ignore anything else. On Unicode islower()
# is not the opposite of islower()
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved
if name[0].isalpha() and name[0].islower() and not name[0].isupper():
return self.create_matcherror(
message="All names should start with an uppercase letter.",
linenumber=linenumber,
Expand Down