metalint 0.11.1 → 0.12.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/README.md +129 -37
- package/package.json +25 -32
- package/src/bin/argv.js +102 -0
- package/src/bin/help.txt +3 -7
- package/src/bin/index.js +49 -75
- package/src/core/configuration/flatten.js +289 -0
- package/src/core/configuration/normalize.js +510 -0
- package/src/core/configuration/override.js +47 -0
- package/src/core/formatter/checkstyle.js +49 -54
- package/src/core/formatter/console.js +61 -53
- package/src/core/formatter/csv.js +25 -25
- package/src/core/formatter/formatter.js +101 -0
- package/src/core/formatter/github.js +36 -42
- package/src/core/formatter/json.js +26 -23
- package/src/core/formatter/unix.js +25 -25
- package/src/core/index.js +98 -46
- package/src/core/levels.js +18 -0
- package/src/core/{severity.js → severities.js} +3 -1
- package/src/core/utils/array.js +16 -0
- package/src/core/utils/file.js +23 -0
- package/src/core/utils/glob.js +257 -0
- package/src/core/utils/object.js +44 -0
- package/src/core/wrapper/addons-linter.js +88 -59
- package/src/core/wrapper/coffeelint__cli.js +80 -0
- package/src/core/wrapper/csslint.js +67 -35
- package/src/core/wrapper/doiuse.js +68 -41
- package/src/core/wrapper/eslint.js +89 -62
- package/src/core/wrapper/htmlhint.js +67 -35
- package/src/core/wrapper/htmllint.js +61 -32
- package/src/core/wrapper/jshint.js +67 -38
- package/src/core/wrapper/jsonlint-mod.js +51 -35
- package/src/core/wrapper/markdownlint.js +68 -40
- package/src/core/wrapper/markuplint.js +74 -44
- package/src/core/wrapper/npm-package-json-lint.js +72 -38
- package/src/core/wrapper/prantlf__jsonlint.js +84 -0
- package/src/core/wrapper/prettier.js +99 -48
- package/src/core/wrapper/purgecss.js +74 -44
- package/src/core/wrapper/standard.js +72 -50
- package/src/core/wrapper/stylelint.js +77 -43
- package/src/core/wrapper/wrapper.js +150 -0
- package/src/core/wrapper/yaml-lint.js +67 -39
- package/src/type/index.d.ts +149 -0
- package/types/configuration/flatten.d.ts +55 -0
- package/types/configuration/normalize.d.ts +50 -0
- package/types/configuration/override.d.ts +3 -0
- package/types/formatter/checkstyle.d.ts +24 -41
- package/types/formatter/console.d.ts +31 -38
- package/types/formatter/csv.d.ts +17 -32
- package/types/formatter/formatter.d.ts +44 -0
- package/types/formatter/github.d.ts +21 -33
- package/types/formatter/json.d.ts +27 -56
- package/types/formatter/unix.d.ts +19 -44
- package/types/index.d.ts +14 -10
- package/types/levels.d.ts +8 -0
- package/types/{severity.d.ts → severities.d.ts} +0 -1
- package/types/utils/array.d.ts +1 -0
- package/types/utils/file.d.ts +1 -0
- package/types/utils/glob.d.ts +39 -0
- package/types/utils/object.d.ts +1 -0
- package/types/wrapper/addons-linter.d.ts +36 -4
- package/types/wrapper/coffeelint__cli.d.ts +36 -0
- package/types/wrapper/csslint.d.ts +36 -4
- package/types/wrapper/doiuse.d.ts +36 -4
- package/types/wrapper/eslint.d.ts +36 -5
- package/types/wrapper/htmlhint.d.ts +36 -4
- package/types/wrapper/htmllint.d.ts +36 -4
- package/types/wrapper/jshint.d.ts +36 -4
- package/types/wrapper/jsonlint-mod.d.ts +35 -4
- package/types/wrapper/markdownlint.d.ts +36 -4
- package/types/wrapper/markuplint.d.ts +36 -4
- package/types/wrapper/npm-package-json-lint.d.ts +36 -4
- package/types/wrapper/prantlf__jsonlint.d.ts +37 -0
- package/types/wrapper/prettier.d.ts +36 -5
- package/types/wrapper/purgecss.d.ts +36 -5
- package/types/wrapper/standard.d.ts +36 -4
- package/types/wrapper/stylelint.d.ts +36 -5
- package/types/wrapper/wrapper.d.ts +67 -0
- package/types/wrapper/yaml-lint.d.ts +36 -4
- package/src/core/glob.js +0 -211
- package/src/core/normalize.js +0 -574
- package/src/core/wrapper/coffeelint.js +0 -47
- package/src/core/wrapper/flow-bin.js +0 -91
- package/src/core/wrapper/json-lint.js +0 -55
- package/src/core/wrapper/jsonlint.js +0 -54
- package/src/core/wrapper/lesshint.js +0 -67
- package/src/types.d.ts +0 -35
- package/types/glob.d.ts +0 -9
- package/types/normalize.d.ts +0 -18
- package/types/wrapper/coffeelint.d.ts +0 -4
- package/types/wrapper/flow-bin.d.ts +0 -4
- package/types/wrapper/json-lint.d.ts +0 -4
- package/types/wrapper/jsonlint.d.ts +0 -4
- package/types/wrapper/lesshint.d.ts +0 -4
package/README.md
CHANGED
|
@@ -14,46 +14,138 @@
|
|
|
14
14
|
## Description
|
|
15
15
|
|
|
16
16
|
**Metalint** est un outil pour analyser tous les fichiers de votre projet.
|
|
17
|
-
L'analyse est déléguée à des linters (outils d'analyse statique de code
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
17
|
+
L'analyse est déléguée à des linters (outils d'analyse statique de code
|
|
18
|
+
source) :
|
|
19
|
+
|
|
20
|
+
<!-- markdownlint-disable no-inline-html -->
|
|
21
|
+
<table>
|
|
22
|
+
<tr>
|
|
23
|
+
<th>Langage / Technologie</th>
|
|
24
|
+
<th>Linters</th>
|
|
25
|
+
</tr>
|
|
26
|
+
<tr>
|
|
27
|
+
<td>CoffeeScript</td>
|
|
28
|
+
<td>
|
|
29
|
+
<a title="@coffeelint/cli"
|
|
30
|
+
href="https://www.npmjs.com/package/@coffeelint/cli">CoffeeLint</a>
|
|
31
|
+
</td>
|
|
32
|
+
</tr>
|
|
33
|
+
<tr>
|
|
34
|
+
<td>CSS</td>
|
|
35
|
+
<td>
|
|
36
|
+
<a title="csslint"
|
|
37
|
+
href="https://www.npmjs.com/package/csslint">CSSLint</a>,
|
|
38
|
+
<a title="doiuse" href="https://www.npmjs.com/package/doiuse">doiuse</a>,
|
|
39
|
+
<a title="prettier"
|
|
40
|
+
href="https://www.npmjs.com/package/prettier">Prettier</a>,
|
|
41
|
+
<a title="purgecss"
|
|
42
|
+
href="https://www.npmjs.com/package/purgecss">PurgeCSS</a>,
|
|
43
|
+
<a title="stylelint"
|
|
44
|
+
href="https://www.npmjs.com/package/stylelint">Stylelint</a>
|
|
45
|
+
</td>
|
|
46
|
+
</tr>
|
|
47
|
+
<tr>
|
|
48
|
+
<td>HTML</td>
|
|
49
|
+
<td>
|
|
50
|
+
<a title="htmlhint"
|
|
51
|
+
href="https://www.npmjs.com/package/htmlhint">HTMLHint</a>,
|
|
52
|
+
<a title="htmllint"
|
|
53
|
+
href="https://www.npmjs.com/package/htmllint">htmllint</a>,
|
|
54
|
+
<a title="markuplint"
|
|
55
|
+
href="https://www.npmjs.com/package/markuplint">markuplint</a>,
|
|
56
|
+
<a title="prettier"
|
|
57
|
+
href="https://www.npmjs.com/package/prettier">Prettier</a>
|
|
58
|
+
</td>
|
|
59
|
+
</tr>
|
|
60
|
+
<tr>
|
|
61
|
+
<td>JavaScript</td>
|
|
62
|
+
<td>
|
|
63
|
+
<a title="eslint" href="https://www.npmjs.com/package/eslint">ESLint</a>,
|
|
64
|
+
<a title="jshint" href="https://www.npmjs.com/package/jshint">JSHint</a>,
|
|
65
|
+
<a title="standard"
|
|
66
|
+
href="https://www.npmjs.com/package/standard">JavaScript Standard
|
|
67
|
+
Style</a>,
|
|
68
|
+
<a title="prettier"
|
|
69
|
+
href="https://www.npmjs.com/package/prettier">Prettier</a>
|
|
70
|
+
</td>
|
|
71
|
+
</tr>
|
|
72
|
+
<tr>
|
|
73
|
+
<td>JSON</td>
|
|
74
|
+
<td>
|
|
75
|
+
<a title="@prantlf/jsonlint"
|
|
76
|
+
href="https://www.npmjs.com/package/@prantlf/jsonlint">@prantlf/JSON
|
|
77
|
+
Lint</a>,
|
|
78
|
+
<a title="jsonlint-mod"
|
|
79
|
+
href="https://www.npmjs.com/package/jsonlint-mod">JSON Lint (mod)</a>,
|
|
80
|
+
<a title="prettier"
|
|
81
|
+
href="https://www.npmjs.com/package/prettier">Prettier</a>
|
|
82
|
+
</td>
|
|
83
|
+
</tr>
|
|
84
|
+
<tr>
|
|
85
|
+
<td>Less</td>
|
|
86
|
+
<td>
|
|
87
|
+
<a title="prettier"
|
|
88
|
+
href="https://www.npmjs.com/package/prettier">Prettier</a>,
|
|
89
|
+
<a title="stylelint"
|
|
90
|
+
href="https://www.npmjs.com/package/stylelint">Stylelint</a>
|
|
91
|
+
</td>
|
|
92
|
+
</tr>
|
|
93
|
+
<tr>
|
|
94
|
+
<td>Markdown</td>
|
|
95
|
+
<td>
|
|
96
|
+
<a title="markdownlint"
|
|
97
|
+
href="https://www.npmjs.com/package/markdownlint">MarkdownLint</a>
|
|
98
|
+
</td>
|
|
99
|
+
</tr>
|
|
100
|
+
<tr>
|
|
101
|
+
<td>package.json</td>
|
|
102
|
+
<td>
|
|
103
|
+
<a title="npm-package-json-lint"
|
|
104
|
+
href="https://www.npmjs.com/package/npm-package-json-lint"
|
|
105
|
+
>npm-package-json-lint</a>
|
|
106
|
+
</td>
|
|
107
|
+
</tr>
|
|
108
|
+
<tr>
|
|
109
|
+
<td>SCSS</td>
|
|
110
|
+
<td>
|
|
111
|
+
<a title="prettier"
|
|
112
|
+
href="https://www.npmjs.com/package/prettier">Prettier</a>,
|
|
113
|
+
<a title="stylelint"
|
|
114
|
+
href="https://www.npmjs.com/package/stylelint">Stylelint</a>
|
|
115
|
+
</td>
|
|
116
|
+
</tr>
|
|
117
|
+
<tr>
|
|
118
|
+
<td>SugarSS</td>
|
|
119
|
+
<td>
|
|
120
|
+
<a title="stylelint"
|
|
121
|
+
href="https://www.npmjs.com/package/stylelint">Stylelint</a>
|
|
122
|
+
</td>
|
|
123
|
+
</tr>
|
|
124
|
+
<tr>
|
|
125
|
+
<td>WebExtension</td>
|
|
126
|
+
<td>
|
|
127
|
+
<a title="addons-linter"
|
|
128
|
+
href="https://www.npmjs.com/package/addons-linter">Add-ons Linter</a>
|
|
129
|
+
</td>
|
|
130
|
+
</tr>
|
|
131
|
+
<tr>
|
|
132
|
+
<td>YAML</td>
|
|
133
|
+
<td>
|
|
134
|
+
<a title="yaml-lint"
|
|
135
|
+
href="https://www.npmjs.com/package/yaml-lint">YAML Lint</a>,
|
|
136
|
+
<a title="prettier"
|
|
137
|
+
href="https://www.npmjs.com/package/prettier">Prettier</a>
|
|
138
|
+
</td>
|
|
139
|
+
</tr>
|
|
140
|
+
</table>
|
|
141
|
+
<!-- markdownlint-enable no-inline-html -->
|
|
50
142
|
|
|
51
143
|
## Installation
|
|
52
144
|
|
|
53
145
|
Vous pouvez installer Metalint en utilisant [npm][link-npm] :
|
|
54
146
|
|
|
55
147
|
```Shell
|
|
56
|
-
npm install
|
|
148
|
+
npm install --save-dev metalint
|
|
57
149
|
```
|
|
58
150
|
|
|
59
151
|
## Configuration
|
|
@@ -68,15 +160,15 @@ linters.
|
|
|
68
160
|
|
|
69
161
|
Dans cet exemple des fichiers de configuration, Metalint analyse les fichiers
|
|
70
162
|
JavaScript (non-minifiés), HTML et CSS ; avec respectivement les linters ESLint,
|
|
71
|
-
HTMLHint et
|
|
163
|
+
HTMLHint et Stylelint.
|
|
72
164
|
|
|
73
165
|
```JavaScript
|
|
74
166
|
// .metalint/metalint.config.js
|
|
75
167
|
export default {
|
|
76
|
-
patterns: ["!/.git
|
|
168
|
+
patterns: ["**", "!/.git/**", "!/node_modules/**"],
|
|
77
169
|
checkers: [
|
|
78
170
|
{
|
|
79
|
-
patterns: ["
|
|
171
|
+
patterns: ["*.js", "!*.min.js"],
|
|
80
172
|
linters: "eslint",
|
|
81
173
|
}, {
|
|
82
174
|
patterns: "*.html",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metalint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Un linter pour les gouverner tous.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"checker",
|
|
@@ -27,72 +27,65 @@
|
|
|
27
27
|
"repository": "regseb/metalint",
|
|
28
28
|
"type": "module",
|
|
29
29
|
"scripts": {
|
|
30
|
-
"lint": "src/bin/index.js",
|
|
31
|
-
"lint:fix": "src/bin/index.js --fix",
|
|
30
|
+
"lint": "node src/bin/index.js",
|
|
31
|
+
"lint:fix": "node src/bin/index.js --fix",
|
|
32
32
|
"lint:types": "tsc --project .tsconfig_lint.json",
|
|
33
33
|
"test": "npm run test:unit",
|
|
34
|
-
"test:unit": "mocha --config test/mocharc.json",
|
|
34
|
+
"test:unit": "mocha --config test/unit/mocharc.json",
|
|
35
35
|
"test:coverage": "stryker run .stryker.config.js",
|
|
36
|
-
"jsdocs": "typedoc --tsconfig .tsconfig_jsdocs.json
|
|
36
|
+
"jsdocs": "typedoc --tsconfig .tsconfig_jsdocs.json",
|
|
37
37
|
"prepare": "tsc --project .tsconfig_types.json",
|
|
38
38
|
"release": "standard-version",
|
|
39
39
|
"clean": "node .script/clean.js"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"chalk": "5.2.0",
|
|
43
|
-
"yargs": "17.7.
|
|
43
|
+
"yargs": "17.7.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@coffeelint/cli": "5.2.11",
|
|
47
|
+
"@prantlf/jsonlint": "14.0.3",
|
|
47
48
|
"@prettier/plugin-xml": "2.2.0",
|
|
48
|
-
"@stryker-mutator/core": "6.4.
|
|
49
|
-
"@stryker-mutator/mocha-runner": "6.4.
|
|
50
|
-
"@types/
|
|
51
|
-
"@types/eslint": "8.21.1",
|
|
52
|
-
"@types/file-entry-cache": "5.0.2",
|
|
49
|
+
"@stryker-mutator/core": "6.4.2",
|
|
50
|
+
"@stryker-mutator/mocha-runner": "6.4.2",
|
|
51
|
+
"@types/eslint": "8.37.0",
|
|
53
52
|
"@types/htmlhint": "1.1.2",
|
|
54
|
-
"@types/js-yaml": "4.0.5",
|
|
55
|
-
"@types/jshint": "2.12.1",
|
|
56
53
|
"@types/mocha": "10.0.1",
|
|
57
54
|
"@types/mock-fs": "4.13.1",
|
|
58
|
-
"@types/
|
|
59
|
-
"@types/sinon": "10.0.
|
|
60
|
-
"@types/yargs": "17.0.
|
|
61
|
-
"addons-linter": "
|
|
55
|
+
"@types/prettier": "2.7.2",
|
|
56
|
+
"@types/sinon": "10.0.14",
|
|
57
|
+
"@types/yargs": "17.0.24",
|
|
58
|
+
"addons-linter": "6.2.0",
|
|
62
59
|
"csslint": "1.0.5",
|
|
63
60
|
"doiuse": "4.4.1",
|
|
64
|
-
"eslint": "8.
|
|
61
|
+
"eslint": "8.39.0",
|
|
65
62
|
"eslint-plugin-array-func": "3.1.8",
|
|
66
63
|
"eslint-plugin-eslint-comments": "3.2.0",
|
|
67
64
|
"eslint-plugin-import": "2.27.5",
|
|
68
|
-
"eslint-plugin-jsdoc": "
|
|
65
|
+
"eslint-plugin-jsdoc": "43.1.1",
|
|
69
66
|
"eslint-plugin-mocha": "10.1.0",
|
|
70
|
-
"eslint-plugin-n": "15.
|
|
67
|
+
"eslint-plugin-n": "15.7.0",
|
|
71
68
|
"eslint-plugin-no-unsanitized": "4.0.2",
|
|
72
69
|
"eslint-plugin-promise": "6.1.1",
|
|
73
|
-
"eslint-plugin-regexp": "1.
|
|
70
|
+
"eslint-plugin-regexp": "1.14.0",
|
|
74
71
|
"eslint-plugin-unicorn": "46.0.0",
|
|
75
|
-
"flow-bin": "0.201.0",
|
|
76
72
|
"htmlhint": "1.1.4",
|
|
77
73
|
"htmllint": "0.8.0",
|
|
78
74
|
"jshint": "2.13.6",
|
|
79
|
-
"json-lint": "0.1.0",
|
|
80
|
-
"jsonlint": "1.6.3",
|
|
81
75
|
"jsonlint-mod": "1.7.6",
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"markuplint": "3.3.0",
|
|
76
|
+
"markdownlint": "0.28.2",
|
|
77
|
+
"markuplint": "3.9.0",
|
|
85
78
|
"mocha": "10.2.0",
|
|
86
79
|
"mock-fs": "5.2.0",
|
|
87
80
|
"npm-package-json-lint": "6.4.0",
|
|
88
|
-
"prettier": "2.8.
|
|
81
|
+
"prettier": "2.8.8",
|
|
89
82
|
"purgecss": "5.0.0",
|
|
90
|
-
"sinon": "15.0.
|
|
83
|
+
"sinon": "15.0.4",
|
|
91
84
|
"standard": "17.0.0",
|
|
92
85
|
"standard-version": "9.5.0",
|
|
93
|
-
"stylelint": "15.
|
|
94
|
-
"typedoc": "0.
|
|
95
|
-
"typescript": "
|
|
86
|
+
"stylelint": "15.6.0",
|
|
87
|
+
"typedoc": "0.24.6",
|
|
88
|
+
"typescript": "5.0.4",
|
|
96
89
|
"yaml-lint": "1.7.0"
|
|
97
90
|
},
|
|
98
91
|
"engines": {
|
package/src/bin/argv.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Sébastien Règne
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
import yargs from "yargs";
|
|
9
|
+
import {
|
|
10
|
+
normalizeFormatter,
|
|
11
|
+
normalizeLevel,
|
|
12
|
+
} from "../core/configuration/normalize.js";
|
|
13
|
+
import { FORMATTERS } from "../core/formatter/formatter.js";
|
|
14
|
+
import Levels from "../core/levels.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {import("../core/formatter/formatter.js").default} TypeofFormatter
|
|
18
|
+
* @typedef {import("../type/index.d.ts").Level} Level
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {Object} Argv
|
|
23
|
+
* @property {string[]} _ Le paramètres de la ligne de
|
|
24
|
+
* commande.
|
|
25
|
+
* @property {string} config L'option
|
|
26
|
+
* <code>--config</code> de la
|
|
27
|
+
* ligne de commande.
|
|
28
|
+
* @property {boolean|undefined} fix L'option <code>--fix</code>
|
|
29
|
+
* de la ligne de commande.
|
|
30
|
+
* @property {TypeofFormatter|undefined} formatter L'option
|
|
31
|
+
* <code>--formatter</code> de
|
|
32
|
+
* la ligne de commande.
|
|
33
|
+
* @property {Level} level L'option <code>--level</code>
|
|
34
|
+
* de la ligne de commande.
|
|
35
|
+
* @property {boolean} help L'option <code>--help</code>
|
|
36
|
+
* de la ligne de commande.
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Extrait, vérifie et normalise les paramètres et les options de la ligne de
|
|
40
|
+
* commande.
|
|
41
|
+
*
|
|
42
|
+
* @param {string[]} argv Les paramètres et les options de la ligne de commande.
|
|
43
|
+
* @returns {Promise<Argv>} Les paramètres et les options normalisés.
|
|
44
|
+
*/
|
|
45
|
+
export const parse = async function (argv = process.argv.slice(2)) {
|
|
46
|
+
const args = yargs(argv)
|
|
47
|
+
.options({
|
|
48
|
+
c: {
|
|
49
|
+
alias: "config",
|
|
50
|
+
default: ".metalint/metalint.config.js",
|
|
51
|
+
requiresArg: true,
|
|
52
|
+
type: "string",
|
|
53
|
+
},
|
|
54
|
+
f: {
|
|
55
|
+
alias: "formatter",
|
|
56
|
+
choices: FORMATTERS,
|
|
57
|
+
requiresArg: true,
|
|
58
|
+
type: "string",
|
|
59
|
+
},
|
|
60
|
+
fix: {
|
|
61
|
+
alias: "fix",
|
|
62
|
+
type: "boolean",
|
|
63
|
+
},
|
|
64
|
+
l: {
|
|
65
|
+
alias: "level",
|
|
66
|
+
choices: Object.keys(Levels).map((l) => l.toLowerCase()),
|
|
67
|
+
default: "info",
|
|
68
|
+
requiresArg: true,
|
|
69
|
+
type: "string",
|
|
70
|
+
},
|
|
71
|
+
help: {
|
|
72
|
+
alias: "help",
|
|
73
|
+
type: "boolean",
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
.help(false)
|
|
77
|
+
.parse();
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
// Ajouter une barre oblique à la fin pour les répertoires.
|
|
81
|
+
_:
|
|
82
|
+
0 === args._.length
|
|
83
|
+
? ["./"]
|
|
84
|
+
: await Promise.all(
|
|
85
|
+
args._.map(async (base) => {
|
|
86
|
+
const stats = await fs.lstat(base);
|
|
87
|
+
return base + (stats.isDirectory() ? "/" : "");
|
|
88
|
+
}),
|
|
89
|
+
),
|
|
90
|
+
config: args.config,
|
|
91
|
+
fix: args.fix,
|
|
92
|
+
// Ne pas utiliser yargs.coerce() pour convertir les données car cette
|
|
93
|
+
// méthode est incompatible avec yargs.choices().
|
|
94
|
+
// https://github.com/yargs/yargs/issues/1379
|
|
95
|
+
formatter:
|
|
96
|
+
undefined === args.formatter
|
|
97
|
+
? undefined
|
|
98
|
+
: await normalizeFormatter(args.formatter),
|
|
99
|
+
level: normalizeLevel(args.level),
|
|
100
|
+
help: args.help ?? false,
|
|
101
|
+
};
|
|
102
|
+
};
|
package/src/bin/help.txt
CHANGED
|
@@ -7,14 +7,10 @@ options courtes.
|
|
|
7
7
|
-f, --formatter=FORMATTER définir le formateur utilisé pour afficher les
|
|
8
8
|
résultats
|
|
9
9
|
--fix corriger les fichiers
|
|
10
|
-
-l, --level=
|
|
11
|
-
-o, --output=OUTPUT spécifier le fichier de sortie où seront écrit les
|
|
12
|
-
résultats
|
|
13
|
-
-p, --patterns=PATRONS spécifier les patrons pour filtrer les fichiers qui
|
|
14
|
-
seront analysés
|
|
10
|
+
-l, --level=LEVEL définir le niveau de sévérité global
|
|
15
11
|
--help afficher l'aide et quitter
|
|
16
12
|
--version afficher des informations de version et quitter
|
|
17
13
|
|
|
18
|
-
L'argument
|
|
14
|
+
L'argument LEVEL peut avoir comme valeur : off, fatal, error, warn ou info.
|
|
19
15
|
|
|
20
|
-
Documentation complète à : <https://
|
|
16
|
+
Documentation complète à : <https://github.com/regseb/metalint>
|
package/src/bin/index.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import fs from "node:fs";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import flatten from "../core/configuration/flatten.js";
|
|
7
|
+
import normalize from "../core/configuration/normalize.js";
|
|
8
8
|
import metalint from "../core/index.js";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
9
|
+
import Severities from "../core/severities.js";
|
|
10
|
+
import { exists } from "../core/utils/file.js";
|
|
11
|
+
import Glob from "../core/utils/glob.js";
|
|
12
|
+
import { parse } from "./argv.js";
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
|
-
* @typedef {import("../
|
|
14
|
-
* @typedef {import("../
|
|
15
|
+
* @typedef {import("../core/formatter/formatter.js")} Formatter
|
|
16
|
+
* @typedef {import("../type/index.d.ts").FlattenedConfigChecker} FlattenedConfigChecker
|
|
17
|
+
* @typedef {import("../type/index.d.ts").FlattenedConfigReporter} FlattenedConfigReporter
|
|
18
|
+
* @typedef {import("../type/index.d.ts").Severity} Severity
|
|
15
19
|
*/
|
|
16
20
|
|
|
17
21
|
if (undefined === import.meta.resolve) {
|
|
@@ -20,72 +24,36 @@ if (undefined === import.meta.resolve) {
|
|
|
20
24
|
*
|
|
21
25
|
* @param {string} specifier Le chemin relatif vers un fichier ou un
|
|
22
26
|
* répertoire.
|
|
23
|
-
* @returns {
|
|
24
|
-
* le fichier ou le répertoire.
|
|
27
|
+
* @returns {string} L'URL absolue vers le fichier ou le répertoire.
|
|
25
28
|
* @see https://nodejs.org/api/esm.html#importmetaresolvespecifier-parent
|
|
26
29
|
*/
|
|
27
30
|
import.meta.resolve = (specifier) => {
|
|
28
|
-
return
|
|
29
|
-
fileURLToPath(new URL(specifier, import.meta.url).href),
|
|
30
|
-
);
|
|
31
|
+
return new URL(specifier, import.meta.url).href;
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
const argv = yargs(process.argv.slice(2))
|
|
35
|
-
.options({
|
|
36
|
-
c: {
|
|
37
|
-
alias: "config",
|
|
38
|
-
default: ".metalint/metalint.config.js",
|
|
39
|
-
requiresArg: true,
|
|
40
|
-
type: "string",
|
|
41
|
-
},
|
|
42
|
-
f: {
|
|
43
|
-
alias: "formatter",
|
|
44
|
-
requiresArg: true,
|
|
45
|
-
type: "string",
|
|
46
|
-
},
|
|
47
|
-
fix: {
|
|
48
|
-
alias: "fix",
|
|
49
|
-
type: "boolean",
|
|
50
|
-
},
|
|
51
|
-
l: {
|
|
52
|
-
alias: "level",
|
|
53
|
-
requiresArg: true,
|
|
54
|
-
type: "string",
|
|
55
|
-
},
|
|
56
|
-
o: {
|
|
57
|
-
alias: "output",
|
|
58
|
-
requiresArg: true,
|
|
59
|
-
type: "string",
|
|
60
|
-
},
|
|
61
|
-
p: {
|
|
62
|
-
alias: "patterns",
|
|
63
|
-
requiresArg: true,
|
|
64
|
-
type: "array",
|
|
65
|
-
},
|
|
66
|
-
help: {
|
|
67
|
-
alias: "help",
|
|
68
|
-
type: "boolean",
|
|
69
|
-
},
|
|
70
|
-
})
|
|
71
|
-
.help(false).argv;
|
|
72
|
-
|
|
73
35
|
/**
|
|
74
36
|
* Vérifie (en appelant des linters) une liste de fichiers.
|
|
75
37
|
*
|
|
76
|
-
* @param {string[]}
|
|
77
|
-
* @param {
|
|
78
|
-
*
|
|
79
|
-
* @param {string}
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
38
|
+
* @param {string[]} files La liste des fichiers.
|
|
39
|
+
* @param {FlattenedConfigChecker[]} checkers La liste des vérifications
|
|
40
|
+
* faites sur les fichiers.
|
|
41
|
+
* @param {string} root L'adresse du répertoire où se
|
|
42
|
+
* trouve le répertoire
|
|
43
|
+
* <code>.metalint/</code>.
|
|
44
|
+
* @param {FlattenedConfigReporter[]} reporters La liste des rapporteurs
|
|
45
|
+
* utilisés pour afficher les
|
|
46
|
+
* résultats.
|
|
47
|
+
* @returns {Promise<Severity|undefined>} La sévérité la plus élévée des
|
|
48
|
+
* résultats.
|
|
85
49
|
*/
|
|
86
50
|
const check = async function (files, checkers, root, reporters) {
|
|
87
51
|
let severity;
|
|
88
52
|
|
|
53
|
+
const formatters = reporters.map((reporter) => {
|
|
54
|
+
// eslint-disable-next-line new-cap
|
|
55
|
+
return new reporter.formatter(reporter.level, reporter.options);
|
|
56
|
+
});
|
|
89
57
|
const results = await metalint(files, checkers, root);
|
|
90
58
|
for (const [file, notices] of Object.entries(results)) {
|
|
91
59
|
// Déterminer la sévérité la plus élévée des résultats.
|
|
@@ -98,19 +66,20 @@ const check = async function (files, checkers, root, reporters) {
|
|
|
98
66
|
}
|
|
99
67
|
|
|
100
68
|
// Afficher les notifications avec chaque rapporteur.
|
|
101
|
-
for (const
|
|
102
|
-
await
|
|
69
|
+
for (const formatter of formatters) {
|
|
70
|
+
await formatter.notify(file, notices);
|
|
103
71
|
}
|
|
104
72
|
}
|
|
105
73
|
|
|
106
74
|
// Attendre tous les rapporteurs.
|
|
107
|
-
await Promise.all(
|
|
75
|
+
await Promise.all(formatters.map((f) => f.finalize()));
|
|
108
76
|
return severity;
|
|
109
77
|
};
|
|
110
78
|
|
|
79
|
+
const argv = await parse();
|
|
111
80
|
if (argv.help) {
|
|
112
81
|
process.stdout.write(
|
|
113
|
-
fs.
|
|
82
|
+
await fs.readFile(fileURLToPath(import.meta.resolve("./help.txt"))),
|
|
114
83
|
);
|
|
115
84
|
process.exit(0);
|
|
116
85
|
}
|
|
@@ -118,7 +87,7 @@ if (argv.help) {
|
|
|
118
87
|
let root = process.cwd();
|
|
119
88
|
// Rechercher le fichier de configuration dans le répertoire courant, puis dans
|
|
120
89
|
// les parents, grands-parents...
|
|
121
|
-
while (!
|
|
90
|
+
while (!(await exists(path.join(root, argv.config)))) {
|
|
122
91
|
// Si on est remonté à la racine.
|
|
123
92
|
if (path.join(root, "..") === root) {
|
|
124
93
|
process.stderr.write("metalint: no such config file.\n");
|
|
@@ -129,24 +98,29 @@ while (!fs.existsSync(path.join(root, argv.config))) {
|
|
|
129
98
|
|
|
130
99
|
try {
|
|
131
100
|
// eslint-disable-next-line no-unsanitized/method
|
|
132
|
-
const { default: config } = await import(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
101
|
+
const { default: config } = await import(
|
|
102
|
+
pathToFileURL(path.join(root, argv.config))
|
|
103
|
+
);
|
|
104
|
+
const { patterns, reporters, checkers } = flatten(
|
|
105
|
+
await normalize(config, {
|
|
106
|
+
dir: path.dirname(path.join(root, argv.config)),
|
|
107
|
+
}),
|
|
137
108
|
argv,
|
|
138
109
|
);
|
|
139
110
|
|
|
140
|
-
const
|
|
141
|
-
const files =
|
|
111
|
+
const glob = new Glob(patterns, { root });
|
|
112
|
+
const files = [];
|
|
113
|
+
for (const base of argv._) {
|
|
114
|
+
files.push(...(await glob.walk(base)));
|
|
115
|
+
}
|
|
142
116
|
|
|
143
117
|
const severity = await check(files, checkers, root, reporters);
|
|
144
118
|
let code;
|
|
145
119
|
switch (severity) {
|
|
146
|
-
case
|
|
120
|
+
case Severities.FATAL:
|
|
147
121
|
code = 2;
|
|
148
122
|
break;
|
|
149
|
-
case
|
|
123
|
+
case Severities.ERROR:
|
|
150
124
|
code = 1;
|
|
151
125
|
break;
|
|
152
126
|
default:
|