Skip to main content
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.

Release files for restructuredtext-lint 0.3.1

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.3.1
File Size Uploaded
restructuredtext_lint-0.3.1.zip 17.0 kB Details
restructuredtext_lint-0.3.1.tar.gz 7.8 kB Details

Release files / restructuredtext_lint-0.3.1.zip

Download URL restructuredtext_lint-0.3.1.zip
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
798f3a182c758c531c3371d17e9ba833b5d5c7e918463d713553ca796d346007
BLAKE2b-256 checksum
How to use checksums
5e01c7f3d497df88e3b8e8684e50fd0fb3fa28b7d7dad5a1aa9dc46c7e027154
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / restructuredtext_lint-0.3.1.tar.gz

Download URL restructuredtext_lint-0.3.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
494caeccb0d59629b5b8951179d363ef759634d730e9d4e6465818cb412e2245
BLAKE2b-256 checksum
How to use checksums
86361dbd105e8c2d5aba9e27c3ac8dd1843430a83aa0efd0e520a5cadbed21d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.0.2

2 release files

2.0.1

2 release files

2.0.0

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.18.0

1 release file

0.17.0

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.3

2 release files

0.14.2

2 release files

0.14.1

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.4

2 release files

0.12.3

2 release files

0.12.2

2 release files

0.11.3

2 release files

0.11.2

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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