beechit/json-to-code-climate-subset-converter

CLI tool that'll convert supported JSON files to a subset of the Code Climate JSON format.

dev-master 2020-04-10 18:47 UTC

This package is auto-updated.

Last update: 2020-06-10 19:15:21 UTC


README

GitHub Workflow Status GitHub Workflow Status GitHub Workflow Status GitHub Workflow Status GitHub Workflow Status GitHub Workflow Status

json-to-code-climate-subset-converter

CLI tool that'll convert supported JSON files to a subset of the Code Climate JSON format. The output file code-climate.json can be used in GitLab CI to show degrations in merge requests via the report artifact. See GitLab Code Quality documentation for more information.

Work in progress

Please note this project is actively worked on but it's not ready for production use.

Supported JSON files

Example input

[
    {
        "type": "issue",
        "type_id": 11007,
        "check_name": "PhanUndeclaredClassConstant",
        "description": "UndefError PhanUndeclaredClassConstant Reference to constant class from undeclared class \\PhpParser\\Node\\Stmt\\ClassMethod",
        "severity": 10,
        "location": {
            "path": "app/Class.php",
            "lines": {
                "begin": 32,
                "end": 34
            }
        }
    }
]

Example output

[
    {
        "description": "(Phan) UndefError PhanUndeclaredClassConstant Reference to constant class from undeclared class \\PhpParser\\Node\\Stmt\\ClassMethod",
        "fingerprint": "fd46675f22771e90045b745429e46682",
        "location": {
            "path": "app/Class.php",
            "lines": {
                "begin": 32,
                "end": 34
            }
        }
    }
]

Running the CLI command

By default, no driver is included in the run. You'll have to manually specify what drivers are to be included whilst converting.

For example, if you wish to run the converter with Psalm, you'll run:

php converter convert --psalm

The included converters are enabled via their respective flags:

  • php converter convert --phpstan
  • php converter convert --psalm
  • php converter convert --phan
  • php converter convert --phpcs
  • php converter convert --phplint

If you wish to specify the Psalm input file (JSON format), you'll run:

php converter convert --psalm --psalm-json-file=path/to/file.json
  • php converter convert --phpstan --phpstan-json-file=path/to/file.json
  • php converter convert --psalm --psalm-json-file=path/to/file.json
  • php converter convert --phan --phan-json-file=path/to/file.json
  • php converter convert --phpcs --phpcs-json-file=path/to/file.json
  • php converter convert --phplint --phplint-json-file=path/to/file.json

If you're working on a project that supports multiple tools, you're free to add as many supported drivers in your command.

php converter convert --phpstan --psalm --phpcs

Running the CLI command in Docker

To build the docker image:

docker build -t converter .

To use the image to convert

docker run --rm -t -v $(pwd):/project -w /project converter convert --phpstan

This will mount the current directory in the container under /project, and execute the converter. This will also remove the container after use.

JSON output

By default a code-climate.json file is generated for you to use.