Skip to main content

This package provides the formatter and linter for cmake, C++ and python, ideal for mixed C++ and python developer.

Project description

Generic formatter and linter

This package provides the formatter and linter for cmake, C++ and python, ideal for mixed C++ and python developer.

Getting Started

Installation

pip install lhy-formatter-linter

Usage

Formatter or linter will check in your project directory recursively, format or lint all the cmake, C++ python code, by the third-party tools:

third-party tool cmake C++ python
formatter cmake-format clang-format yapf
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

User can choose to format or lint one or two languages by using -l or --language

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 project, there must be some sub directories for sure don't contain the source code.

lhy-formatter-linter by default ignore the follow directories at the first level under project root dir:

.git, build, .vscode, .cache, .pytest_cache

User can add your custom sub directories by optional argument -id or --ignore-dirs, The format of sub directories to ingore could be absolute path or relative path to project root dir

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

Or user can specify a txt file which contains the directories to ignore in content, one line for one directoy.

an example named dirs-to-ignore.txt text file content

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

Then use optional argument -ig, --ignore-file to parse those directories to ignore to formatter or linter.

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

Format or lint config files

formatter or linter will use by default the format or lint config file under project root dir.

User can put format and lint config files directly under project root dir to have you own custom formatting or linting rules.

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

Or these optional arguments below can specify the config files path:

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)
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>

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 used in CI pipeline, to guarantee all the code on remote is in norm.

jenkins example.

stage('Check code norm') {
    agent any
    steps {
        dir('script') {
            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 - see the LICENSE.md file for details.

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.6.tar.gz (6.9 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.6-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lhy_formatter_linter-0.0.6.tar.gz
Algorithm Hash digest
SHA256 66c884b3ab7081337e1cd4e1348a5e44a23ddc1259683b309051aa622674316d
MD5 2f2ba575477fbcc46466f716c875fb98
BLAKE2b-256 a7a282a1a09517bed3523113bb28be17f03c82419c2b2d58136b8b19848f5aa7

See more details on using hashes here.

Provenance

The following attestation bundles were made for lhy_formatter_linter-0.0.6.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.6-py3-none-any.whl.

File metadata

File hashes

Hashes for lhy_formatter_linter-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 149b3f1cc8806caf7c70ef80266ff9516d58f1eebedec0941fbbd4843cc5f7b6
MD5 90b97bf78580bfdae84e8367ae7e6c4a
BLAKE2b-256 2cb89b0395fec82c55d30b4260551aec31d01617f428358bf2e721eaea9d2d64

See more details on using hashes here.

Provenance

The following attestation bundles were made for lhy_formatter_linter-0.0.6-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