Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linter Failing on docstr_stmt With NotImplementedError #233

Closed
ogrady opened this issue Oct 8, 2023 · 1 comment
Closed

Linter Failing on docstr_stmt With NotImplementedError #233

ogrady opened this issue Oct 8, 2023 · 1 comment
Labels
bug Something isn't working linter

Comments

@ogrady
Copy link

ogrady commented Oct 8, 2023

Hi,

the linter currently handles the old-style docstrings as "not implemented".
While Godot seems to have moved from quote-based docstrings to diamond-based ones, the linter just crashes with a very non-descriptive error:

# foo.gd
"""
hello world!
"""
> gdlint foo.gd

Traceback (most recent call last):
  File "/home/user/.local/bin/gdlint", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/gdtoolkit/linter/__main__.py", line 66, in main
    problems_total += _lint_file(file_path, config)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/gdtoolkit/linter/__main__.py", line 134, in _lint_file
    problems = lint_code(content, config)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/gdtoolkit/linter/__init__.py", line 119, in lint_code
    problems += class_checks.lint(parse_tree, config)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/gdtoolkit/linter/class_checks.py", line 38, in lint
    problems += [problem for cluster in problem_clusters for problem in cluster]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/gdtoolkit/linter/class_checks.py", line 38, in <listcomp>
    problems += [problem for cluster in problem_clusters for problem in cluster]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/gdtoolkit/linter/class_checks.py", line 35, in <genexpr>
    function(ast) if name not in disable else []
    ^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/gdtoolkit/linter/class_checks.py", line 71, in _class_definitions_order_check
    return [
           ^
  File "/home/user/.local/lib/python3.11/site-packages/gdtoolkit/linter/class_checks.py", line 74, in <listcomp>
    for problem in _class_definitions_order_check_for_class(a_class, order)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/gdtoolkit/linter/class_checks.py", line 87, in _class_definitions_order_check_for_class
    statement_section = _map_statement_to_section(statement)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/gdtoolkit/linter/class_checks.py", line 145, in _map_statement_to_section
    raise NotImplementedError
NotImplementedError

Could this maybe be changed to recommend the user to change quotes to double diamonds? Or even better: fix it to be so?
The unhandled statement kind in this case is docstr_stmt

I had written a small script to do the conversion for us when we migrated from Godot 3.x to 4, if that is any help:

import sys
import re

def fix_file(lines):
    buffer = []
    in_comment = False
    for line in lines:
        if line.strip().startswith('"""'):
            in_comment = not in_comment
        else:
            if in_comment:
                match = re.search(r'^(\s*)(.*)$', line)
                buffer.append('%s## %s\n' % (match.group(1), match.group(2)))
            else:
                buffer.append(line)
    return buffer

def main(args):
    for file in args:
        with open(file, 'r') as rh:
            new_lines = fix_file(rh.readlines())
            with open(file, 'w') as wh:
                wh.writelines(new_lines)
@Scony Scony added bug Something isn't working linter labels Oct 22, 2023
@Scony
Copy link
Owner

Scony commented Oct 22, 2023

In Godot 4 the docstrings were removed at first and re-added after a few months due to user complaints. I followed the Godot in gdtoolkit and it looks like I forgot to re-add linter support for them while re-adding general support.

@Scony Scony closed this as completed in 8b8c753 Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linter
Projects
None yet
Development

No branches or pull requests

2 participants