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.
Files changed (98) hide show
  1. package/README.md +135 -37
  2. package/package.json +38 -43
  3. package/src/bin/argv.js +103 -0
  4. package/src/bin/help.txt +3 -7
  5. package/src/bin/index.js +54 -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 +50 -54
  10. package/src/core/formatter/console.js +62 -53
  11. package/src/core/formatter/csv.js +26 -25
  12. package/src/core/formatter/formatter.js +101 -0
  13. package/src/core/formatter/github.js +37 -42
  14. package/src/core/formatter/json.js +27 -23
  15. package/src/core/formatter/unix.js +26 -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 +258 -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 +74 -42
  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-check-updates.js +87 -0
  35. package/src/core/wrapper/npm-package-json-lint.js +72 -38
  36. package/src/core/wrapper/prantlf__jsonlint.js +84 -0
  37. package/src/core/wrapper/prettier.js +92 -49
  38. package/src/core/wrapper/purgecss.js +74 -44
  39. package/src/core/wrapper/sort-package-json.js +95 -0
  40. package/src/core/wrapper/standard.js +72 -50
  41. package/src/core/wrapper/stylelint.js +78 -43
  42. package/src/core/wrapper/wrapper.js +150 -0
  43. package/src/core/wrapper/yaml-lint.js +67 -39
  44. package/src/type/index.d.ts +149 -0
  45. package/types/configuration/flatten.d.ts +55 -0
  46. package/types/configuration/normalize.d.ts +50 -0
  47. package/types/configuration/override.d.ts +3 -0
  48. package/types/formatter/checkstyle.d.ts +24 -41
  49. package/types/formatter/console.d.ts +31 -38
  50. package/types/formatter/csv.d.ts +17 -32
  51. package/types/formatter/formatter.d.ts +44 -0
  52. package/types/formatter/github.d.ts +21 -33
  53. package/types/formatter/json.d.ts +27 -56
  54. package/types/formatter/unix.d.ts +19 -44
  55. package/types/index.d.ts +14 -10
  56. package/types/levels.d.ts +8 -0
  57. package/types/severities.d.ts +7 -0
  58. package/types/utils/array.d.ts +1 -0
  59. package/types/utils/file.d.ts +1 -0
  60. package/types/utils/glob.d.ts +39 -0
  61. package/types/utils/object.d.ts +1 -0
  62. package/types/wrapper/addons-linter.d.ts +36 -4
  63. package/types/wrapper/coffeelint__cli.d.ts +36 -0
  64. package/types/wrapper/csslint.d.ts +36 -4
  65. package/types/wrapper/doiuse.d.ts +36 -4
  66. package/types/wrapper/eslint.d.ts +36 -5
  67. package/types/wrapper/htmlhint.d.ts +36 -4
  68. package/types/wrapper/htmllint.d.ts +36 -4
  69. package/types/wrapper/jshint.d.ts +36 -4
  70. package/types/wrapper/jsonlint-mod.d.ts +35 -4
  71. package/types/wrapper/markdownlint.d.ts +36 -4
  72. package/types/wrapper/markuplint.d.ts +36 -4
  73. package/types/wrapper/npm-check-updates.d.ts +36 -0
  74. package/types/wrapper/npm-package-json-lint.d.ts +36 -4
  75. package/types/wrapper/prantlf__jsonlint.d.ts +37 -0
  76. package/types/wrapper/prettier.d.ts +36 -5
  77. package/types/wrapper/purgecss.d.ts +36 -5
  78. package/types/wrapper/sort-package-json.d.ts +36 -0
  79. package/types/wrapper/standard.d.ts +36 -4
  80. package/types/wrapper/stylelint.d.ts +36 -5
  81. package/types/wrapper/wrapper.d.ts +67 -0
  82. package/types/wrapper/yaml-lint.d.ts +36 -4
  83. package/src/core/glob.js +0 -211
  84. package/src/core/normalize.js +0 -574
  85. package/src/core/wrapper/coffeelint.js +0 -47
  86. package/src/core/wrapper/flow-bin.js +0 -91
  87. package/src/core/wrapper/json-lint.js +0 -55
  88. package/src/core/wrapper/jsonlint.js +0 -54
  89. package/src/core/wrapper/lesshint.js +0 -67
  90. package/src/types.d.ts +0 -35
  91. package/types/glob.d.ts +0 -9
  92. package/types/normalize.d.ts +0 -18
  93. package/types/severity.d.ts +0 -8
  94. package/types/wrapper/coffeelint.d.ts +0 -4
  95. package/types/wrapper/flow-bin.d.ts +0 -4
  96. package/types/wrapper/json-lint.d.ts +0 -4
  97. package/types/wrapper/jsonlint.d.ts +0 -4
  98. 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 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-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 metalint --save-dev
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 stylelint.
169
+ HTMLHint et Stylelint.
72
170
 
73
171
  ```JavaScript
74
172
  // .metalint/metalint.config.js
75
173
  export default {
76
- patterns: ["!/.git/", "!/node_modules/", "**"],
174
+ patterns: ["**", "!/.git/**", "!/node_modules/**"],
77
175
  checkers: [
78
176
  {
79
- patterns: ["!*.min.js", "*.js"],
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.11.1",
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 --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
- "chalk": "5.2.0",
43
- "yargs": "17.7.1"
42
+ "chalk": "5.3.0",
43
+ "yargs": "17.7.2"
44
44
  },
45
45
  "devDependencies": {
46
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",
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/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.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": "4.4.1",
64
- "eslint": "8.35.0",
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": "40.0.1",
65
+ "eslint-plugin-jsdoc": "46.4.4",
69
66
  "eslint-plugin-mocha": "10.1.0",
70
- "eslint-plugin-n": "15.6.1",
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.12.0",
74
- "eslint-plugin-unicorn": "46.0.0",
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
- "lesshint": "6.3.7",
83
- "markdownlint": "0.27.0",
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-package-json-lint": "6.4.0",
88
- "prettier": "2.8.4",
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.1",
91
- "standard": "17.0.0",
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.0",
94
- "typedoc": "0.23.26",
95
- "typescript": "4.9.5",
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": {
@@ -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=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,26 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import fs from "node:fs";
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 { fileURLToPath } from "node:url";
6
- import yargs from "yargs";
7
- import glob from "../core/glob.js";
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 normalize from "../core/normalize.js";
10
- import SEVERITY from "../core/severity.js";
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("../types").Checker} Checker
14
- * @typedef {import("../types").Formatter} Formatter
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 {Promise<string>} Une promesse contenant le chemin absolue vers
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 Promise.resolve(
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[]} 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.
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 reporter of reporters) {
102
- await reporter.notify(file, notices);
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(reporters.map((r) => r.finalize(severity)));
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.readFileSync(await import.meta.resolve("./help.txt")),
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 (!fs.existsSync(path.join(root, argv.config))) {
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(path.join(root, argv.config));
133
- const { patterns, checkers, reporters } = await normalize(
134
- config,
135
- root,
136
- path.dirname(path.join(root, argv.config)),
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 bases = await Promise.resolve(argv._.map((a) => glob.normalize(a)));
141
- const files = await glob.walk(bases, patterns, root);
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 SEVERITY.FATAL:
125
+ case Severities.FATAL:
147
126
  code = 2;
148
127
  break;
149
- case SEVERITY.ERROR:
128
+ case Severities.ERROR:
150
129
  code = 1;
151
130
  break;
152
131
  default: