mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Python docstring inspection
This commit is contained in:
@@ -181,6 +181,9 @@ INSP.NAME.default.argument=Default argument is mutable
|
||||
# PyRaisingNewStyleClassInspection
|
||||
INSP.NAME.raising.new.style.class=Raising a new style class
|
||||
|
||||
# PyDocstringInspection
|
||||
INSP.NAME.docstring=Missing or empty docstring
|
||||
|
||||
# Refactoring
|
||||
# introduce
|
||||
refactoring.introduce.name.error=Incorrect name
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.jetbrains.python.inspections;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* Author: Alexey.Ivanov
|
||||
* Date: 10.03.2010
|
||||
* Time: 16:14:45
|
||||
*/
|
||||
public class PyDocstringInspection extends LocalInspectionTool {
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getGroupDisplayName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return PyBundle.message("INSP.NAME.docstring");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getShortName() {
|
||||
return "PyDocstringInspection";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
|
||||
return new Visitor(holder);
|
||||
}
|
||||
|
||||
private static class Visitor extends PyInspectionVisitor {
|
||||
|
||||
public Visitor(final ProblemsHolder holder) {
|
||||
super(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyFile(PyFile node) {
|
||||
checkDocString(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyFunction(PyFunction node) {
|
||||
checkDocString(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyClass(PyClass node) {
|
||||
checkDocString(node);
|
||||
}
|
||||
|
||||
private void checkDocString(PyDocStringOwner node) {
|
||||
PyStringLiteralExpression docStringExpression = node.getDocStringExpression();
|
||||
if (docStringExpression == null) {
|
||||
registerProblem(node, "Missing docstring"); // node?
|
||||
} else if ("".equals(docStringExpression.getStringValue().trim())) {
|
||||
registerProblem(docStringExpression, "Empty docstring");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ public class PythonInspectionToolProvider implements InspectionToolProvider {
|
||||
PyDefaultArgumentInspection.class,
|
||||
PyRaisingNewStyleClassInspection.class,
|
||||
PyUnboundLocalVariableInspection.class,
|
||||
PyDocstringInspection.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>test.py</file>
|
||||
<line>1</line>
|
||||
<description>Missing docstring</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.py</file>
|
||||
<line>1</line>
|
||||
<description>Missing docstring</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.py</file>
|
||||
<line>4</line>
|
||||
<description>Missing docstring</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.py</file>
|
||||
<line>9</line>
|
||||
<description>Empty docstring</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.py</file>
|
||||
<line>13</line>
|
||||
<description>Empty docstring</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -0,0 +1,14 @@
|
||||
class A:
|
||||
pass
|
||||
|
||||
def foo():
|
||||
pass
|
||||
|
||||
|
||||
class B:
|
||||
""""""
|
||||
pass
|
||||
|
||||
def bar():
|
||||
""""""
|
||||
pass
|
||||
@@ -137,4 +137,9 @@ public class PythonInspectionsTest extends PyLightFixtureTestCase {
|
||||
LocalInspectionTool inspection = new PyUnboundLocalVariableInspection();
|
||||
doTest(getTestName(false), inspection);
|
||||
}
|
||||
|
||||
public void testPyDocstringInspection() throws Throwable {
|
||||
LocalInspectionTool inspection = new PyDocstringInspection();
|
||||
doTest(getTestName(false), inspection);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user