Skip to main content

restructuredtext-lint

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.

Metadata

Release files for restructuredtext-lint 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distributions (sdists)

Source distribution for restructuredtext-lint 0.6.0
File Size Uploaded Provenance Actions
restructuredtext_lint-0.6.0.zip 23.1 kB Without provenance Details for restructuredtext_lint-0.6.0.zip
restructuredtext_lint-0.6.0.tar.gz 11.2 kB Without provenance Details for restructuredtext_lint-0.6.0.tar.gz

Release files / restructuredtext_lint-0.6.0.zip

Download URL restructuredtext_lint-0.6.0.zip
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4e5411871e98f4220919a53796ed489e6575fd6e00b888efc06018102de85f3f
BLAKE2b-256 checksum
How to use checksums
ce9bbdd70b978d6e8e548ae9416f1a9df67c9b7e01ee8d3e3a7b4c51deafa4b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / restructuredtext_lint-0.6.0.tar.gz

Download URL restructuredtext_lint-0.6.0.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8896b8cc6f7b499e8b5562b82c6cf51d6421a501b624259524f956114ecc64f2
BLAKE2b-256 checksum
How to use checksums
a5fc8460cebc9958fc064b92880a10d10c28058d391907c129cebe3cd3b7e75a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for restructuredtext-lint 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page