metalint 0.10.0 → 0.11.1
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/LICENSE +1 -1
- package/README.md +70 -23
- package/package.json +99 -90
- package/src/bin/help.txt +3 -2
- package/src/bin/index.js +79 -59
- package/src/core/formatter/checkstyle.js +20 -17
- package/src/core/formatter/console.js +44 -24
- package/src/core/formatter/csv.js +11 -9
- package/src/core/formatter/github.js +114 -0
- package/src/core/formatter/json.js +16 -9
- package/src/core/formatter/unix.js +10 -7
- package/src/core/glob.js +76 -55
- package/src/core/index.js +21 -11
- package/src/core/normalize.js +222 -132
- package/src/core/severity.js +5 -3
- package/src/core/wrapper/addons-linter.js +47 -33
- package/src/core/wrapper/coffeelint.js +22 -16
- package/src/core/wrapper/csslint.js +27 -19
- package/src/core/wrapper/doiuse.js +28 -18
- package/src/core/wrapper/eslint.js +54 -34
- package/src/core/wrapper/flow-bin.js +18 -12
- package/src/core/wrapper/htmlhint.js +27 -19
- package/src/core/wrapper/htmllint.js +20 -13
- package/src/core/wrapper/jshint.js +28 -18
- package/src/core/wrapper/json-lint.js +25 -17
- package/src/core/wrapper/jsonlint-mod.js +22 -16
- package/src/core/wrapper/jsonlint.js +22 -16
- package/src/core/wrapper/lesshint.js +40 -29
- package/src/core/wrapper/markdownlint.js +28 -21
- package/src/core/wrapper/markuplint.js +60 -0
- package/src/core/wrapper/npm-package-json-lint.js +55 -0
- package/src/core/wrapper/prettier.js +77 -0
- package/src/core/wrapper/purgecss.js +33 -26
- package/src/core/wrapper/standard.js +45 -18
- package/src/core/wrapper/stylelint.js +32 -20
- package/src/core/wrapper/yaml-lint.js +28 -19
- package/src/types.d.ts +21 -19
- package/types/formatter/checkstyle.d.ts +5 -5
- package/types/formatter/console.d.ts +4 -4
- package/types/formatter/csv.d.ts +4 -4
- package/types/formatter/github.d.ts +40 -0
- package/types/formatter/json.d.ts +12 -10
- package/types/formatter/unix.d.ts +9 -7
- package/types/glob.d.ts +4 -25
- package/types/wrapper/addons-linter.d.ts +3 -1
- package/types/wrapper/coffeelint.d.ts +3 -1
- package/types/wrapper/csslint.d.ts +3 -1
- package/types/wrapper/doiuse.d.ts +3 -1
- package/types/wrapper/eslint.d.ts +4 -1
- package/types/wrapper/flow-bin.d.ts +3 -1
- package/types/wrapper/htmlhint.d.ts +3 -1
- package/types/wrapper/htmllint.d.ts +3 -1
- package/types/wrapper/jshint.d.ts +3 -1
- package/types/wrapper/json-lint.d.ts +3 -1
- package/types/wrapper/jsonlint-mod.d.ts +3 -1
- package/types/wrapper/jsonlint.d.ts +3 -1
- package/types/wrapper/lesshint.d.ts +3 -1
- package/types/wrapper/markdownlint.d.ts +3 -1
- package/types/wrapper/markuplint.d.ts +4 -0
- package/types/wrapper/npm-package-json-lint.d.ts +4 -0
- package/types/wrapper/prettier.d.ts +5 -0
- package/types/wrapper/purgecss.d.ts +4 -1
- package/types/wrapper/standard.d.ts +3 -1
- package/types/wrapper/stylelint.d.ts +4 -1
- package/types/wrapper/yaml-lint.d.ts +3 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Metalint
|
|
2
2
|
|
|
3
|
+
<!-- Utiliser du HTML pour faire flotter l'image à droite. -->
|
|
4
|
+
<!-- markdownlint-disable-next-line no-inline-html-->
|
|
5
|
+
<img src="asset/logo.svg" align="right" alt="">
|
|
6
|
+
|
|
3
7
|
[![npm][img-npm]][link-npm]
|
|
4
8
|
[![build][img-build]][link-build]
|
|
5
9
|
[![coverage][img-coverage]][link-coverage]
|
|
@@ -13,6 +17,8 @@
|
|
|
13
17
|
L'analyse est déléguée à des linters (outils d'analyse statique de code source)
|
|
14
18
|
ou des utilitaires selon le type de fichier :
|
|
15
19
|
|
|
20
|
+
- _Générique_ :
|
|
21
|
+
[Prettier](https://regseb.github.io/metalint/user/linters/prettier/) ;
|
|
16
22
|
- WebExtension : [Add-ons
|
|
17
23
|
Linter](https://regseb.github.io/metalint/user/linters/addons-linter/) ;
|
|
18
24
|
- CoffeeScript :
|
|
@@ -23,8 +29,9 @@ ou des utilitaires selon le type de fichier :
|
|
|
23
29
|
[lesshint](https://regseb.github.io/metalint/user/linters/lesshint/),
|
|
24
30
|
[PurgeCSS](https://regseb.github.io/metalint/user/linters/purgecss/) et
|
|
25
31
|
[stylelint](https://regseb.github.io/metalint/user/linters/stylelint/) ;
|
|
26
|
-
- HTML : [HTMLHint](https://regseb.github.io/metalint/user/linters/htmlhint/)
|
|
27
|
-
[htmllint](https://regseb.github.io/metalint/user/linters/htmllint/)
|
|
32
|
+
- HTML : [HTMLHint](https://regseb.github.io/metalint/user/linters/htmlhint/),
|
|
33
|
+
[htmllint](https://regseb.github.io/metalint/user/linters/htmllint/) et
|
|
34
|
+
[markuplint](https://regseb.github.io/metalint/user/linters/markuplint/) ;
|
|
28
35
|
- JavaScript : [ESLint](https://regseb.github.io/metalint/user/linters/eslint/),
|
|
29
36
|
[Flow](https://regseb.github.io/metalint/user/linters/flow-bin/),
|
|
30
37
|
[JSHint](https://regseb.github.io/metalint/user/linters/jshint/) et
|
|
@@ -34,6 +41,9 @@ ou des utilitaires selon le type de fichier :
|
|
|
34
41
|
[JSON Lint](https://regseb.github.io/metalint/user/linters/jsonlint/) et
|
|
35
42
|
[JSON Lint
|
|
36
43
|
(mod)](https://regseb.github.io/metalint/user/linters/jsonlint-mod/) ;
|
|
44
|
+
- package.json (npm) :
|
|
45
|
+
[npm-package-json-lint](https://regseb.github.io/metalint/user/linters/npm-package-json-lint/)
|
|
46
|
+
;
|
|
37
47
|
- Markdown :
|
|
38
48
|
[MarkdownLint](https://regseb.github.io/metalint/user/linters/markdownlint/) ;
|
|
39
49
|
- YAML : [YAML Lint](https://regseb.github.io/metalint/user/linters/yaml-lint/).
|
|
@@ -42,7 +52,7 @@ ou des utilitaires selon le type de fichier :
|
|
|
42
52
|
|
|
43
53
|
Vous pouvez installer Metalint en utilisant [npm][link-npm] :
|
|
44
54
|
|
|
45
|
-
```
|
|
55
|
+
```Shell
|
|
46
56
|
npm install metalint --save-dev
|
|
47
57
|
```
|
|
48
58
|
|
|
@@ -50,17 +60,18 @@ npm install metalint --save-dev
|
|
|
50
60
|
|
|
51
61
|
Tous les fichiers de configuration sont à regrouper dans le répertoire
|
|
52
62
|
`.metalint/` qui doit être placé à la racine du projet. Le fichier
|
|
53
|
-
`metalint.config.js`
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
`metalint.config.js` export un objet JSON indiquant les linters à utiliser pour
|
|
64
|
+
chaque fichier. Les autres fichiers contiennent les options spécifiques pour les
|
|
65
|
+
linters.
|
|
56
66
|
|
|
57
67
|
## Exemple
|
|
58
68
|
|
|
59
|
-
Dans cet exemple
|
|
60
|
-
|
|
61
|
-
|
|
69
|
+
Dans cet exemple des fichiers de configuration, Metalint analyse les fichiers
|
|
70
|
+
JavaScript (non-minifiés), HTML et CSS ; avec respectivement les linters ESLint,
|
|
71
|
+
HTMLHint et stylelint.
|
|
62
72
|
|
|
63
73
|
```JavaScript
|
|
74
|
+
// .metalint/metalint.config.js
|
|
64
75
|
export default {
|
|
65
76
|
patterns: ["!/.git/", "!/node_modules/", "**"],
|
|
66
77
|
checkers: [
|
|
@@ -78,20 +89,56 @@ export default {
|
|
|
78
89
|
};
|
|
79
90
|
```
|
|
80
91
|
|
|
81
|
-
|
|
92
|
+
```JavaScript
|
|
93
|
+
// .metalint/eslint.config.js
|
|
94
|
+
export default {
|
|
95
|
+
rules: {
|
|
96
|
+
quotes: ["error", "double"],
|
|
97
|
+
semi: ["error", "always"],
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```JavaScript
|
|
103
|
+
// .metalint/htmlhint.config.js
|
|
104
|
+
export default {
|
|
105
|
+
"attr-value-not-empty": false,
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```JavaScript
|
|
110
|
+
// .metalint/stylelint.config.js
|
|
111
|
+
export default {
|
|
112
|
+
rules: {
|
|
113
|
+
"color-no-invalid-hex": true,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Intégration
|
|
119
|
+
|
|
120
|
+
Après avoir installé Metalint et les linters dans votre projet npm, vous pouvez
|
|
121
|
+
ajouter le script suivant dans votre `package.json` :
|
|
82
122
|
|
|
83
|
-
```
|
|
84
|
-
|
|
123
|
+
```JSON
|
|
124
|
+
{
|
|
125
|
+
"scripts": {
|
|
126
|
+
"lint": "metalint"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
85
129
|
```
|
|
86
130
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
[img-npm]:https://img.shields.io/npm/dm/metalint?label=npm
|
|
90
|
-
[img-build]:https://img.shields.io/github/workflow/status/regseb/metalint/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
[
|
|
96
|
-
[
|
|
97
|
-
[link-
|
|
131
|
+
Metalint est maintenant utilisable avec la commande : `npm run lint`
|
|
132
|
+
|
|
133
|
+
[img-npm]: https://img.shields.io/npm/dm/metalint?label=npm&logo=npm&logoColor=white
|
|
134
|
+
[img-build]: https://img.shields.io/github/actions/workflow/status/regseb/metalint/ci.yml?branch=main&logo=github&logoColor=white
|
|
135
|
+
|
|
136
|
+
<!-- Attendre que le logo de Stryker soit accepté.
|
|
137
|
+
https://github.com/simple-icons/simple-icons/pull/7388 -->
|
|
138
|
+
|
|
139
|
+
[img-coverage]: https://img.shields.io/endpoint?label=coverage&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fregseb%2Fmetalint%2Fmain
|
|
140
|
+
[img-semver]: https://img.shields.io/badge/semver-2.0.0-blue?logo=semver&logoColor=white
|
|
141
|
+
[link-npm]: https://www.npmjs.com/package/metalint
|
|
142
|
+
[link-build]: https://github.com/regseb/metalint/actions/workflows/ci.yml?query=branch%3Amain
|
|
143
|
+
[link-coverage]: https://dashboard.stryker-mutator.io/reports/github.com/regseb/metalint/main
|
|
144
|
+
[link-semver]: https://semver.org/spec/v2.0.0.html "Semantic Versioning 2.0.0"
|
package/package.json
CHANGED
|
@@ -1,92 +1,101 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
2
|
+
"name": "metalint",
|
|
3
|
+
"version": "0.11.1",
|
|
4
|
+
"description": "Un linter pour les gouverner tous.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"checker",
|
|
7
|
+
"lint",
|
|
8
|
+
"metalint",
|
|
9
|
+
"quality",
|
|
10
|
+
"static-analysis"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/regseb/metalint#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/regseb/metalint/issues",
|
|
15
|
+
"email": "regseb@gmail.com"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "Sébastien Règne <regseb@gmail.com> (https://github.com/regseb)",
|
|
19
|
+
"funding": "https://www.paypal.me/sebastienregne",
|
|
20
|
+
"files": [
|
|
21
|
+
"src/",
|
|
22
|
+
"types/"
|
|
23
|
+
],
|
|
24
|
+
"main": "src/core/index.js",
|
|
25
|
+
"types": "types/index.d.ts",
|
|
26
|
+
"bin": "src/bin/index.js",
|
|
27
|
+
"repository": "regseb/metalint",
|
|
28
|
+
"type": "module",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"lint": "src/bin/index.js",
|
|
31
|
+
"lint:fix": "src/bin/index.js --fix",
|
|
32
|
+
"lint:types": "tsc --project .tsconfig_lint.json",
|
|
33
|
+
"test": "npm run test:unit",
|
|
34
|
+
"test:unit": "mocha --config test/mocharc.json",
|
|
35
|
+
"test:coverage": "stryker run .stryker.config.js",
|
|
36
|
+
"jsdocs": "typedoc --tsconfig .tsconfig_jsdocs.json --out jsdocs/ src/core/",
|
|
37
|
+
"prepare": "tsc --project .tsconfig_types.json",
|
|
38
|
+
"release": "standard-version",
|
|
39
|
+
"clean": "node .script/clean.js"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"chalk": "5.2.0",
|
|
43
|
+
"yargs": "17.7.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@coffeelint/cli": "5.2.11",
|
|
47
|
+
"@prettier/plugin-xml": "2.2.0",
|
|
48
|
+
"@stryker-mutator/core": "6.4.1",
|
|
49
|
+
"@stryker-mutator/mocha-runner": "6.4.1",
|
|
50
|
+
"@types/debug": "4.1.7",
|
|
51
|
+
"@types/eslint": "8.21.1",
|
|
52
|
+
"@types/file-entry-cache": "5.0.2",
|
|
53
|
+
"@types/htmlhint": "1.1.2",
|
|
54
|
+
"@types/js-yaml": "4.0.5",
|
|
55
|
+
"@types/jshint": "2.12.1",
|
|
56
|
+
"@types/mocha": "10.0.1",
|
|
57
|
+
"@types/mock-fs": "4.13.1",
|
|
58
|
+
"@types/node": "18.14.6",
|
|
59
|
+
"@types/sinon": "10.0.13",
|
|
60
|
+
"@types/yargs": "17.0.22",
|
|
61
|
+
"addons-linter": "5.30.0",
|
|
62
|
+
"csslint": "1.0.5",
|
|
63
|
+
"doiuse": "4.4.1",
|
|
64
|
+
"eslint": "8.35.0",
|
|
65
|
+
"eslint-plugin-array-func": "3.1.8",
|
|
66
|
+
"eslint-plugin-eslint-comments": "3.2.0",
|
|
67
|
+
"eslint-plugin-import": "2.27.5",
|
|
68
|
+
"eslint-plugin-jsdoc": "40.0.1",
|
|
69
|
+
"eslint-plugin-mocha": "10.1.0",
|
|
70
|
+
"eslint-plugin-n": "15.6.1",
|
|
71
|
+
"eslint-plugin-no-unsanitized": "4.0.2",
|
|
72
|
+
"eslint-plugin-promise": "6.1.1",
|
|
73
|
+
"eslint-plugin-regexp": "1.12.0",
|
|
74
|
+
"eslint-plugin-unicorn": "46.0.0",
|
|
75
|
+
"flow-bin": "0.201.0",
|
|
76
|
+
"htmlhint": "1.1.4",
|
|
77
|
+
"htmllint": "0.8.0",
|
|
78
|
+
"jshint": "2.13.6",
|
|
79
|
+
"json-lint": "0.1.0",
|
|
80
|
+
"jsonlint": "1.6.3",
|
|
81
|
+
"jsonlint-mod": "1.7.6",
|
|
82
|
+
"lesshint": "6.3.7",
|
|
83
|
+
"markdownlint": "0.27.0",
|
|
84
|
+
"markuplint": "3.3.0",
|
|
85
|
+
"mocha": "10.2.0",
|
|
86
|
+
"mock-fs": "5.2.0",
|
|
87
|
+
"npm-package-json-lint": "6.4.0",
|
|
88
|
+
"prettier": "2.8.4",
|
|
89
|
+
"purgecss": "5.0.0",
|
|
90
|
+
"sinon": "15.0.1",
|
|
91
|
+
"standard": "17.0.0",
|
|
92
|
+
"standard-version": "9.5.0",
|
|
93
|
+
"stylelint": "15.2.0",
|
|
94
|
+
"typedoc": "0.23.26",
|
|
95
|
+
"typescript": "4.9.5",
|
|
96
|
+
"yaml-lint": "1.7.0"
|
|
97
|
+
},
|
|
98
|
+
"engines": {
|
|
99
|
+
"node": ">=18.12.0"
|
|
100
|
+
}
|
|
92
101
|
}
|
package/src/bin/help.txt
CHANGED
|
@@ -6,13 +6,14 @@ options courtes.
|
|
|
6
6
|
-c, --config=CONFIG spécifier l'emplacement du fichier de configuration
|
|
7
7
|
-f, --formatter=FORMATTER définir le formateur utilisé pour afficher les
|
|
8
8
|
résultats
|
|
9
|
+
--fix corriger les fichiers
|
|
9
10
|
-l, --level=NIVEAU définir le niveau de sévérité global
|
|
10
11
|
-o, --output=OUTPUT spécifier le fichier de sortie où seront écrit les
|
|
11
12
|
résultats
|
|
12
13
|
-p, --patterns=PATRONS spécifier les patrons pour filtrer les fichiers qui
|
|
13
14
|
seront analysés
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
--help afficher l'aide et quitter
|
|
16
|
+
--version afficher des informations de version et quitter
|
|
16
17
|
|
|
17
18
|
L'argument NIVEAU peut avoir comme valeur : off, fatal, error, warn ou info.
|
|
18
19
|
|
package/src/bin/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import path from "node:path";
|
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import yargs from "yargs";
|
|
7
7
|
import glob from "../core/glob.js";
|
|
8
|
-
import normalize from "../core/normalize.js";
|
|
9
8
|
import metalint from "../core/index.js";
|
|
9
|
+
import normalize from "../core/normalize.js";
|
|
10
10
|
import SEVERITY from "../core/severity.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -14,51 +14,61 @@ import SEVERITY from "../core/severity.js";
|
|
|
14
14
|
* @typedef {import("../types").Formatter} Formatter
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
if (undefined === import.meta.resolve) {
|
|
18
|
+
/**
|
|
19
|
+
* Résous un chemin relatif à partir du module.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} specifier Le chemin relatif vers un fichier ou un
|
|
22
|
+
* répertoire.
|
|
23
|
+
* @returns {Promise<string>} Une promesse contenant le chemin absolue vers
|
|
24
|
+
* le fichier ou le répertoire.
|
|
25
|
+
* @see https://nodejs.org/api/esm.html#importmetaresolvespecifier-parent
|
|
26
|
+
*/
|
|
27
|
+
import.meta.resolve = (specifier) => {
|
|
28
|
+
return Promise.resolve(
|
|
29
|
+
fileURLToPath(new URL(specifier, import.meta.url).href),
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
29
33
|
|
|
30
|
-
const argv = yargs(process.argv.slice(2))
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
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;
|
|
62
72
|
|
|
63
73
|
/**
|
|
64
74
|
* Vérifie (en appelant des linters) une liste de fichiers.
|
|
@@ -70,17 +80,18 @@ const argv = yargs(process.argv.slice(2)).options({
|
|
|
70
80
|
* dossier <code>.metalint/</code>.
|
|
71
81
|
* @param {Formatter[]} reporters La liste des rapporteurs utilisés pour
|
|
72
82
|
* afficher les résultats.
|
|
73
|
-
* @returns {Promise
|
|
83
|
+
* @returns {Promise<number|undefined>} La sévérité la plus élévée des
|
|
84
|
+
* résultats.
|
|
74
85
|
*/
|
|
75
86
|
const check = async function (files, checkers, root, reporters) {
|
|
76
|
-
let severity
|
|
87
|
+
let severity;
|
|
77
88
|
|
|
78
89
|
const results = await metalint(files, checkers, root);
|
|
79
90
|
for (const [file, notices] of Object.entries(results)) {
|
|
80
91
|
// Déterminer la sévérité la plus élévée des résultats.
|
|
81
|
-
if (
|
|
92
|
+
if (undefined !== notices) {
|
|
82
93
|
for (const notice of notices) {
|
|
83
|
-
if (
|
|
94
|
+
if (undefined === severity || severity > notice.severity) {
|
|
84
95
|
severity = notice.severity;
|
|
85
96
|
}
|
|
86
97
|
}
|
|
@@ -98,7 +109,9 @@ const check = async function (files, checkers, root, reporters) {
|
|
|
98
109
|
};
|
|
99
110
|
|
|
100
111
|
if (argv.help) {
|
|
101
|
-
process.stdout.write(
|
|
112
|
+
process.stdout.write(
|
|
113
|
+
fs.readFileSync(await import.meta.resolve("./help.txt")),
|
|
114
|
+
);
|
|
102
115
|
process.exit(0);
|
|
103
116
|
}
|
|
104
117
|
|
|
@@ -117,20 +130,27 @@ while (!fs.existsSync(path.join(root, argv.config))) {
|
|
|
117
130
|
try {
|
|
118
131
|
// eslint-disable-next-line no-unsanitized/method
|
|
119
132
|
const { default: config } = await import(path.join(root, argv.config));
|
|
120
|
-
const { patterns, checkers, reporters } =
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
const { patterns, checkers, reporters } = await normalize(
|
|
134
|
+
config,
|
|
135
|
+
root,
|
|
136
|
+
path.dirname(path.join(root, argv.config)),
|
|
137
|
+
argv,
|
|
138
|
+
);
|
|
125
139
|
|
|
126
|
-
const
|
|
140
|
+
const bases = await Promise.resolve(argv._.map((a) => glob.normalize(a)));
|
|
141
|
+
const files = await glob.walk(bases, patterns, root);
|
|
127
142
|
|
|
128
143
|
const severity = await check(files, checkers, root, reporters);
|
|
129
144
|
let code;
|
|
130
145
|
switch (severity) {
|
|
131
|
-
case SEVERITY.FATAL:
|
|
132
|
-
|
|
133
|
-
|
|
146
|
+
case SEVERITY.FATAL:
|
|
147
|
+
code = 2;
|
|
148
|
+
break;
|
|
149
|
+
case SEVERITY.ERROR:
|
|
150
|
+
code = 1;
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
code = 0;
|
|
134
154
|
}
|
|
135
155
|
process.exit(code);
|
|
136
156
|
} catch (err) {
|