Socket
Socket
Sign inDemoInstall

sort-lines

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-lines

alphabetize lines in files


Maintainers
1

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.

Lines can be sorted case-insensitively by using the [ci] or [case-insensitive] options:

# names.py
names = [  # pragma: alphabetize[case-insensitive]
    'Alice',
    'bob',
    'Charlie',
    'david',
    'Eve',
]

Or by passing --case-insensitive on the command line.

pre-commit

This tool can be used with pre-commit:

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc