dzhu/rstfmt

Crash if code block does not contain line separator

Opened this issue · 0 comments

Reproduction

  1. Prepare file foo.rst with content:
.. code:: python
    foo()
..
  1. Perform:
rstfmt foo.rst

Current

:1: (ERROR/3) Error in "code" directive:
maximum 1 argument(s) allowed, 2 supplied.

.. code:: python
   foo()
Traceback (most recent call last):
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 2142, in run_directive
    self.parse_directive_block(indented, line_offset,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 2207, in parse_directive_block
    arguments = self.parse_directive_arguments(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 2245, in parse_directive_arguments
    raise MarkupError(
docutils.parsers.rst.states.MarkupError: maximum 1 argument(s) allowed, 2 supplied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\Scripts\rstfmt.exe\__main__.py", line 7, in <module>
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\rstfmt\__main__.py", line 91, in main
    do_file(args, path, misformatted)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\rstfmt\__main__.py", line 19, in do_file
    doc = rstfmt.parse_string(inp)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\rstfmt\rstfmt.py", line 758, in parse_string
    parser.parse(s, doc)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\__init__.py", line 184, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 169, in run
    results = StateMachineWS.run(self, input_lines, input_offset,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 3024, in text
    self.section(title.lstrip(), source, style, lineno + 1, messages)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 325, in section
    self.new_subsection(title, lineno, messages)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 391, in new_subsection
    newabsoffset = self.nested_parse(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 279, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 3024, in text
    self.section(title.lstrip(), source, style, lineno + 1, messages)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 325, in section
    self.new_subsection(title, lineno, messages)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 391, in new_subsection
    newabsoffset = self.nested_parse(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 279, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 2785, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 325, in section
    self.new_subsection(title, lineno, messages)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 391, in new_subsection
    newabsoffset = self.nested_parse(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 279, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 2785, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 325, in section
    self.new_subsection(title, lineno, messages)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 391, in new_subsection
    newabsoffset = self.nested_parse(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 279, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 1170, in indent
    elements = self.block_quote(indented, line_offset)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 1187, in block_quote
    self.nested_parse(blockquote_lines, line_offset, blockquote)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 279, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 1276, in bullet
    new_line_offset, blank_finish = self.nested_list_parse(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 316, in nested_list_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 2535, in bullet
    listitem, blank_finish = self.list_item(match.end())
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 1295, in list_item
    self.nested_parse(indented, input_offset=line_offset,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 279, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 1170, in indent
    elements = self.block_quote(indented, line_offset)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 1187, in block_quote
    self.nested_parse(blockquote_lines, line_offset, blockquote)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 279, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 2355, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 2367, in explicit_construct
    return method(self, expmatch)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 2104, in directive
    return self.run_directive(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\parsers\rst\states.py", line 2145, in run_directive
    error = self.reporter.error(
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\utils\__init__.py", line 231, in error
    return self.system_message(self.ERROR_LEVEL, *args, **kwargs)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\rstfmt\rstfmt.py", line 281, in system_message
    msg = super().system_message(level, message, *children, **kwargs)
  File "C:\Users\gr29906\AppData\Local\Programs\Python\Python310\lib\site-packages\docutils\utils\__init__.py", line 197, in system_message
    raise SystemMessage(msg, level)
docutils.utils.SystemMessage: :1: (ERROR/3) Error in "code" directive:
maximum 1 argument(s) allowed, 2 supplied.

.. code:: python
   foo()

Expected

Error about missing new line separator / auto fixing