@code-pushup/eslint-plugin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/README.md +147 -0
- package/bin.js +806 -0
- package/index.js +874 -0
- package/package.json +13 -0
- package/src/bin.d.ts +1 -0
- package/src/index.d.ts +3 -0
- package/src/lib/config.d.ts +13 -0
- package/src/lib/eslint-plugin.d.ts +23 -0
- package/src/lib/meta/groups.d.ts +4 -0
- package/src/lib/meta/hash.d.ts +2 -0
- package/src/lib/meta/index.d.ts +6 -0
- package/src/lib/meta/rules.d.ts +11 -0
- package/src/lib/meta/transform.d.ts +3 -0
- package/src/lib/runner/index.d.ts +6 -0
- package/src/lib/runner/lint.d.ts +3 -0
- package/src/lib/runner/transform.d.ts +3 -0
- package/src/lib/runner/types.d.ts +13 -0
- package/src/lib/setup.d.ts +3 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
# [0.3.0](https://github.com/code-pushup/cli/compare/plugin-eslint@0.2.0...plugin-eslint@0.3.0) (2023-11-30)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- **utils:** add file-system helper ([#336](https://github.com/code-pushup/cli/issues/336)) ([001498b](https://github.com/code-pushup/cli/commit/001498b1f54460f77f46eaaa9033e4b04629c878))
|
|
10
|
+
|
|
11
|
+
# [0.2.0](https://github.com/code-pushup/cli/compare/plugin-eslint@0.1.1...plugin-eslint@0.2.0) (2023-11-30)
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
- **plugin-eslint:** ensure working directory exists before writing .eslintrc.json ([3f19d6f](https://github.com/code-pushup/cli/commit/3f19d6f7ecc8fe69dd717cdb2a9912d6a1c53033))
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
- **plugin-eslint:** add support for inline eslint config ([67571eb](https://github.com/code-pushup/cli/commit/67571eb529ade91a77e2c739a3995674e52701af))
|
|
20
|
+
|
|
21
|
+
## [0.1.1](https://github.com/code-pushup/cli/compare/plugin-eslint@0.1.0...plugin-eslint@0.1.1) (2023-11-30)
|
|
22
|
+
|
|
23
|
+
# 0.1.0 (2023-11-29)
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
- lint config and errors ([6f5f677](https://github.com/code-pushup/cli/commit/6f5f6779a37359fdde2740fa42e44e7320fa190c))
|
|
28
|
+
- **plugin-eslint:** allow unmatched patterns ([d350187](https://github.com/code-pushup/cli/commit/d350187109205788eaefd3ee280f5f80a9896cd7))
|
|
29
|
+
- **plugin-eslint:** ensure runner output directory exists ([fca87f5](https://github.com/code-pushup/cli/commit/fca87f582ccce7a6c09f823fe03d14809a878fb4))
|
|
30
|
+
- **plugin-eslint:** exclude rules which are turned off ([f2cc454](https://github.com/code-pushup/cli/commit/f2cc45424b3d14e4b0c7c9964d8be9288af1f0c4))
|
|
31
|
+
- **plugin-eslint:** handle implicitly relative config paths ([39a7d43](https://github.com/code-pushup/cli/commit/39a7d43cb900607bacb21764540f5b0a5fcf418a))
|
|
32
|
+
- **plugin-eslint:** omit empty docsUrl in audit metadata ([3127683](https://github.com/code-pushup/cli/commit/3127683b59bd328f085ff1c558db02d985e4b5cd))
|
|
33
|
+
- **plugin-eslint:** pluralize audit display value based on count ([aa35d0c](https://github.com/code-pushup/cli/commit/aa35d0cc00e505f71ccdaa6612f498d95a88c4ea))
|
|
34
|
+
- refactor after core package intro ([#83](https://github.com/code-pushup/cli/issues/83)) ([aa39d09](https://github.com/code-pushup/cli/commit/aa39d098c53f7de958509ad465c18b6bee5ec4b9))
|
|
35
|
+
- **testing:** fix tests for Windows ([#165](https://github.com/code-pushup/cli/issues/165)) ([b80255b](https://github.com/code-pushup/cli/commit/b80255b5ed93c9cb6312d8c426a82f4b8bd1cdf3)), closes [#131](https://github.com/code-pushup/cli/issues/131)
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
- **cli:** initial collect command ([#45](https://github.com/code-pushup/cli/issues/45)) ([ba048be](https://github.com/code-pushup/cli/commit/ba048be5f3e9b4291ae6311051cda89403186795))
|
|
40
|
+
- **cli:** persist login and formatting options ([#47](https://github.com/code-pushup/cli/issues/47)) ([6241fd7](https://github.com/code-pushup/cli/commit/6241fd7412f33a8d40183b40f8ed7e39e85278dd))
|
|
41
|
+
- **cli:** setup yargs for cli ([#42](https://github.com/code-pushup/cli/issues/42)) ([37ea0a5](https://github.com/code-pushup/cli/commit/37ea0a56c987ef38cf7e961d885c711b32de777a)), closes [#6](https://github.com/code-pushup/cli/issues/6) [#38](https://github.com/code-pushup/cli/issues/38)
|
|
42
|
+
- configure build and tests to handle ESM and CJS configs ([48cd967](https://github.com/code-pushup/cli/commit/48cd967866a84488e6a2382fe44687a31ca47db2))
|
|
43
|
+
- **models:** validate plugin icons using portal-client package ([f52cc75](https://github.com/code-pushup/cli/commit/f52cc75ed766e47e1d9f82fda1560e0085b3c02e))
|
|
44
|
+
- **plugin-eslint:** configure bin entry point ([b34ecb2](https://github.com/code-pushup/cli/commit/b34ecb224ff0182aab40811e1abdfe1f5446efcd))
|
|
45
|
+
- **plugin-eslint:** convert rule ids to slugs, add basic description to audits ([971c97a](https://github.com/code-pushup/cli/commit/971c97a49b583f61b9e6eb8500c4712687f5797a))
|
|
46
|
+
- **plugin-eslint:** create groups from rules' meta.docs.category (per plugin) ([56e129c](https://github.com/code-pushup/cli/commit/56e129c58be4c0544bc1c9dffec1f7ce09260254))
|
|
47
|
+
- **plugin-eslint:** create groups from rules' meta.type (problem/suggestion/layout) ([0350e49](https://github.com/code-pushup/cli/commit/0350e492c26015097ef94fb51eb15d7d334a5080))
|
|
48
|
+
- **plugin-eslint:** implement runner logic ([0ad5445](https://github.com/code-pushup/cli/commit/0ad5445e427fd365e6e039d3aa13a3a5e7c1d47e))
|
|
49
|
+
- **plugin-eslint:** include NPM package name and version ([25bda11](https://github.com/code-pushup/cli/commit/25bda113f31c20cc98832ed2f112abe0e058b54c))
|
|
50
|
+
- **plugin-eslint:** register audit metadata based on eslintrc and file patterns ([3aac581](https://github.com/code-pushup/cli/commit/3aac581acb5955b673641ee9df52e6a99656b07b))
|
|
51
|
+
- **plugin-eslint:** rule options used to identify audit, options in slug (hash) and description ([b9f51c9](https://github.com/code-pushup/cli/commit/b9f51c97d40cbfe7c62f85c4a289ad2528f1fba1))
|
|
52
|
+
- **plugin-eslint:** validate initializer params with Zod ([56e1aee](https://github.com/code-pushup/cli/commit/56e1aeeedec220fb5f68de9c3fa0eb309fbd2cf2))
|
|
53
|
+
- **utils:** add upload logic ([#66](https://github.com/code-pushup/cli/issues/66)) ([3e88ffc](https://github.com/code-pushup/cli/commit/3e88ffcbbe375f1fe01bdfd05c088253eeeb98d9)), closes [#21](https://github.com/code-pushup/cli/issues/21) [#57](https://github.com/code-pushup/cli/issues/57) [#85](https://github.com/code-pushup/cli/issues/85)
|
|
54
|
+
- **utils:** move parts from utils into core ([#81](https://github.com/code-pushup/cli/issues/81)) ([dd0a180](https://github.com/code-pushup/cli/commit/dd0a1805ddb97de14d7a4938938aa0bfd852a528)), closes [#78](https://github.com/code-pushup/cli/issues/78)
|
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# @code-pushup/eslint-plugin
|
|
2
|
+
|
|
3
|
+
🕵️ **Code PushUp plugin for detecting problems in source code using ESLint.** 📋
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The plugin parses your ESLint configuration and lints targetted files using [ESLint's Node.js API](https://eslint.org/docs/latest/integrate/nodejs-api).
|
|
8
|
+
|
|
9
|
+
Detected ESLint rules are mapped to Code PushUp audits. Audit reports are calculated from the lint results in the following way:
|
|
10
|
+
|
|
11
|
+
- the score is a binary "pass" or "fail" - 1 if no errors or warnings are found, otherwise 0
|
|
12
|
+
- the value equals the sum of all errors and warnings
|
|
13
|
+
- individual errors and warnings are mapped to issues in the audit details
|
|
14
|
+
|
|
15
|
+
## Getting started
|
|
16
|
+
|
|
17
|
+
1. If you haven't already, install [@code-pushup/cli](../cli/README.md) and create a configuration file.
|
|
18
|
+
|
|
19
|
+
2. Install as a dev dependency with your package manager:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm install --save-dev @code-pushup/eslint-plugin
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
yarn add --dev @code-pushup/eslint-plugin
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pnpm add --save-dev @code-pushup/eslint-plugin
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
3. Prepare an [ESLint configuration file](https://eslint.org/docs/latest/use/configure/configuration-files) with rules you're interested in measuring.
|
|
34
|
+
|
|
35
|
+
Remember that Code PushUp only collects and uploads the results, it doesn't fail if errors are found.
|
|
36
|
+
So you can be more strict than in most linter setups, the idea is to set aspirational goals and track your progress.
|
|
37
|
+
|
|
38
|
+
4. Add this plugin to the `plugins` array in your Code PushUp CLI config file (e.g. `code-pushup.config.js`).
|
|
39
|
+
|
|
40
|
+
Pass in the path to your ESLint config file, along with glob patterns for which files you wish to target (relative to `process.cwd()`).
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import eslintPlugin from '@code-pushup/eslint-plugin';
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
// ...
|
|
47
|
+
plugins: [
|
|
48
|
+
// ...
|
|
49
|
+
await eslintPlugin({ eslintrc: '.eslintrc.js', patterns: ['src/**/*.js'] }),
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
5. (Optional) Reference audits (or groups) which you wish to include in custom categories (use `npx code-pushup print-config` to list audits and groups).
|
|
55
|
+
|
|
56
|
+
Assign weights based on what influence each ESLint rule should have on the overall category score (assign weight 0 to only include as extra info, without influencing category score).
|
|
57
|
+
Note that categories can combine multiple plugins.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
export default {
|
|
61
|
+
// ...
|
|
62
|
+
categories: [
|
|
63
|
+
{
|
|
64
|
+
slug: 'code-style',
|
|
65
|
+
title: 'Code style',
|
|
66
|
+
refs: [
|
|
67
|
+
{
|
|
68
|
+
type: 'audit',
|
|
69
|
+
plugin: 'eslint',
|
|
70
|
+
slug: 'no-var',
|
|
71
|
+
weight: 1,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'audit',
|
|
75
|
+
plugin: 'eslint',
|
|
76
|
+
slug: 'prefer-const',
|
|
77
|
+
weight: 1,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: 'audit',
|
|
81
|
+
plugin: 'eslint',
|
|
82
|
+
slug: 'react-hooks-rules-of-hooks',
|
|
83
|
+
weight: 2,
|
|
84
|
+
},
|
|
85
|
+
// ...
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
slug: 'performance',
|
|
90
|
+
title: 'Performance',
|
|
91
|
+
refs: [
|
|
92
|
+
// ... weighted performance audits (e.g. from Lighthouse) ...
|
|
93
|
+
{
|
|
94
|
+
type: 'audit',
|
|
95
|
+
plugin: 'eslint',
|
|
96
|
+
slug: 'react-jsx-key',
|
|
97
|
+
weight: 0,
|
|
98
|
+
},
|
|
99
|
+
// ...
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
// ...
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Referencing individual audits provides a lot of granularity, but it can be difficult to maintain such a configuration when there is a high amount of lint rules. A simpler way is to reference many related audits at once using groups. E.g. you can distinguish rules which have declared a type of `problem`, `suggestion`, or `layout`:
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
export default {
|
|
111
|
+
// ...
|
|
112
|
+
categories: [
|
|
113
|
+
{
|
|
114
|
+
slug: 'bug-prevention',
|
|
115
|
+
title: 'Bug prevention',
|
|
116
|
+
refs: [
|
|
117
|
+
{
|
|
118
|
+
type: 'group',
|
|
119
|
+
plugin: 'eslint',
|
|
120
|
+
slug: 'problems',
|
|
121
|
+
weight: 100,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
slug: 'code-style',
|
|
127
|
+
title: 'Code style',
|
|
128
|
+
refs: [
|
|
129
|
+
{
|
|
130
|
+
type: 'group',
|
|
131
|
+
plugin: 'eslint',
|
|
132
|
+
slug: 'suggestions',
|
|
133
|
+
weight: 75,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: 'group',
|
|
137
|
+
plugin: 'eslint',
|
|
138
|
+
slug: 'formatting',
|
|
139
|
+
weight: 25,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
};
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
6. Run the CLI with `npx code-pushup collect` and view or upload report (refer to [CLI docs](../cli/README.md)).
|