|
| 1 | +# eslint-formatter-codeclimate |
| 2 | + |
| 3 | +[](https://github.com/remcohaszing/eslint-formatter-codeclimate/actions/workflows/ci.yaml) |
| 4 | +[](https://codecov.io/gh/remcohaszing/eslint-formatter-codeclimate) |
| 5 | +[](https://www.npmjs.com/package/eslint-formatter-codeclimate) |
| 6 | +[](https://www.npmjs.com/package/eslint-formatter-codeclimate) |
| 7 | + |
| 8 | +Format [ESLint](https://eslint.org) results as a |
| 9 | +[Code Climate](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md) report. |
| 10 | + |
| 11 | +## Table of Contents |
| 12 | + |
| 13 | +- [Installation](#installation) |
| 14 | +- [Usage](#usage) |
| 15 | + - [Command Line](#command-line) |
| 16 | +- [API](#api) |
| 17 | + - [`toCodeClimate(results, rulesMeta, cwd)`](#tocodeclimateresults-rulesmeta-cwd) |
| 18 | + - [`formatter()`](#formatter) |
| 19 | +- [Compatibility](#compatibility) |
| 20 | +- [License](#license) |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +```sh |
| 25 | +npm install eslint-formatter-codeclimate |
| 26 | +``` |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +### Command Line |
| 31 | + |
| 32 | +Using the ESLint CLI: |
| 33 | + |
| 34 | +```sh |
| 35 | +eslint --format codeclimate |
| 36 | +``` |
| 37 | + |
| 38 | +Programmatically using Node.js: |
| 39 | + |
| 40 | +```js |
| 41 | +import { ESLint } from 'eslint' |
| 42 | +import { toCodeClimate } from 'eslint-formatter-codeclimate' |
| 43 | + |
| 44 | +const cwd = process.cwd() |
| 45 | +const eslint = new ESLint({ cwd }) |
| 46 | +const results = await eslint.lintFiles([]) |
| 47 | +const rulesMeta = eslint.getRulesMetaForResults(results) |
| 48 | +const issues = toCodeClimate(results, rulesMeta, cwd) |
| 49 | + |
| 50 | +console.log(issues) |
| 51 | +``` |
| 52 | + |
| 53 | +## API |
| 54 | + |
| 55 | +### `toCodeClimate(results, rulesMeta, cwd)` |
| 56 | + |
| 57 | +Convert ESLint messages to CodeClimate issues. |
| 58 | + |
| 59 | +#### Arguments |
| 60 | + |
| 61 | +- `results` (`ESLint.LintResult[]`) — The ESLint report results. |
| 62 | +- `rulesMeta` (`Record<string, Rule.RuleMetaData>`) — The ESLint rule meta data. |
| 63 | +- `cwd` (`string`) — The current work directory to calculate relative paths against. |
| 64 | + |
| 65 | +#### Returns |
| 66 | + |
| 67 | +The ESLint messages in the form of a GitLab code quality report. |
| 68 | + |
| 69 | +### `formatter()` |
| 70 | + |
| 71 | +The default export is an ESLint formatter which represents ESLint results as a CodeClimate report. |
| 72 | + |
| 73 | +#### Arguments |
| 74 | + |
| 75 | +- `results` (`ESLint.LintResult[]`) — The ESLint report results. |
| 76 | +- `data` (`ESLint.LintResultData`) — The ESLint report result data. |
| 77 | + |
| 78 | +#### Returns |
| 79 | + |
| 80 | +The Code Climate report as a string. |
| 81 | + |
| 82 | +## Compatibility |
| 83 | + |
| 84 | +This project is compatible with Node.js 20 or greater. |
| 85 | + |
| 86 | +## License |
| 87 | + |
| 88 | +[MIT](LICENSE.md) © [Remco Haszing](https://github.com/remcohaszing) |
0 commit comments