Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
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.
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.
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
alphabetize lines in files
We found that sort-lines demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.