Repository: oppia/oppia

Issue:
Empty docstring linter error
**Describe the bug**
When the docstring of some methods is set to `""""""` the pre-commit linter will show an error:

```
Traceback (most recent call last):
  File "scripts/concurrent_task_utils.py", line 101, in run
    self.task_results = self.func()
  File "scripts/linters/python_linter.py", line 481, in perform_all_lint_checks
    linter_stdout.append(self.lint_py_files())
  File "scripts/linters/python_linter.py", line 345, in lint_py_files
    exit=False).linter
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/lint.py", line 1353, in __init__
    linter.check(args)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/lint.py", line 774, in check
    self._do_check(files_or_modules)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/lint.py", line 907, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/lint.py", line 986, in check_astroid_module
    walker.walk(ast_node)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/utils.py", line 1014, in walk
    self.walk(child)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/utils.py", line 1014, in walk
    self.walk(child)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/utils.py", line 1011, in walk
    cb(astroid)
  File "scripts/linters/pylint_extensions.py", line 634, in visit_functiondef
    self.check_docstring_style(node)
  File "scripts/linters/pylint_extensions.py", line 789, in check_docstring_style
    self.check_docstring_structure(node)
  File "scripts/linters/pylint_extensions.py", line 833, in check_docstring_structure
    if docstring[0][0] == b' ':
IndexError: string index out of range
``` 
Empty docstring linter error
**Describe the bug**
When the docstring of some methods is set to `""""""` the pre-commit linter will show an error:

```
Traceback (most recent call last):
  File "scripts/concurrent_task_utils.py", line 101, in run
    self.task_results = self.func()
  File "scripts/linters/python_linter.py", line 481, in perform_all_lint_checks
    linter_stdout.append(self.lint_py_files())
  File "scripts/linters/python_linter.py", line 345, in lint_py_files
    exit=False).linter
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/lint.py", line 1353, in __init__
    linter.check(args)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/lint.py", line 774, in check
    self._do_check(files_or_modules)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/lint.py", line 907, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/lint.py", line 986, in check_astroid_module
    walker.walk(ast_node)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/utils.py", line 1014, in walk
    self.walk(child)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/utils.py", line 1014, in walk
    self.walk(child)
  File "/home/vojtech/Programming/oppia/oppia/../oppia_tools/pylint-quotes-0.1.8/pylint/utils.py", line 1011, in walk
    cb(astroid)
  File "scripts/linters/pylint_extensions.py", line 634, in visit_functiondef
    self.check_docstring_style(node)
  File "scripts/linters/pylint_extensions.py", line 789, in check_docstring_style
    self.check_docstring_structure(node)
  File "scripts/linters/pylint_extensions.py", line 833, in check_docstring_structure
    if docstring[0][0] == b' ':
IndexError: string index out of range
``` 


Discussion:
Hey @vojtechjelinek ,
I tried to reproduce the issue with empty docstring as you have mention above, But i am unable to reproduce the issue.(it does not throw error.),is this issue still reproducible?
![image](https://user-images.githubusercontent.com/55298925/98093463-ff84c980-1ead-11eb-9c7a-ad4e8b8a199c.png)

@vojtechjelinek 
i was able to reproduce this issue by the following docstring:
```
def somefunction():
    """
    """
```
![image](https://user-images.githubusercontent.com/55298925/98100310-aec59e80-1eb6-11eb-9228-6be696684406.png)
**Note: All check passed even with error.**



@vojtechjelinek i would like to work on this issue can you please assign me ?
Also, let me know what should be the expected behaviour.
I think the expected outcome should be that `Empty method docstring` is returned and that there is no error.

@AdityaDubey0 any updates on this?
@AdityaDubey0 Do you want to complete your work on this issue? If not, then kindly let me know. Thanks!
@sajalasati initially I was finding it difficult, I will take a pass again and if I need any help I will let you know
Hey @vojtechjelinek ,
I tried to reproduce the issue with empty docstring as you have mention above, But i am unable to reproduce the issue.(it does not throw error.),is this issue still reproducible?
![image](https://user-images.githubusercontent.com/55298925/98093463-ff84c980-1ead-11eb-9c7a-ad4e8b8a199c.png)

@vojtechjelinek 
i was able to reproduce this issue by the following docstring:
```
def somefunction():
    """
    """
```
![image](https://user-images.githubusercontent.com/55298925/98100310-aec59e80-1eb6-11eb-9228-6be696684406.png)
**Note: All check passed even with error.**



@vojtechjelinek i would like to work on this issue can you please assign me ?
Also, let me know what should be the expected behaviour.
I think the expected outcome should be that `Empty method docstring` is returned and that there is no error.

@AdityaDubey0 any updates on this?
@AdityaDubey0 Do you want to complete your work on this issue? If not, then kindly let me know. Thanks!
@sajalasati initially I was finding it difficult, I will take a pass again and if I need any help I will let you know

Resolving patch:
diff --git a/scripts/linters/pylint_extensions.py b/scripts/linters/pylint_extensions.py
--- a/scripts/linters/pylint_extensions.py
+++ b/scripts/linters/pylint_extensions.py
@@ -830,7 +830,7 @@ def check_docstring_structure(self, node):
         if node.doc:
             docstring = node.doc.splitlines()
             # Check for space after """ in docstring.
-            if docstring[0][0] == b' ':
+            if len(docstring[0]) > 0 and docstring[0][0] == b' ':
                 self.add_message('space-after-triple-quote', node=node)
             # Check if single line docstring span two lines.
             if len(docstring) == 2 and docstring[-1].strip() == b'':


Test patch:
diff --git a/scripts/linters/pylint_extensions_test.py b/scripts/linters/pylint_extensions_test.py
--- a/scripts/linters/pylint_extensions_test.py
+++ b/scripts/linters/pylint_extensions_test.py
@@ -736,6 +736,21 @@ def test_space_after_docstring(self):
             self.checker_test_object.checker.visit_functiondef(
                 node_space_after_docstring)
 
+    def test_two_lines_empty_docstring_raise_correct_message(self):
+        node_with_docstring = astroid.extract_node(
+            u"""def func():
+                    \"\"\"
+                    \"\"\"
+                    pass
+        """)
+        message = testutils.Message(
+            msg_id='single-line-docstring-span-two-lines',
+            node=node_with_docstring)
+
+        with self.checker_test_object.assertAddsMessages(message):
+            self.checker_test_object.checker.visit_functiondef(
+                node_with_docstring)
+
     def test_single_line_docstring_span_two_lines(self):
         node_single_line_docstring_span_two_lines = astroid.extract_node(
             u"""def func(): #@