Skip to main content

alphabetize lines in files

Project description

sort lines

Alphabetize lines in a file.

This tool uses leading whitespace to delimit the lines that should be alphabetized. It is intended for use with Python code but should work with anything that has consistent indentation.

usage

Indicate that some lines should be alphabetized by including a comment on the line above (the comment must include # pragma: alphabetize).

# names.py
names = [  # pragma: alphabetize
    'Alice',
    'Bob',
    'Charlie',
    'David',
    'Eve',
]

Run this tool on the file:

sort-lines names.py

Indentation will be used to decide which lines need to be sorted. The first line after the pragma comment will set the indentation level and every subsequent line with the same amount of indentation will be included in the sorting. The first line with a different indentation(including blank lines) will indicate the end of the sorted lines.

pre-commit

This tool can be used with pre-commit:

repos:
-   repo: https://github.com/samueljsb/sort-lines
    rev: v0.1.2
    hooks:
    -   id: sort-lines

Project details


Download files

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

Source Distribution

sort_lines-0.1.2.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

sort_lines-0.1.2-py2.py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 2 Python 3

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