Skip to content

Commit

Permalink
name[casing]: now applies only to scripts supporting uppercase (#2347)
Browse files Browse the repository at this point in the history
Fixes: #2340
  • Loading branch information
ssbarnea committed Aug 27, 2022
1 parent 29ec745 commit a698f85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
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()
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

0 comments on commit a698f85

Please sign in to comment.