metalint 0.11.1 → 0.13.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 +135 -37
- package/package.json +38 -43
- package/src/bin/argv.js +103 -0
- package/src/bin/help.txt +3 -7
- package/src/bin/index.js +54 -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 +50 -54
- package/src/core/formatter/console.js +62 -53
- package/src/core/formatter/csv.js +26 -25
- package/src/core/formatter/formatter.js +101 -0
- package/src/core/formatter/github.js +37 -42
- package/src/core/formatter/json.js +27 -23
- package/src/core/formatter/unix.js +26 -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 +258 -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 +74 -42
- 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-check-updates.js +87 -0
- 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 +92 -49
- package/src/core/wrapper/purgecss.js +74 -44
- package/src/core/wrapper/sort-package-json.js +95 -0
- package/src/core/wrapper/standard.js +72 -50
- package/src/core/wrapper/stylelint.js +78 -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/severities.d.ts +7 -0
- 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-check-updates.d.ts +36 -0
- 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/sort-package-json.d.ts +36 -0
- 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/severity.d.ts +0 -8
- 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,144 @@
|
|
|
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-check-updates"
|
|
104
|
+
href="https://www.npmjs.com/package/npm-check-updates"
|
|
105
|
+
>npm-check-updates</a>,
|
|
106
|
+
<a title="npm-package-json-lint"
|
|
107
|
+
href="https://www.npmjs.com/package/npm-package-json-lint"
|
|
108
|
+
>npm-package-json-lint</a>,
|
|
109
|
+
<a title="sort-package-json"
|
|
110
|
+
href="https://www.npmjs.com/package/sort-package-json"
|
|
111
|
+
>Sort Package.json</a>
|
|
112
|
+
</td>
|
|
113
|
+
</tr>
|
|
114
|
+
<tr>
|
|
115
|
+
<td>SCSS</td>
|
|
116
|
+
<td>
|
|
117
|
+
<a title="prettier"
|
|
118
|
+
href="https://www.npmjs.com/package/prettier">Prettier</a>,
|
|
119
|
+
<a title="stylelint"
|
|
120
|
+
href="https://www.npmjs.com/package/stylelint">Stylelint</a>
|
|
121
|
+
</td>
|
|
122
|
+
</tr>
|
|
123
|
+
<tr>
|
|
124
|
+
<td>SugarSS</td>
|
|
125
|
+
<td>
|
|
126
|
+
<a title="stylelint"
|
|
127
|
+
href="https://www.npmjs.com/package/stylelint">Stylelint</a>
|
|
128
|
+
</td>
|
|
129
|
+
</tr>
|
|
130
|
+
<tr>
|
|
131
|
+
<td>WebExtension</td>
|
|
132
|
+
<td>
|
|
133
|
+
<a title="addons-linter"
|
|
134
|
+
href="https://www.npmjs.com/package/addons-linter">Add-ons Linter</a>
|
|
135
|
+
</td>
|
|
136
|
+
</tr>
|
|
137
|
+
<tr>
|
|
138
|
+
<td>YAML</td>
|
|
139
|
+
<td>
|
|
140
|
+
<a title="yaml-lint"
|
|
141
|
+
href="https://www.npmjs.com/package/yaml-lint">YAML Lint</a>,
|
|
142
|
+
<a title="prettier"
|
|
143
|
+
href="https://www.npmjs.com/package/prettier">Prettier</a>
|
|
144
|
+
</td>
|
|
145
|
+
</tr>
|
|
146
|
+
</table>
|
|
147
|
+
<!-- markdownlint-enable no-inline-html -->
|
|
50
148
|
|
|
51
149
|
## Installation
|
|
52
150
|
|
|
53
151
|
Vous pouvez installer Metalint en utilisant [npm][link-npm] :
|
|
54
152
|
|
|
55
153
|
```Shell
|
|
56
|
-
npm install
|
|
154
|
+
npm install --save-dev --save-exact metalint
|
|
57
155
|
```
|
|
58
156
|
|
|
59
157
|
## Configuration
|
|
@@ -68,15 +166,15 @@ linters.
|
|
|
68
166
|
|
|
69
167
|
Dans cet exemple des fichiers de configuration, Metalint analyse les fichiers
|
|
70
168
|
JavaScript (non-minifiés), HTML et CSS ; avec respectivement les linters ESLint,
|
|
71
|
-
HTMLHint et
|
|
169
|
+
HTMLHint et Stylelint.
|
|
72
170
|
|
|
73
171
|
```JavaScript
|
|
74
172
|
// .metalint/metalint.config.js
|
|
75
173
|
export default {
|
|
76
|
-
patterns: ["!/.git
|
|
174
|
+
patterns: ["**", "!/.git/**", "!/node_modules/**"],
|
|
77
175
|
checkers: [
|
|
78
176
|
{
|
|
79
|
-
patterns: ["
|
|
177
|
+
patterns: ["*.js", "!*.min.js"],
|
|
80
178
|
linters: "eslint",
|
|
81
179
|
}, {
|
|
82
180
|
patterns: "*.html",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metalint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Un linter pour les gouverner tous.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"checker",
|
|
@@ -18,81 +18,76 @@
|
|
|
18
18
|
"author": "Sébastien Règne <regseb@gmail.com> (https://github.com/regseb)",
|
|
19
19
|
"funding": "https://www.paypal.me/sebastienregne",
|
|
20
20
|
"files": [
|
|
21
|
-
"src/",
|
|
22
|
-
"types/"
|
|
21
|
+
"./src/",
|
|
22
|
+
"./types/"
|
|
23
23
|
],
|
|
24
|
-
"main": "src/core/index.js",
|
|
25
|
-
"types": "types/index.d.ts",
|
|
26
|
-
"bin": "src/bin/index.js",
|
|
24
|
+
"main": "./src/core/index.js",
|
|
25
|
+
"types": "./types/index.d.ts",
|
|
26
|
+
"bin": "./src/bin/index.js",
|
|
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
|
-
"chalk": "5.
|
|
43
|
-
"yargs": "17.7.
|
|
42
|
+
"chalk": "5.3.0",
|
|
43
|
+
"yargs": "17.7.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@coffeelint/cli": "5.2.11",
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"@stryker-mutator/
|
|
50
|
-
"@
|
|
51
|
-
"@types/eslint": "8.
|
|
52
|
-
"@types/file-entry-cache": "5.0.2",
|
|
47
|
+
"@prantlf/jsonlint": "14.0.3",
|
|
48
|
+
"@prettier/plugin-xml": "3.1.1",
|
|
49
|
+
"@stryker-mutator/core": "7.1.1",
|
|
50
|
+
"@stryker-mutator/mocha-runner": "7.1.1",
|
|
51
|
+
"@types/eslint": "8.44.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.3",
|
|
56
|
+
"@types/sinon": "10.0.15",
|
|
57
|
+
"@types/yargs": "17.0.24",
|
|
58
|
+
"addons-linter": "6.10.0",
|
|
62
59
|
"csslint": "1.0.5",
|
|
63
|
-
"doiuse": "
|
|
64
|
-
"eslint": "8.
|
|
60
|
+
"doiuse": "6.0.2",
|
|
61
|
+
"eslint": "8.45.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": "46.4.4",
|
|
69
66
|
"eslint-plugin-mocha": "10.1.0",
|
|
70
|
-
"eslint-plugin-n": "
|
|
67
|
+
"eslint-plugin-n": "16.0.1",
|
|
71
68
|
"eslint-plugin-no-unsanitized": "4.0.2",
|
|
72
69
|
"eslint-plugin-promise": "6.1.1",
|
|
73
|
-
"eslint-plugin-regexp": "1.
|
|
74
|
-
"eslint-plugin-unicorn": "
|
|
75
|
-
"flow-bin": "0.201.0",
|
|
70
|
+
"eslint-plugin-regexp": "1.15.0",
|
|
71
|
+
"eslint-plugin-unicorn": "48.0.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.29.0",
|
|
77
|
+
"markuplint": "3.12.0",
|
|
85
78
|
"mocha": "10.2.0",
|
|
86
79
|
"mock-fs": "5.2.0",
|
|
87
|
-
"npm-
|
|
88
|
-
"
|
|
80
|
+
"npm-check-updates": "16.10.16",
|
|
81
|
+
"npm-package-json-lint": "7.0.0",
|
|
82
|
+
"prettier": "3.0.0",
|
|
89
83
|
"purgecss": "5.0.0",
|
|
90
|
-
"sinon": "15.0
|
|
91
|
-
"
|
|
84
|
+
"sinon": "15.2.0",
|
|
85
|
+
"sort-package-json": "2.5.1",
|
|
86
|
+
"standard": "17.1.0",
|
|
92
87
|
"standard-version": "9.5.0",
|
|
93
|
-
"stylelint": "15.2
|
|
94
|
-
"typedoc": "0.
|
|
95
|
-
"typescript": "
|
|
88
|
+
"stylelint": "15.10.2",
|
|
89
|
+
"typedoc": "0.24.8",
|
|
90
|
+
"typescript": "5.1.6",
|
|
96
91
|
"yaml-lint": "1.7.0"
|
|
97
92
|
},
|
|
98
93
|
"engines": {
|
package/src/bin/argv.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Sébastien Règne
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
import process from "node:process";
|
|
9
|
+
import yargs from "yargs";
|
|
10
|
+
import {
|
|
11
|
+
normalizeFormatter,
|
|
12
|
+
normalizeLevel,
|
|
13
|
+
} from "../core/configuration/normalize.js";
|
|
14
|
+
import { FORMATTERS } from "../core/formatter/formatter.js";
|
|
15
|
+
import Levels from "../core/levels.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {import("../core/formatter/formatter.js").default} TypeofFormatter
|
|
19
|
+
* @typedef {import("../type/index.d.ts").Level} Level
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {Object} Argv
|
|
24
|
+
* @property {string[]} _ Le paramètres de la ligne de
|
|
25
|
+
* commande.
|
|
26
|
+
* @property {string} config L'option
|
|
27
|
+
* <code>--config</code> de la
|
|
28
|
+
* ligne de commande.
|
|
29
|
+
* @property {boolean|undefined} fix L'option <code>--fix</code>
|
|
30
|
+
* de la ligne de commande.
|
|
31
|
+
* @property {TypeofFormatter|undefined} formatter L'option
|
|
32
|
+
* <code>--formatter</code> de
|
|
33
|
+
* la ligne de commande.
|
|
34
|
+
* @property {Level} level L'option <code>--level</code>
|
|
35
|
+
* de la ligne de commande.
|
|
36
|
+
* @property {boolean} help L'option <code>--help</code>
|
|
37
|
+
* de la ligne de commande.
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Extrait, vérifie et normalise les paramètres et les options de la ligne de
|
|
41
|
+
* commande.
|
|
42
|
+
*
|
|
43
|
+
* @param {string[]} argv Les paramètres et les options de la ligne de commande.
|
|
44
|
+
* @returns {Promise<Argv>} Les paramètres et les options normalisés.
|
|
45
|
+
*/
|
|
46
|
+
export const parse = async function (argv = process.argv.slice(2)) {
|
|
47
|
+
const args = yargs(argv)
|
|
48
|
+
.options({
|
|
49
|
+
c: {
|
|
50
|
+
alias: "config",
|
|
51
|
+
default: ".metalint/metalint.config.js",
|
|
52
|
+
requiresArg: true,
|
|
53
|
+
type: "string",
|
|
54
|
+
},
|
|
55
|
+
f: {
|
|
56
|
+
alias: "formatter",
|
|
57
|
+
choices: FORMATTERS,
|
|
58
|
+
requiresArg: true,
|
|
59
|
+
type: "string",
|
|
60
|
+
},
|
|
61
|
+
fix: {
|
|
62
|
+
alias: "fix",
|
|
63
|
+
type: "boolean",
|
|
64
|
+
},
|
|
65
|
+
l: {
|
|
66
|
+
alias: "level",
|
|
67
|
+
choices: Object.keys(Levels).map((l) => l.toLowerCase()),
|
|
68
|
+
default: "info",
|
|
69
|
+
requiresArg: true,
|
|
70
|
+
type: "string",
|
|
71
|
+
},
|
|
72
|
+
help: {
|
|
73
|
+
alias: "help",
|
|
74
|
+
type: "boolean",
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
.help(false)
|
|
78
|
+
.parse();
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
// Ajouter une barre oblique à la fin pour les répertoires.
|
|
82
|
+
_:
|
|
83
|
+
0 === args._.length
|
|
84
|
+
? ["./"]
|
|
85
|
+
: await Promise.all(
|
|
86
|
+
args._.map(async (base) => {
|
|
87
|
+
const stats = await fs.lstat(base);
|
|
88
|
+
return base + (stats.isDirectory() ? "/" : "");
|
|
89
|
+
}),
|
|
90
|
+
),
|
|
91
|
+
config: args.config,
|
|
92
|
+
fix: args.fix,
|
|
93
|
+
// Ne pas utiliser yargs.coerce() pour convertir les données car cette
|
|
94
|
+
// méthode est incompatible avec yargs.choices().
|
|
95
|
+
// https://github.com/yargs/yargs/issues/1379
|
|
96
|
+
formatter:
|
|
97
|
+
undefined === args.formatter
|
|
98
|
+
? undefined
|
|
99
|
+
: await normalizeFormatter(args.formatter),
|
|
100
|
+
level: normalizeLevel(args.level),
|
|
101
|
+
help: args.help ?? false,
|
|
102
|
+
};
|
|
103
|
+
};
|
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,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// Désactiver cette règle car elle ne supporte pas les valeurs de la propriété
|
|
4
|
+
// "files" (du package.json) commençant par "./".
|
|
5
|
+
// https://github.com/eslint-community/eslint-plugin-n/issues/99
|
|
6
|
+
// eslint-disable-next-line n/no-unpublished-bin
|
|
7
|
+
import fs from "node:fs/promises";
|
|
4
8
|
import path from "node:path";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
9
|
+
import process from "node:process";
|
|
10
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
|
+
import flatten from "../core/configuration/flatten.js";
|
|
12
|
+
import normalize from "../core/configuration/normalize.js";
|
|
8
13
|
import metalint from "../core/index.js";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
14
|
+
import Severities from "../core/severities.js";
|
|
15
|
+
import { exists } from "../core/utils/file.js";
|
|
16
|
+
import Glob from "../core/utils/glob.js";
|
|
17
|
+
import { parse } from "./argv.js";
|
|
11
18
|
|
|
12
19
|
/**
|
|
13
|
-
* @typedef {import("../
|
|
14
|
-
* @typedef {import("../
|
|
20
|
+
* @typedef {import("../core/formatter/formatter.js")} Formatter
|
|
21
|
+
* @typedef {import("../type/index.d.ts").FlattenedConfigChecker} FlattenedConfigChecker
|
|
22
|
+
* @typedef {import("../type/index.d.ts").FlattenedConfigReporter} FlattenedConfigReporter
|
|
23
|
+
* @typedef {import("../type/index.d.ts").Severity} Severity
|
|
15
24
|
*/
|
|
16
25
|
|
|
17
26
|
if (undefined === import.meta.resolve) {
|
|
@@ -20,72 +29,36 @@ if (undefined === import.meta.resolve) {
|
|
|
20
29
|
*
|
|
21
30
|
* @param {string} specifier Le chemin relatif vers un fichier ou un
|
|
22
31
|
* répertoire.
|
|
23
|
-
* @returns {
|
|
24
|
-
* le fichier ou le répertoire.
|
|
32
|
+
* @returns {string} L'URL absolue vers le fichier ou le répertoire.
|
|
25
33
|
* @see https://nodejs.org/api/esm.html#importmetaresolvespecifier-parent
|
|
26
34
|
*/
|
|
27
35
|
import.meta.resolve = (specifier) => {
|
|
28
|
-
return
|
|
29
|
-
fileURLToPath(new URL(specifier, import.meta.url).href),
|
|
30
|
-
);
|
|
36
|
+
return new URL(specifier, import.meta.url).href;
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
39
|
|
|
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
40
|
/**
|
|
74
41
|
* Vérifie (en appelant des linters) une liste de fichiers.
|
|
75
42
|
*
|
|
76
|
-
* @param {string[]}
|
|
77
|
-
* @param {
|
|
78
|
-
*
|
|
79
|
-
* @param {string}
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
43
|
+
* @param {string[]} files La liste des fichiers.
|
|
44
|
+
* @param {FlattenedConfigChecker[]} checkers La liste des vérifications
|
|
45
|
+
* faites sur les fichiers.
|
|
46
|
+
* @param {string} root L'adresse du répertoire où se
|
|
47
|
+
* trouve le répertoire
|
|
48
|
+
* <code>.metalint/</code>.
|
|
49
|
+
* @param {FlattenedConfigReporter[]} reporters La liste des rapporteurs
|
|
50
|
+
* utilisés pour afficher les
|
|
51
|
+
* résultats.
|
|
52
|
+
* @returns {Promise<Severity|undefined>} La sévérité la plus élévée des
|
|
53
|
+
* résultats.
|
|
85
54
|
*/
|
|
86
55
|
const check = async function (files, checkers, root, reporters) {
|
|
87
56
|
let severity;
|
|
88
57
|
|
|
58
|
+
const formatters = reporters.map((reporter) => {
|
|
59
|
+
// eslint-disable-next-line new-cap
|
|
60
|
+
return new reporter.formatter(reporter.level, reporter.options);
|
|
61
|
+
});
|
|
89
62
|
const results = await metalint(files, checkers, root);
|
|
90
63
|
for (const [file, notices] of Object.entries(results)) {
|
|
91
64
|
// Déterminer la sévérité la plus élévée des résultats.
|
|
@@ -98,19 +71,20 @@ const check = async function (files, checkers, root, reporters) {
|
|
|
98
71
|
}
|
|
99
72
|
|
|
100
73
|
// Afficher les notifications avec chaque rapporteur.
|
|
101
|
-
for (const
|
|
102
|
-
await
|
|
74
|
+
for (const formatter of formatters) {
|
|
75
|
+
await formatter.notify(file, notices);
|
|
103
76
|
}
|
|
104
77
|
}
|
|
105
78
|
|
|
106
79
|
// Attendre tous les rapporteurs.
|
|
107
|
-
await Promise.all(
|
|
80
|
+
await Promise.all(formatters.map((f) => f.finalize()));
|
|
108
81
|
return severity;
|
|
109
82
|
};
|
|
110
83
|
|
|
84
|
+
const argv = await parse();
|
|
111
85
|
if (argv.help) {
|
|
112
86
|
process.stdout.write(
|
|
113
|
-
fs.
|
|
87
|
+
await fs.readFile(fileURLToPath(import.meta.resolve("./help.txt"))),
|
|
114
88
|
);
|
|
115
89
|
process.exit(0);
|
|
116
90
|
}
|
|
@@ -118,7 +92,7 @@ if (argv.help) {
|
|
|
118
92
|
let root = process.cwd();
|
|
119
93
|
// Rechercher le fichier de configuration dans le répertoire courant, puis dans
|
|
120
94
|
// les parents, grands-parents...
|
|
121
|
-
while (!
|
|
95
|
+
while (!(await exists(path.join(root, argv.config)))) {
|
|
122
96
|
// Si on est remonté à la racine.
|
|
123
97
|
if (path.join(root, "..") === root) {
|
|
124
98
|
process.stderr.write("metalint: no such config file.\n");
|
|
@@ -129,24 +103,29 @@ while (!fs.existsSync(path.join(root, argv.config))) {
|
|
|
129
103
|
|
|
130
104
|
try {
|
|
131
105
|
// eslint-disable-next-line no-unsanitized/method
|
|
132
|
-
const { default: config } = await import(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
106
|
+
const { default: config } = await import(
|
|
107
|
+
pathToFileURL(path.join(root, argv.config))
|
|
108
|
+
);
|
|
109
|
+
const { patterns, reporters, checkers } = flatten(
|
|
110
|
+
await normalize(config, {
|
|
111
|
+
dir: path.dirname(path.join(root, argv.config)),
|
|
112
|
+
}),
|
|
137
113
|
argv,
|
|
138
114
|
);
|
|
139
115
|
|
|
140
|
-
const
|
|
141
|
-
const files =
|
|
116
|
+
const glob = new Glob(patterns, { root });
|
|
117
|
+
const files = [];
|
|
118
|
+
for (const base of argv._) {
|
|
119
|
+
files.push(...(await glob.walk(base)));
|
|
120
|
+
}
|
|
142
121
|
|
|
143
122
|
const severity = await check(files, checkers, root, reporters);
|
|
144
123
|
let code;
|
|
145
124
|
switch (severity) {
|
|
146
|
-
case
|
|
125
|
+
case Severities.FATAL:
|
|
147
126
|
code = 2;
|
|
148
127
|
break;
|
|
149
|
-
case
|
|
128
|
+
case Severities.ERROR:
|
|
150
129
|
code = 1;
|
|
151
130
|
break;
|
|
152
131
|
default:
|