Skip to content

Commit

Permalink
added without deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison committed Sep 7, 2024
1 parent 4147fde commit 407ad51
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions checker/generator/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ var endpointValueSets = ValueSets{
nouns: []string{"stability"}, // /Paths/PathItem/Operation
actions: []string{"decrease"},
},
ValueSetA{
nouns: []string{"api path", "api"},
actions: []string{"add", "remove"},
adverb: "without deprecation",
},
ValueSetB{
nouns: []string{"endpoint"}, // /Paths/PathItem
actions: []string{"add", "remove", "deprecate", "reactivate"},
Expand Down
20 changes: 14 additions & 6 deletions checker/generator/checks.go → checker/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,26 @@ func standardizeSpaces(s string) string {
}

func getActionMessage(action string) string {
if isUnary(action) {
return conjugate(action) + " to %s"
switch getArity(action) {
case 0:
return ""
case 1:
return " to %s"
case 2:
return " from %s to %s"
default:
return ""
}
return conjugate(action) + " from %s to %s"
}

func isUnary(action string) bool {
func getArity(action string) int {
switch action {
case "add", "remove":
return 0
case "set":
return true
return 1
}
return false
return 2
}

func conjugate(verb string) string {
Expand Down
4 changes: 4 additions & 0 deletions checker/generator/messages.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
stability-decreased: stability was decreased from %s to %s
api-path-added: api path was added without deprecation
api-path-removed: api path was removed without deprecation
api-added: api was added without deprecation
api-removed: api was removed without deprecation
endpoint-added: added endpoint
endpoint-removed: removed endpoint
endpoint-deprecated: deprecated endpoint
Expand Down
7 changes: 4 additions & 3 deletions checker/generator/value_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ValueSet struct {
hierarchy []string
nouns []string
actions []string
adverb string
}

func (v ValueSet) setHierarchy(hierarchy []string) ValueSet {
Expand All @@ -57,19 +58,19 @@ func (v ValueSetA) setHierarchy(hierarchy []string) IValueSet {
}

func (v ValueSetA) generate(out io.Writer) {
generateMessage := func(hierarchy []string, noun, attributiveAdjective, predicativeAdjective, action string) string {
generateMessage := func(hierarchy []string, noun, attributiveAdjective, predicativeAdjective, action, adverb string) string {
prefix := addAttribute(noun, attributiveAdjective, predicativeAdjective)
if hierarchyMessage := getHierarchyMessage(hierarchy); hierarchyMessage != "" {
prefix += " of " + hierarchyMessage
}

return standardizeSpaces(fmt.Sprintf("%s was %s", prefix, getActionMessage(action)))
return standardizeSpaces(fmt.Sprintf("%s was %s %s %s", prefix, conjugate(action), getActionMessage(action), adverb))
}

for _, noun := range v.nouns {
for _, action := range v.actions {
id := generateId(v.hierarchy, noun, action)
message := generateMessage(v.hierarchy, noun, v.attributiveAdjective, v.predicativeAdjective, action)
message := generateMessage(v.hierarchy, noun, v.attributiveAdjective, v.predicativeAdjective, action, v.adverb)
fmt.Fprintln(out, fmt.Sprintf("%s: %s", id, message))

Check failure on line 74 in checker/generator/value_set.go

View workflow job for this annotation

GitHub Actions / lint

S1038: should use fmt.Fprintf instead of fmt.Fprintln(fmt.Sprintf(...)) (but don't forget the newline) (gosimple)
}
}
Expand Down

0 comments on commit 407ad51

Please sign in to comment.