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

Is there a way to lint doctest compatible code examples. #1

Closed
proofit404 opened this issue Jun 4, 2019 · 5 comments · Fixed by #2
Closed

Is there a way to lint doctest compatible code examples. #1

proofit404 opened this issue Jun 4, 2019 · 5 comments · Fixed by #2
Assignees
Labels
enhancement New feature or request

Comments

@proofit404
Copy link

proofit404 commented Jun 4, 2019

Hi, thank you for the meaningful package!

I prefer to write my code examples to be compatible with python doctest module.

>>> class broken( object ):
...     def IsThereAReason(notself, **k):
...         pass

It would be great if we will be able to lint this code :)

P.S. Is there a chance you will start to use complete markdown parser and run flake8 through API and not subprocesses?

I understand this approach works right now, but in future, it will case support troubles.

Regards, Artem.

@johnfraney
Copy link
Owner

@proofit404 You're welcome! That's an interesting idea. It would be possible to add an additional regex rule to lint a pycon block like this:

```pycon
>>> class broken( object ):
...     def IsThereAReason(notself, **k):
...         pass
```

I'd just have to strip the first 4 characters off each line. That sounds like a fun feature to add.

About the subprocess: I was just looking today at flake8-rst, which I did realize existed when I started working on this. I'll see what I can learn from that project.

@johnfraney johnfraney self-assigned this Jun 5, 2019
@johnfraney johnfraney added the enhancement New feature or request label Jun 5, 2019
johnfraney added a commit that referenced this issue Jun 13, 2019
Add support for linting python/REPL code blocks, like:

    ```pycon
    >>> banana = "banana"
    >>> for character in banana:
    ...     print(characterr)
    ```

Closes #1
@johnfraney
Copy link
Owner

johnfraney commented Jun 13, 2019

@proofit404 I've got a working version of this feature. Given this file, flake8-markdown outputs these errors:

tests/samples/pycon.md:10:11: F821 undefined name 'characterr'
tests/samples/pycon.md:17:10: E999 SyntaxError: EOL while scanning string literal
tests/samples/pycon.md:25:1: F821 undefined name 'false'

I want to clean up the code some more and add more tests before I publish this. You can try this feature in the lint-pycon-blocks branch.

After this feature release, I'm going to turn this into a proper Flake8 plugin. Thanks again for the suggestions!

@proofit404
Copy link
Author

Good job! Thanks for the time you have invested in it.

@johnfraney
Copy link
Owner

johnfraney commented Jun 14, 2019

@proofit404 Thanks, thanks! I should be able to get this published this evening. One quirk that I'll mention in the README is that the code examples should end with a newline. Flake8 complains about the "file" not ending with a newline, and doctest needs it, too. Without the newline, doctest thinks that the three backticks are part of the expected output.

johnfraney added a commit that referenced this issue Jun 14, 2019
Add support for linting pycon code blocks, like:

    ```pycon
    >>> banana = "banana"
    >>> for character in banana:
    ...     print(characterr)
    ```

- Include license file in build
- Bump version to v0.2.0

Closes #1
johnfraney added a commit that referenced this issue Jun 15, 2019
Add support for linting pycon code blocks, like:

    ```pycon
    >>> banana = "banana"
    >>> for character in banana:
    ...     print(characterr)
    ```

- Include license file in build
- Bump version to v0.2.0

Closes #1
johnfraney added a commit that referenced this issue Jun 15, 2019
Add support for linting pycon code blocks, like:

    ```pycon
    >>> banana = "banana"
    >>> for character in banana:
    ...     print(characterr)
    ```

- Include license file in build
- Bump version to v0.2.0

Closes #1
@proofit404
Copy link
Author

🎉 🍰 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants