Skip to content

Commit

Permalink
Add more tests for docstrings (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmos authored Feb 8, 2019
1 parent a112fa3 commit aa1408f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions warn/warn_docstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"
)

// FunctionLengthDocstringThreshold is a limit for a function size (in statements), above which
// a public function is required to have a docstring.
const FunctionLengthDocstringThreshold = 5

// getDocstrings returns a docstring of the statemenets and true if it exists.
Expand Down
29 changes: 29 additions & 0 deletions warn/warn_docstring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ def f(x):

checkFindings(t, "function-docstring", `
def f(x):
"""Short function with a docstring"""
return x
`,
[]string{
`:2: Argument "x" is not documented.`,
`:2: Return value of "f" is not documented.`,
},
scopeEverywhere)

checkFindings(t, "function-docstring", `
def f(x):
# long function
x += 1
x *= 2
Expand All @@ -89,6 +100,24 @@ def _f(x):
`,
[]string{},
scopeEverywhere)

checkFindings(t, "function-docstring", `
def _f(x):
"""Long private function
with a docstring"""
x += 1
x *= 2
x /= 3
x -= 4
x %= 5
return x
`,
[]string{
`:2: The docstring for the function "_f" should start with a one-line summary.`,
`:2: Argument "x" is not documented.`,
`:2: Return value of "_f" is not documented.`,
},
scopeEverywhere)
}

func TestFunctionDocstringFormat(t *testing.T) {
Expand Down

0 comments on commit aa1408f

Please sign in to comment.