lhy-formatter-linter


Namelhy-formatter-linter JSON
Version 0.0.8 PyPI version JSON
download
home_pageNone
SummaryThis package provides formatters and linters for CMake, C++, and Python, making it ideal for developers who work with both C++ and Python.
upload_time2025-02-18 09:28:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License
keywords cmake-format lint clang-format clang-tidy flake8 code format code lint lhy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```sh
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   | 
| linter           | cmake-lint   | clang-tidy      | flake8 | 

```sh
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

```sh
lhy format -p <project-root-dir> 
```
### lint code in yout project

```sh
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.


```sh
lhy format -p <project-root-dir> -l cmake
```

```sh
lhy lint -p <project-root-dir> -l python
```

```sh
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.


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

```sh
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.

```sh
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.


```sh

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

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

#### formatter config file path arguments
```sh
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)
```

```sh

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

```sh

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.
```jenkins

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. For more information, please refer to the [LICENSE.md](https://github.com/sygslhy/coding_tools/blob/main/LICENSE.md) file.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "lhy-formatter-linter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Yuan SUN <sunyuan860510@gmail.com>",
    "keywords": "cmake-format, lint, clang-format, clang-tidy, flake8, code format, code lint, lhy",
    "author": null,
    "author_email": "Yuan SUN <sunyuan860510@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/5b/cd/85755d85bad5294f33fc2dfa0c0b98cd32740dc7b2a603ffbcdc50e508e3/lhy_formatter_linter-0.0.8.tar.gz",
    "platform": null,
    "description": "# Generic formatter and linter\n\nThis package provides formatters and linters for CMake, C++, and Python, making it ideal for developers who work with both C++ and Python.\n\n# Getting Started\n\n## Installation\n\n```sh\npip install lhy-formatter-linter\n```\n\n## Usage\n\nThe formatter or linter will recursively scan your project directory, formatting or linting all CMake, C++, and Python code using third-party tools.\n\n| third-party tool | cmake        | C++             | python | \n|------------------|--------------|-----------------|--------|\n| formatter        | cmake-format | clang-format    | yapf   | \n| linter           | cmake-lint   | clang-tidy      | flake8 | \n\n```sh\nlhy -h\nusage: lhy [-h] {format,lint} ...\n\ncode formatter and linter.\n\npositional arguments:\n  {format,lint}\n    format       Format code\n    lint         Lint code\n```\n\n### format code in yout project\n\n```sh\nlhy format -p <project-root-dir> \n```\n### lint code in yout project\n\n```sh\nlhy lint -p <project-root-dir> \n```\n\n## Optional arguments\n\n### Choose languages \n\nUsers can choose to format or lint one or more languages by using the `-l` or `--language` option.\n\n\n```sh\nlhy format -p <project-root-dir> -l cmake\n```\n\n```sh\nlhy lint -p <project-root-dir> -l python\n```\n\n```sh\nlhy lint -p <project-root-dir> -l cmake cxx\n```\n\n### Ignore no-source directories\n\nIn a project, there are typically subdirectories that do not contain source code.\n\nBy default, `lhy-formatter-linter` ignores the following directories at the top level under the project root directory:\n\n* `.git`\n* `build`\n* `.vscode`\n* `.cache`\n* `.pytest_cache`\n\nUsers 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.\n\n\n```sh\nlhy format -p <project-root-dir> --ignore-dirs .github py_venv <project_root_dir>/docs\n```\n\n```sh\nlhy lint -p <project-root-dir> --ignore-dirs <project_root_dir>/.github  <project_root_dir>/py_venv docs\n```\nAlternatively, users can specify a text file that contains the directories to ignore, with one directory per line.\n\nFor example, a file named `dirs-to-ignore.txt` could have the following content:\n\n```\n<project_root_dir>/.github\n<project_root_dir>/py_venv\ndocs\n```\nThen, 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.\n\n```sh\nlhy format -p <project-root-dir> --ignore-file dirs-to-ignore.txt\n```\n\n### Format or lint config files\n\nBy default, the formatter or linter will use the format or lint configuration files located directly under the project root directory.\n\nUsers 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.\n\n\n```sh\n\n\u2514\u2500\u2500 user\n    \u251c\u2500\u2500 project_root_dir\n    \u2502   \u251c\u2500\u2500 src\n    \u2502   \u251c\u2500\u2500 .clang-format\n    \u2502   \u251c\u2500\u2500 .clang-tidy\n    \u2502   \u251c\u2500\u2500 .cmake-format\n    \u2502   \u251c\u2500\u2500 .flake8\n    \u2502   \u2514\u2500\u2500 .style.yapf\n\n```\nAlternatively, users can specify the configuration file paths using the following optional arguments:\n\n#### formatter config file path arguments\n```sh\noptional cmake format arguments:\n  --cmake-format-config CMAKE_FORMAT_CONFIG\n                        Path of cmake format custom config file (default: None)\n\noptional c++ format arguments:\n  --clang-format-config CLANG_FORMAT_CONFIG\n                        Path of clang format custom config file (default: None)\n\noptional python format arguments:\n  --yapf-config YAPF_CONFIG\n                        Path of yapf custom config file (default: None)\n```\n\n```sh\n\nlhy format -p <project-root-dir> \\\n    --cmake-format-config <cmake-format-config-absolute-file-path> \\\n    --clang-format-config <clang-format-config-absolute-file-path> \\\n    --yapf-config <yapf-config-absolute-file-path>\n```\n\n\n#### linter config file path arguments\n```sh\noptional cmake lint arguments:\n  --cmake-lint-config CMAKE_LINT_CONFIG\n                        Path of cmake lint custom config file (default: None)\n\noptional c++ format arguments:\n  --clang-tidy-config CLANG_TIDY_CONFIG\n                        Path of clang tidy custom config file (default: None)\n\noptional python format arguments:\n  --flake8-config FLAKE8_CONFIG\n                        Path of flake8 custom config file (default: None)\n```\n\n```sh\n\nlhy format -p <project-root-dir> \\\n    --cmake-lint-config <cmake-lint-config-absolute-file-path> \\\n    --clang-tidy-config <clang-tidy-config-absolute-file-path> \\\n    --flake8-config <flake8-config-absolute-file-path>\n```\n\n## Integrate to CI\n\nThis 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.\n\n\n### jenkins example.\n```jenkins\n\nstage('Check code norm') {\n    agent any\n    steps {\n        dir('script') {\n            sh 'lhy lint -p <project_root_dir>'\n            sh 'lhy format -p <project_root_dir>'\n        }\n        sh 'git diff --exit-code'\n    }\n}\n\n```\n\n\n\n# License\n\nThis project is licensed under the MIT License. For more information, please refer to the [LICENSE.md](https://github.com/sygslhy/coding_tools/blob/main/LICENSE.md) file.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "This package provides formatters and linters for CMake, C++, and Python, making it ideal for developers who work with both C++ and Python.",
    "version": "0.0.8",
    "project_urls": {
        "Homepage": "https://github.com/sygslhy/lhy-formatter-linter",
        "Issues": "https://github.com/sygslhy/lhy-formatter-linter/issues",
        "Releases": "https://github.com/sygslhy/lhy-formatter-linter/releases",
        "Repository": "https://github.com/sygslhy/lhy-formatter-linter"
    },
    "split_keywords": [
        "cmake-format",
        " lint",
        " clang-format",
        " clang-tidy",
        " flake8",
        " code format",
        " code lint",
        " lhy"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8b47d8d774622a2e35fc4d94331a39890b6a28eac461ff2fe1b09c03bdfb075d",
                "md5": "e79ceebb612f0288e2d6116543e82c49",
                "sha256": "cbd6a8dc2013632c44ee01383b2ef5a15771ae76079bc7cc2095031ce659d1b6"
            },
            "downloads": -1,
            "filename": "lhy_formatter_linter-0.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e79ceebb612f0288e2d6116543e82c49",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 8577,
            "upload_time": "2025-02-18T09:28:48",
            "upload_time_iso_8601": "2025-02-18T09:28:48.385366Z",
            "url": "https://files.pythonhosted.org/packages/8b/47/d8d774622a2e35fc4d94331a39890b6a28eac461ff2fe1b09c03bdfb075d/lhy_formatter_linter-0.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5bcd85755d85bad5294f33fc2dfa0c0b98cd32740dc7b2a603ffbcdc50e508e3",
                "md5": "eeb1e928a66d5efeec4a5e8c8cfed54c",
                "sha256": "582bcd17c9fb19ed0ffad218dbb6b8453b6931a7f8c6ae2bf444171c934be031"
            },
            "downloads": -1,
            "filename": "lhy_formatter_linter-0.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "eeb1e928a66d5efeec4a5e8c8cfed54c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 7183,
            "upload_time": "2025-02-18T09:28:49",
            "upload_time_iso_8601": "2025-02-18T09:28:49.602196Z",
            "url": "https://files.pythonhosted.org/packages/5b/cd/85755d85bad5294f33fc2dfa0c0b98cd32740dc7b2a603ffbcdc50e508e3/lhy_formatter_linter-0.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-18 09:28:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sygslhy",
    "github_project": "lhy-formatter-linter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "lhy-formatter-linter"
}
        
Elapsed time: 0.47370s