Skip to main content

reStructuredText linter

Project description

Build Status

reStructuredText linter

This was created out of frustration with PyPI; it sucks finding out your reST is invalid after uploading it. It is being developed in junction with a Sublime Text linter.

Getting Started

Install the module with: pip install restructuredtext_lint

import restructuredtext_lint
errors = restructuredtext_lint.lint("""
Hello World
=======
""")

# `errors` will be list of system messages
# [<system_message: <paragraph...><literal_block...>>]
errors[0].message  # Title underline too short.

CLI Utility

For your convenience, we present a CLI utility rst-lint (also available as restructuredtext-lint).

$ rst-lint --help
usage: rst-lint [-h] [--format FORMAT] filepath

Lint a reStructuredText file

positional arguments:
  filepath         File to lint

optional arguments:
  -h, --help       show this help message and exit
  --format FORMAT  Format of output (e.g. text, json)

$ rst-lint README.rst
WARNING README.rst:2 Title underline too short.

Documentation

restructuredtext-lint exposes a lint function

restructuredtext_lint.lint(content, filepath=None)

Lint reStructuredText and return errors

  • content String - reStructuredText to be linted

  • filepath String - Optional path to file, this will be returned as the source

Returns:

  • errors List - List of errors
    • Each error is a class from docutils with the following attrs
      • line Integer - Line where the error occurred

      • source String - filepath provided in parameters

      • level Integer - Level of the warning
        • Levels represent ‘info’: 1, ‘warning’: 2, ‘error’: 3, ‘severe’: 4

      • type String - Noun describing the error level
        • Levels can be ‘INFO’, ‘WARNING’, ‘ERROR’, or ‘SEVERE’

      • message String - Error message

      • full_message String - Error message and source lines where the error occurred

    • It should be noted that level, type, message, and full_message are custom attrs added onto the original system_message

Examples

Here is an example of all invalid properties

rst = """
Some content.

Hello World
=======
Some more content!
"""
errors = restructuredtext_lint.lint(rst, 'myfile.py')
errors[0].line  # 5
errors[0].source  # myfile.py
errors[0].level  # 2
errors[0].type  # WARNING
errors[0].message  # Title underline too short.
errors[0].full_message  # Title underline too short.
                        #
                        # Hello World
                        # =======

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Test via nosetests.

Donating

Support this project and others by twolfson via gittip.

Support via Gittip

Unlicense

As of Nov 22 2013, Todd Wolfson has released this repository and its contents to the public domain.

It has been released under the UNLICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

restructuredtext_lint-0.2.0.zip (16.0 kB view details)

Uploaded Source

restructuredtext_lint-0.2.0.tar.gz (7.3 kB view details)

Uploaded Source

File details

Details for the file restructuredtext_lint-0.2.0.zip.

File metadata

File hashes

Hashes for restructuredtext_lint-0.2.0.zip
Algorithm Hash digest
SHA256 c3d04ded95fde13ef2de9f1825328e9009de60c38158f6aa47b4bbe267b0e89b
MD5 573b8a24e8748d2f06db4ad03e616f8b
BLAKE2b-256 6101e33ee68faddbfd8d172a9fd6838e28f5c7c895c6ec46ebdef7372a1fb204

See more details on using hashes here.

File details

Details for the file restructuredtext_lint-0.2.0.tar.gz.

File metadata

File hashes

Hashes for restructuredtext_lint-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f826435e0392da28e57923f27d5691265d79eeea96a48cbdc3953e20241c45f2
MD5 f5b4a9182c2d784e2553d8360c10f6b7
BLAKE2b-256 f9c4d377147ad7df7bf907518396524b10514cff19efb69ed3cf175d93f2e72f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page