Skip to content

Commit

Permalink
Fix error in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Topin2001 authored Apr 23, 2024
1 parent 74601ab commit f025365
Showing 1 changed file with 21 additions and 41 deletions.
62 changes: 21 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

This project is a fork of [pylint-sonarjson](https://github.com/omegacen/pylint-sonarjson), which is not maintained anymore.

A PyLint plugin that can output to [SonarQube-importable JSON](https://docs.sonarqube.org/latest/analysis/generic-issue/)
with configurable issue severity, effort, and type.
A PyLint plugin that can output to [SonarQube-importable JSON](https://docs.sonarqube.org/latest/analysis/generic-issue/) with configurable issue severity, effort, and type.

This is useful because when importing PyLint's
[parsable output](https://pylint.pycqa.org/en/latest/user_guide/output.html#output-options)
via [SonarQube mechanism for third-party issues](https://docs.sonarqube.org/latest/analysis/external-issues/)
all the severities are set to `MAJOR`. With `pylint-sonarjson-catlab` you can configure the
issue severity per PyLint message ID, and import that as generic JSON in SonarQube.
This is useful because when importing PyLint's [parsable output](https://pylint.pycqa.org/en/latest/user_guide/output.html#output-options) via [SonarQube mechanism for third-party issues](https://docs.sonarqube.org/latest/analysis/external-issues/) all the severities are set to `MAJOR`. With `pylint-sonarjson-catlab` you can configure the issue severity per PyLint message ID, and import that as generic JSON in SonarQube.

## Usage

```
$ pylint \
--load-plugins=pylint_sonarjson_catlab \
```shell
pylint \
--load-plugins=pylint_sonarjson \
--output-format=sonarjson \
--sonar-rules=<msg_id>:<severity>[:<effort>[:<type>]],... \
--sonar-default-severity=<severity> \
Expand All @@ -26,32 +21,20 @@ $ pylint \
[...]
```
The plugin provides a new option `sonar-rules` that can configure the severity,
effort, and type of the issue as it would appear in SonarQube. The option takes
a comma-separated list whose items are of the form `<msg_id>:<severity>:<effort>:<type>`.
The plugin provides a new option `sonar-rules` that can configure the severity, effort, and type of the issue as it would appear in SonarQube. The option takes a comma-separated list whose items are of the form `<msg_id>:<severity>:<effort>:<type>`.
The effort and type are optional and may be omitted.
In addition, the default severity, effort, and type for messages that are not listed
in `sonar-rules` can respectively be set with `sonar-default-severity`,
`sonar-default-effort`, `sonar-default-type`. They default to `MINOR`, `5`, and
`CODE_SMELL` respectively.
In addition, the default severity, effort, and type for messages that are not listed in `sonar-rules` can respectively be set with `sonar-default-severity`, `sonar-default-effort`, `sonar-default-type`. They default to `MINOR`, `5`, and `CODE_SMELL` respectively.
Setting the option `only-enable-sonar-rules` to `y` disables all messages
except for those specified in `sonar-rules`. It is equivalent to
`--disable=all --enable=<msg_id>,...` where `<msg_id>,...` are the message IDs
specified in `sonar-rules`. The default value of `only-enable-sonar-rules` is `n`.
Setting the option `only-enable-sonar-rules` to `y` disables all messages except for those specified in `sonar-rules`. It is equivalent to `--disable=all --enable=<msg_id>,...` where `<msg_id>,...` are the message IDs specified in `sonar-rules`. The default value of `only-enable-sonar-rules` is `n`.
Lastly, enabling the option `halt-on-invalid-sonar-rules` will cause the plugin
to raise an exception when a rule given in `sonar-rules` does not exist in Pylint
and halt. Disabling this option will instead only report the invalid rule on
stderr but will otherwise ignore the invalid rule. The default value of
`halt-on-invalid-sonar-rules` is `y`.`
Lastly, enabling the option `halt-on-invalid-sonar-rules` will cause the plugin to raise an exception when a rule given in `sonar-rules` does not exist in Pylint and halt. Disabling this option will instead only report the invalid rule on stderr but will otherwise ignore the invalid rule. The default value of `halt-on-invalid-sonar-rules` is `y`.`
For example:
```
$ pylint \
--load-plugins=pylint_sonarjson_catlab \
```shell
pylint \
--load-plugins=pylint_sonarjson \
--output-format=sonarjson \
--sonar-rules=C0114:INFO:10,C0328:MINOR:1 \
my_file.py
Expand Down Expand Up @@ -83,28 +66,26 @@ Output:
This output, when saved to a file, can be imported into SonarQube as follows:
```
$ sonar-scanner -Dsonar.externalIssuesReportPaths=<path_to_pylint_sonarjson_catlab_log>
```shell
sonar-scanner -Dsonar.externalIssuesReportPaths=<path_to_pylint_sonarjson_catlab_log>
```
## Installation
```
pip install pylint-sonarjson_catlab
```shell
pip install pylint-sonarjson-catlab
```
## Configuration via pylintrc or pyproject.toml
Instead of via the command line, the plugin can be configured via a `pylintrc` file
or via `pyproject.toml`,
Instead of via the command line, the plugin can be configured via a `pylintrc` file or via `pyproject.toml`,
[as described in the Pylint documentation](https://pylint.pycqa.org/en/latest/user_guide/usage/run.html#command-line-options).
Here is an exampe `pylintrc` file, generated with the `--generate-rcfile`
command line option:
Here is an exampe `pylintrc` file, generated with the `--generate-rcfile` command line option:
```
```yaml
[MAIN]
load-plugins=pylint_sonarjson_catlab
load-plugins=pylint_sonarjson
[REPORTS]
Expand Down Expand Up @@ -137,5 +118,4 @@ sonar-default-type=CODE_SMELL
sonar-rules=C0114:INFO:10,C0328:MINOR:1
```
Similar output for `pyproject.toml` can be generated with the `--generate-toml-config`
command line option.
Similar output for `pyproject.toml` can be generated with the `--generate-toml-config` command line option.

0 comments on commit f025365

Please sign in to comment.