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] [--encoding ENCODING] 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)
  --encoding ENCODING   Encoding of the source file (e.g. utf-8)

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

Documentation

restructuredtext-lint exposes a lint and lint_file 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

restructuredtext_lint.lint_file(filepath, encoding=None)

Lint a reStructuredText file and return errors

Returns: Same structure as restructuredtext_lint.lint

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.10.0.zip (23.8 kB view details)

Uploaded Source

restructuredtext_lint-0.10.0.tar.gz (11.6 kB view details)

Uploaded Source

File details

Details for the file restructuredtext_lint-0.10.0.zip.

File metadata

File hashes

Hashes for restructuredtext_lint-0.10.0.zip
Algorithm Hash digest
SHA256 96d54c36b7327439390899810046ca0d6e9527294f4c62493b6d3846dee658c1
MD5 001e28321c98f028d91ef70745d7bb6e
BLAKE2b-256 c0d7b87559ce2e0624cf7d7f9032efaec1a73a8b38e8ba65adaffd98e66b97fb

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for restructuredtext_lint-0.10.0.tar.gz
Algorithm Hash digest
SHA256 c19d0b8c2cf08c69fc7d3134fcfd016bdc9bdac28ba8ddccc589c1eff1921453
MD5 f188b220194d2cc8f62666b783a1c766
BLAKE2b-256 48f86cbec7aff64903f7d6404f487ca4f9e66a240f9b8924954ce3a8e67f23a2

See more details on using hashes here.

Provenance

Supported by

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