Skip to content

Commit

Permalink
feat(AIP-156): allow singleton list (#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz committed Aug 11, 2023
1 parent 4dc9f98 commit ccb38cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions docs/rules/0156/forbidden-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
rule:
aip: 156
name: [core, '0156', forbidden-methods]
summary: Singletons must not define List, Create, or Delete methods.
summary: Singletons must not define Create, or Delete methods.
permalink: /156/forbidden-methods
redirect_from:
- /0156/forbidden-methods
---

# Singletons: Forbidden methods

This rule enforces that singleton resources do not define `List`, `Create`, or
`Delete` methods, as mandated in [AIP-156][].
This rule enforces that singleton resources do not define `Create`, or `Delete`
methods, as mandated in [AIP-156][].

## Details

This rule looks at any message with a `name` variable in the URI where the name
ends in anything other than `*`. It assumes that this is a method operating on
a singleton resource, and complains if the method is a `List`, `Create`, or
`Delete` standard method.
a singleton resource, and complains if the method is a `Create`, or `Delete`
standard method.

## Examples

Expand Down
4 changes: 2 additions & 2 deletions rules/aip0156/forbidden_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ var forbiddenMethods = &lint.MethodRule{
return false
},
LintMethod: func(m *desc.MethodDescriptor) []lint.Problem {
// Singletons should not use Create, List, or Delete.
for _, badPrefix := range []string{"Create", "List", "Delete"} {
// Singletons should not use Create, or Delete.
for _, badPrefix := range []string{"Create", "Delete"} {
if strings.HasPrefix(m.GetName(), badPrefix) {
return []lint.Problem{{
Message: fmt.Sprintf("Singletons must not define %q methods.", badPrefix),
Expand Down
2 changes: 1 addition & 1 deletion rules/aip0156/forbidden_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestForbiddenMethods(t *testing.T) {
}{
{"ValidGet", "GetPublisherSettings", "/settings", testutils.Problems{}},
{"ValidUpdate", "UpdatePublisherSettings", "/settings", testutils.Problems{}},
{"ValidList", "ListPublisherSettings", "/settings", testutils.Problems{}},
{"InvalidCreate", "CreatePublisherSettings", "/settings", testutils.Problems{{Message: "Create"}}},
{"InvalidList", "ListPublisherSettings", "/settings", testutils.Problems{{Message: "List"}}},
{"InvalidDelete", "DeletePublisherSettings", "/settings", testutils.Problems{{Message: "Delete"}}},
{"Irrelevant", "CreatePublisher", "", testutils.Problems{}},
} {
Expand Down

0 comments on commit ccb38cf

Please sign in to comment.