Skip to main content

This package provides formatters and linters for CMake, C++, and Python, making it ideal for developers who work with both C++ and Python.

Project description

Generic formatter and linter

This package provides formatters and linters for CMake, C++, and Python, making it ideal for developers who work with both C++ and Python.

Getting Started

Installation

pip install lhy-formatter-linter

Usage

The formatter or linter will recursively scan your project directory, formatting or linting all CMake, C++, and Python code using third-party tools.

third-party tool cmake C++ python
formatter cmake-format clang-format yapf, isort
linter cmake-lint clang-tidy flake8
lhy -h
usage: lhy [-h] {format,lint} ...

code formatter and linter.

positional arguments:
  {format,lint}
    format       Format code
    lint         Lint code

format code in yout project

lhy format -p <project-root-dir> 

lint code in yout project

lhy lint -p <project-root-dir> 

Optional arguments

Choose languages

Users can choose to format or lint one or more languages by using the -l or --language option.

lhy format -p <project-root-dir> -l cmake
lhy lint -p <project-root-dir> -l python
lhy lint -p <project-root-dir> -l cmake cxx

Ignore no-source directories

In a project, there are typically subdirectories that do not contain source code.

By default, lhy-formatter-linter ignores the following directories at the top level under the project root directory:

  • .git
  • build
  • .vscode
  • .cache
  • .pytest_cache

Users can add custom subdirectories to ignore using the optional argument -id or --ignore-dirs. The format of the subdirectories to ignore can be either an absolute path or a relative path to the project root directory.

lhy format -p <project-root-dir> --ignore-dirs .github py_venv <project_root_dir>/docs
lhy lint -p <project-root-dir> --ignore-dirs <project_root_dir>/.github  <project_root_dir>/py_venv docs

Alternatively, users can specify a text file that contains the directories to ignore, with one directory per line.

For example, a file named dirs-to-ignore.txt could have the following content:

<project_root_dir>/.github
<project_root_dir>/py_venv
docs

Then, use the optional argument -ig or --ignore-file to specify the file containing the directories to ignore, which will be parsed by the formatter or linter.

lhy format -p <project-root-dir> --ignore-file dirs-to-ignore.txt

Format or lint config files

By default, the formatter or linter will use the format or lint configuration files located directly under the project root directory.

Users can place their own custom format and lint configuration files directly under the project root directory to override the default settings and apply their own custom formatting or linting rules.

└── user
    ├── project_root_dir
       ├── src
       ├── .clang-format
       ├── .clang-tidy
       ├── .cmake-format
       ├── .flake8
       ├── .style.yapf
       └── .isort.cfg

Alternatively, users can specify the configuration file paths using the following optional arguments:

formatter config file path arguments

optional cmake format arguments:
  --cmake-format-config CMAKE_FORMAT_CONFIG
                        Path of cmake format custom config file (default: None)

optional c++ format arguments:
  --clang-format-config CLANG_FORMAT_CONFIG
                        Path of clang format custom config file (default: None)

optional python format arguments:
  --yapf-config YAPF_CONFIG
                        Path of yapf custom config file (default: None)
  --isort-config ISORT_CONFIG
                        Path of isort custom config file
lhy format -p <project-root-dir> \
    --cmake-format-config <cmake-format-config-absolute-file-path> \
    --clang-format-config <clang-format-config-absolute-file-path> \
    --yapf-config <yapf-config-absolute-file-path> \
    --isort-config <isort-config-absolute-file-path>

linter config file path arguments

optional cmake lint arguments:
  --cmake-lint-config CMAKE_LINT_CONFIG
                        Path of cmake lint custom config file (default: None)

optional c++ format arguments:
  --clang-tidy-config CLANG_TIDY_CONFIG
                        Path of clang tidy custom config file (default: None)

optional python format arguments:
  --flake8-config FLAKE8_CONFIG
                        Path of flake8 custom config file (default: None)
lhy format -p <project-root-dir> \
    --cmake-lint-config <cmake-lint-config-absolute-file-path> \
    --clang-tidy-config <clang-tidy-config-absolute-file-path> \
    --flake8-config <flake8-config-absolute-file-path>

Integrate to CI

This package can be integrated into a Continuous Integration (CI) pipeline to ensure that all code on the remote repository conforms to the specified norms and standards.

jenkins example.

stage('Check code') {
    agent any
    steps {
        sh 'lhy lint -p <project_root_dir>'
        sh 'lhy format -p <project_root_dir>'
        sh 'git diff --exit-code'
    }
}

License

This project is licensed under the MIT License. For more information, please refer to the LICENSE.md file.

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

lhy_formatter_linter-0.0.10.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lhy_formatter_linter-0.0.10-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file lhy_formatter_linter-0.0.10.tar.gz.

File metadata

  • Download URL: lhy_formatter_linter-0.0.10.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for lhy_formatter_linter-0.0.10.tar.gz
Algorithm Hash digest
SHA256 6935292da4bc58897591a5bfea5e9038ae9bdbc36ea263f5a9788bae8009e05a
MD5 bba2709e6e26c56b60d56025e01fc050
BLAKE2b-256 ee09ae89a37f9e5fe661130be932c6359a45521096141a8c4cff63dfcf3bcbd3

See more details on using hashes here.

Provenance

The following attestation bundles were made for lhy_formatter_linter-0.0.10.tar.gz:

Publisher: lhy.yml on sygslhy/lhy-formatter-linter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lhy_formatter_linter-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for lhy_formatter_linter-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 75688f20706c05df44fdda7b658171865ef71508a1260409308ca1cf87d50ddf
MD5 36b32bd5efb5d18b2788fce30f39fc9b
BLAKE2b-256 5b0e24c052982c633eed431b3ee15bc086db0704f10725f5129329ce2b7bdf3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lhy_formatter_linter-0.0.10-py3-none-any.whl:

Publisher: lhy.yml on sygslhy/lhy-formatter-linter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page