Skip to content

AlgorithmAlchemy/flake8-only-english

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flake8-only-english

⭐️ Thanks everyone who has starred the project, it means a lot!

PyPI version Install from PyPI by clicking the badge above

GitHub
View the source code on GitHub

Downloads License

Flake8 plugin that enforces corporate code style by detecting and reporting any only-english text in Python source code.
It ensures that comments, docstrings, and string literals are written in English only, maintaining consistency across the codebase.


Features

  • Scans Python files for only-english characters in:
    • Comments (# ...)
    • Docstrings (""" ... """ / ''' ... ''')
    • String literals ("..." / '...')
  • Raises a linting error (NL001) when only-english text is found.
  • Works seamlessly with Flake8 and pre-commit hooks.
  • Lightweight and dependency-minimal.

Installation

pip install flake8-only-english

Usage

Run normally via flake8:

flake8 app
flake8 --select=NLE
flake8 --select=NLE001
flake8 --select=NLE002

Example output:

/example.py:5:10: NLE001 Non-English text in docstring

Example

# This is a valid English comment
def hello():
    """Valid English docstring"""
    msg = "Hello world"
    return msg

Example (with pre-commit)

Add to .pre-commit-config.yaml:

repos:
  - repo: https://github.com/AlgorithmAlchemy/flake8-only-english
    rev: v0.1.0
    hooks:
      - id: flake8
        additional_dependencies: [ flake8-only-english ]

Run:

pre-commit run --all-files

Error Codes

  • NLE001 — Non-English text in docstring.
  • NLE002 — Non-English text in string literal

Development

Clone and install in editable mode:

git clone https://github.com/AlgorithmAlchemy/flake8-only-english
cd flake8-only-english
pip install -e .[dev]
pytest

License

MIT License © 2025 AlgorithmAlchemy