aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar laurentlb <laurentlb@google.com>2017-11-27 02:52:07 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-11-27 02:53:54 -0800
commit9fea5b89a5cf8744dbe32aff279a9e2c2613c9d8 (patch)
tree538bf019585ea541aa6ef64737006d1b5533e9d7 /src
parentf91ec333a32dce253a301a71c2bb0f189febc96d (diff)
Use more precise categories for missing docstring.
Split missing-docstring into missing-module-docstring and missing-function-docstring. RELNOTES: None. PiperOrigin-RevId: 176993716
Diffstat (limited to 'src')
-rw-r--r--src/test/skylark/skylint/skylint_test.py3
-rw-r--r--src/tools/skylark/java/com/google/devtools/skylark/skylint/DocstringChecker.java8
-rw-r--r--src/tools/skylark/javatests/com/google/devtools/skylark/skylint/DocstringCheckerTest.java4
3 files changed, 9 insertions, 6 deletions
diff --git a/src/test/skylark/skylint/skylint_test.py b/src/test/skylark/skylint/skylint_test.py
index 42e1ed8eb1..eec9a4fd3d 100644
--- a/src/test/skylark/skylint/skylint_test.py
+++ b/src/test/skylark/skylint/skylint_test.py
@@ -60,7 +60,8 @@ class SkylintTest(unittest.TestCase):
def testDisablingCategory(self):
output = subprocess.check_output([
- testenv.SKYLINT_BINARY_PATH, "--disable-categories=missing-docstring",
+ testenv.SKYLINT_BINARY_PATH,
+ "--disable-categories=missing-module-docstring",
os.path.join(testenv.SKYLINT_TESTDATA_PATH, "bad.bzl.test")
])
self.assertEqual(output, "")
diff --git a/src/tools/skylark/java/com/google/devtools/skylark/skylint/DocstringChecker.java b/src/tools/skylark/java/com/google/devtools/skylark/skylint/DocstringChecker.java
index 47c02e1b73..35f99e9f50 100644
--- a/src/tools/skylark/java/com/google/devtools/skylark/skylint/DocstringChecker.java
+++ b/src/tools/skylark/java/com/google/devtools/skylark/skylint/DocstringChecker.java
@@ -36,7 +36,8 @@ import java.util.List;
/** Checks the existence of docstrings. */
public class DocstringChecker extends SyntaxTreeVisitor {
- private static final String MISSING_DOCSTRING_CATEGORY = "missing-docstring";
+ private static final String MISSING_MODULE_DOCSTRING_CATEGORY = "missing-module-docstring";
+ private static final String MISSING_FUNCTION_DOCSTRING_CATEGORY = "missing-function-docstring";
private static final String INCONSISTENT_DOCSTRING_CATEGORY = "inconsistent-docstring";
private static final String BAD_DOCSTRING_FORMAT_CATEGORY = "bad-docstring-format";
/** If a function is at least this many statements long, a docstring is required. */
@@ -60,7 +61,8 @@ public class DocstringChecker extends SyntaxTreeVisitor {
// This location is invalid if the file is empty but this edge case is not worth the trouble.
Location end = new Location(2, 1);
LocationRange range = new LocationRange(start, end);
- issues.add(new Issue(MISSING_DOCSTRING_CATEGORY, "file has no module docstring", range));
+ issues.add(
+ new Issue(MISSING_MODULE_DOCSTRING_CATEGORY, "file has no module docstring", range));
} else {
List<DocstringParseError> errors = new ArrayList<>();
DocstringUtils.parseDocstring(moduleDocstring, errors);
@@ -98,7 +100,7 @@ public class DocstringChecker extends SyntaxTreeVisitor {
String name = node.getIdentifier().getName();
issues.add(
new Issue(
- MISSING_DOCSTRING_CATEGORY,
+ MISSING_FUNCTION_DOCSTRING_CATEGORY,
"function '"
+ name
+ "' has no docstring"
diff --git a/src/tools/skylark/javatests/com/google/devtools/skylark/skylint/DocstringCheckerTest.java b/src/tools/skylark/javatests/com/google/devtools/skylark/skylint/DocstringCheckerTest.java
index ebaabfdaf4..30d17fea24 100644
--- a/src/tools/skylark/javatests/com/google/devtools/skylark/skylint/DocstringCheckerTest.java
+++ b/src/tools/skylark/javatests/com/google/devtools/skylark/skylint/DocstringCheckerTest.java
@@ -49,13 +49,13 @@ public class DocstringCheckerTest {
" print(5)")
.toString();
Truth.assertThat(errorMessage)
- .contains("1:1-2:1: file has no module docstring [missing-docstring]");
+ .contains("1:1-2:1: file has no module docstring [missing-module-docstring]");
Truth.assertThat(errorMessage)
.contains(
"2:1-4:2: function 'function' has no docstring"
+ " (if this function is intended to be private,"
+ " the name should start with an underscore: '_function')"
- + " [missing-docstring]");
+ + " [missing-function-docstring]");
}
@Test