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.
Files changed (93) hide show
  1. package/README.md +129 -37
  2. package/package.json +25 -32
  3. package/src/bin/argv.js +102 -0
  4. package/src/bin/help.txt +3 -7
  5. package/src/bin/index.js +49 -75
  6. package/src/core/configuration/flatten.js +289 -0
  7. package/src/core/configuration/normalize.js +510 -0
  8. package/src/core/configuration/override.js +47 -0
  9. package/src/core/formatter/checkstyle.js +49 -54
  10. package/src/core/formatter/console.js +61 -53
  11. package/src/core/formatter/csv.js +25 -25
  12. package/src/core/formatter/formatter.js +101 -0
  13. package/src/core/formatter/github.js +36 -42
  14. package/src/core/formatter/json.js +26 -23
  15. package/src/core/formatter/unix.js +25 -25
  16. package/src/core/index.js +98 -46
  17. package/src/core/levels.js +18 -0
  18. package/src/core/{severity.js → severities.js} +3 -1
  19. package/src/core/utils/array.js +16 -0
  20. package/src/core/utils/file.js +23 -0
  21. package/src/core/utils/glob.js +257 -0
  22. package/src/core/utils/object.js +44 -0
  23. package/src/core/wrapper/addons-linter.js +88 -59
  24. package/src/core/wrapper/coffeelint__cli.js +80 -0
  25. package/src/core/wrapper/csslint.js +67 -35
  26. package/src/core/wrapper/doiuse.js +68 -41
  27. package/src/core/wrapper/eslint.js +89 -62
  28. package/src/core/wrapper/htmlhint.js +67 -35
  29. package/src/core/wrapper/htmllint.js +61 -32
  30. package/src/core/wrapper/jshint.js +67 -38
  31. package/src/core/wrapper/jsonlint-mod.js +51 -35
  32. package/src/core/wrapper/markdownlint.js +68 -40
  33. package/src/core/wrapper/markuplint.js +74 -44
  34. package/src/core/wrapper/npm-package-json-lint.js +72 -38
  35. package/src/core/wrapper/prantlf__jsonlint.js +84 -0
  36. package/src/core/wrapper/prettier.js +99 -48
  37. package/src/core/wrapper/purgecss.js +74 -44
  38. package/src/core/wrapper/standard.js +72 -50
  39. package/src/core/wrapper/stylelint.js +77 -43
  40. package/src/core/wrapper/wrapper.js +150 -0
  41. package/src/core/wrapper/yaml-lint.js +67 -39
  42. package/src/type/index.d.ts +149 -0
  43. package/types/configuration/flatten.d.ts +55 -0
  44. package/types/configuration/normalize.d.ts +50 -0
  45. package/types/configuration/override.d.ts +3 -0
  46. package/types/formatter/checkstyle.d.ts +24 -41
  47. package/types/formatter/console.d.ts +31 -38
  48. package/types/formatter/csv.d.ts +17 -32
  49. package/types/formatter/formatter.d.ts +44 -0
  50. package/types/formatter/github.d.ts +21 -33
  51. package/types/formatter/json.d.ts +27 -56
  52. package/types/formatter/unix.d.ts +19 -44
  53. package/types/index.d.ts +14 -10
  54. package/types/levels.d.ts +8 -0
  55. package/types/{severity.d.ts → severities.d.ts} +0 -1
  56. package/types/utils/array.d.ts +1 -0
  57. package/types/utils/file.d.ts +1 -0
  58. package/types/utils/glob.d.ts +39 -0
  59. package/types/utils/object.d.ts +1 -0
  60. package/types/wrapper/addons-linter.d.ts +36 -4
  61. package/types/wrapper/coffeelint__cli.d.ts +36 -0
  62. package/types/wrapper/csslint.d.ts +36 -4
  63. package/types/wrapper/doiuse.d.ts +36 -4
  64. package/types/wrapper/eslint.d.ts +36 -5
  65. package/types/wrapper/htmlhint.d.ts +36 -4
  66. package/types/wrapper/htmllint.d.ts +36 -4
  67. package/types/wrapper/jshint.d.ts +36 -4
  68. package/types/wrapper/jsonlint-mod.d.ts +35 -4
  69. package/types/wrapper/markdownlint.d.ts +36 -4
  70. package/types/wrapper/markuplint.d.ts +36 -4
  71. package/types/wrapper/npm-package-json-lint.d.ts +36 -4
  72. package/types/wrapper/prantlf__jsonlint.d.ts +37 -0
  73. package/types/wrapper/prettier.d.ts +36 -5
  74. package/types/wrapper/purgecss.d.ts +36 -5
  75. package/types/wrapper/standard.d.ts +36 -4
  76. package/types/wrapper/stylelint.d.ts +36 -5
  77. package/types/wrapper/wrapper.d.ts +67 -0
  78. package/types/wrapper/yaml-lint.d.ts +36 -4
  79. package/src/core/glob.js +0 -211
  80. package/src/core/normalize.js +0 -574
  81. package/src/core/wrapper/coffeelint.js +0 -47
  82. package/src/core/wrapper/flow-bin.js +0 -91
  83. package/src/core/wrapper/json-lint.js +0 -55
  84. package/src/core/wrapper/jsonlint.js +0 -54
  85. package/src/core/wrapper/lesshint.js +0 -67
  86. package/src/types.d.ts +0 -35
  87. package/types/glob.d.ts +0 -9
  88. package/types/normalize.d.ts +0 -18
  89. package/types/wrapper/coffeelint.d.ts +0 -4
  90. package/types/wrapper/flow-bin.d.ts +0 -4
  91. package/types/wrapper/json-lint.d.ts +0 -4
  92. package/types/wrapper/jsonlint.d.ts +0 -4
  93. 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 source)
18
- ou des utilitaires selon le type de fichier :
19
-
20
- - _Générique_ :
21
- [Prettier](https://regseb.github.io/metalint/user/linters/prettier/) ;
22
- - WebExtension : [Add-ons
23
- Linter](https://regseb.github.io/metalint/user/linters/addons-linter/) ;
24
- - CoffeeScript :
25
- [CoffeeLint](https://regseb.github.io/metalint/user/linters/coffeelint/) ;
26
- - CSS (SCSS, Sass, Less) :
27
- [CSSLint](https://regseb.github.io/metalint/user/linters/csslint/),
28
- [doiuse](https://regseb.github.io/metalint/user/linters/doiuse/),
29
- [lesshint](https://regseb.github.io/metalint/user/linters/lesshint/),
30
- [PurgeCSS](https://regseb.github.io/metalint/user/linters/purgecss/) et
31
- [stylelint](https://regseb.github.io/metalint/user/linters/stylelint/) ;
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/) ;
35
- - JavaScript : [ESLint](https://regseb.github.io/metalint/user/linters/eslint/),
36
- [Flow](https://regseb.github.io/metalint/user/linters/flow-bin/),
37
- [JSHint](https://regseb.github.io/metalint/user/linters/jshint/) et
38
- [JavaScript Standard
39
- Style](https://regseb.github.io/metalint/user/linters/standard/) ;
40
- - JSON : [JSON-Lint](https://regseb.github.io/metalint/user/linters/json-lint/),
41
- [JSON Lint](https://regseb.github.io/metalint/user/linters/jsonlint/) et
42
- [JSON Lint
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
- ;
47
- - Markdown :
48
- [MarkdownLint](https://regseb.github.io/metalint/user/linters/markdownlint/) ;
49
- - YAML : [YAML Lint](https://regseb.github.io/metalint/user/linters/yaml-lint/).
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 metalint --save-dev
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 stylelint.
163
+ HTMLHint et Stylelint.
72
164
 
73
165
  ```JavaScript
74
166
  // .metalint/metalint.config.js
75
167
  export default {
76
- patterns: ["!/.git/", "!/node_modules/", "**"],
168
+ patterns: ["**", "!/.git/**", "!/node_modules/**"],
77
169
  checkers: [
78
170
  {
79
- patterns: ["!*.min.js", "*.js"],
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.11.1",
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 --out jsdocs/ src/core/",
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.1"
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.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",
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/node": "18.14.6",
59
- "@types/sinon": "10.0.13",
60
- "@types/yargs": "17.0.22",
61
- "addons-linter": "5.30.0",
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.35.0",
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": "40.0.1",
65
+ "eslint-plugin-jsdoc": "43.1.1",
69
66
  "eslint-plugin-mocha": "10.1.0",
70
- "eslint-plugin-n": "15.6.1",
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.12.0",
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
- "lesshint": "6.3.7",
83
- "markdownlint": "0.27.0",
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.4",
81
+ "prettier": "2.8.8",
89
82
  "purgecss": "5.0.0",
90
- "sinon": "15.0.1",
83
+ "sinon": "15.0.4",
91
84
  "standard": "17.0.0",
92
85
  "standard-version": "9.5.0",
93
- "stylelint": "15.2.0",
94
- "typedoc": "0.23.26",
95
- "typescript": "4.9.5",
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": {
@@ -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=NIVEAU définir le niveau de sévérité global
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 NIVEAU peut avoir comme valeur : off, fatal, error, warn ou info.
14
+ L'argument LEVEL peut avoir comme valeur : off, fatal, error, warn ou info.
19
15
 
20
- Documentation complète à : <https://regseb.github.io/metalint/>
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 yargs from "yargs";
7
- import glob from "../core/glob.js";
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 normalize from "../core/normalize.js";
10
- import SEVERITY from "../core/severity.js";
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("../types").Checker} Checker
14
- * @typedef {import("../types").Formatter} Formatter
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 {Promise<string>} Une promesse contenant le chemin absolue vers
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 Promise.resolve(
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[]} files La liste des fichiers.
77
- * @param {Checker[]} checkers La liste des vérifications faites sur les
78
- * fichiers.
79
- * @param {string} root L'adresse du répertoire où se trouve le
80
- * dossier <code>.metalint/</code>.
81
- * @param {Formatter[]} reporters La liste des rapporteurs utilisés pour
82
- * afficher les résultats.
83
- * @returns {Promise<number|undefined>} La sévérité la plus élévée des
84
- * résultats.
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 reporter of reporters) {
102
- await reporter.notify(file, notices);
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(reporters.map((r) => r.finalize(severity)));
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.readFileSync(await import.meta.resolve("./help.txt")),
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 (!fs.existsSync(path.join(root, argv.config))) {
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(path.join(root, argv.config));
133
- const { patterns, checkers, reporters } = await normalize(
134
- config,
135
- root,
136
- path.dirname(path.join(root, argv.config)),
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 bases = await Promise.resolve(argv._.map((a) => glob.normalize(a)));
141
- const files = await glob.walk(bases, patterns, root);
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 SEVERITY.FATAL:
120
+ case Severities.FATAL:
147
121
  code = 2;
148
122
  break;
149
- case SEVERITY.ERROR:
123
+ case Severities.ERROR:
150
124
  code = 1;
151
125
  break;
152
126
  default: