metalint 0.14.1 → 0.15.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020-2023 Sébastien Règne
3
+ Copyright (c) 2020-2024 Sébastien Règne
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Metalint
2
2
 
3
- <!-- Utiliser du HTML pour faire flotter l'image à droite. -->
3
+ <!-- Utiliser du HTML (avec l'attribut "align" obsolète) pour faire flotter
4
+ l'image à droite. -->
4
5
  <!-- markdownlint-disable-next-line no-inline-html-->
5
6
  <img src="asset/logo.svg" align="right" alt="">
6
7
 
@@ -72,6 +73,7 @@ source) :
72
73
  <tr>
73
74
  <td>JSON</td>
74
75
  <td>
76
+ <a title="ajv" href="https://www.npmjs.com/package/ajv">Ajv</a>,
75
77
  <a title="@prantlf/jsonlint"
76
78
  href="https://www.npmjs.com/package/@prantlf/jsonlint">@prantlf/JSON
77
79
  Lint</a>,
@@ -100,18 +102,16 @@ source) :
100
102
  <tr>
101
103
  <td>package.json</td>
102
104
  <td>
103
- <!-- markdownlint-disable no-bare-urls -->
104
- <!-- https://github.com/DavidAnson/markdownlint/issues/961 -->
105
+ <a title="depcheck"
106
+ href="https://www.npmjs.com/package/depcheck">Depcheck</a>
105
107
  <a title="npm-check-updates"
106
108
  href="https://www.npmjs.com/package/npm-check-updates"
107
109
  >npm-check-updates</a>,
108
- <!-- markdownlint-enable no-bare-urls -->
109
- <!-- markdownlint-disable no-bare-urls -->
110
- <!-- https://github.com/DavidAnson/markdownlint/issues/961 -->
111
110
  <a title="npm-package-json-lint"
112
111
  href="https://www.npmjs.com/package/npm-package-json-lint"
113
112
  >npm-package-json-lint</a>,
114
- <!-- markdownlint-enable no-bare-urls -->
113
+ <a title="publint"
114
+ href="https://www.npmjs.com/package/publint">publint</a>,
115
115
  <a title="sort-package-json"
116
116
  href="https://www.npmjs.com/package/sort-package-json">Sort
117
117
  Package.json</a>
@@ -133,6 +133,15 @@ source) :
133
133
  href="https://www.npmjs.com/package/stylelint">Stylelint</a>
134
134
  </td>
135
135
  </tr>
136
+ <tr>
137
+ <td>SVG</td>
138
+ <td>
139
+ <a title="prettier"
140
+ href="https://www.npmjs.com/package/prettier">Prettier</a>,
141
+ <a title="svglint"
142
+ href="https://www.npmjs.com/package/svglint">SVGLint</a>
143
+ </td>
144
+ </tr>
136
145
  <tr>
137
146
  <td>WebExtension</td>
138
147
  <td>
@@ -221,6 +230,8 @@ export default {
221
230
 
222
231
  ## Intégration
223
232
 
233
+ ### npm
234
+
224
235
  Après avoir installé Metalint et les linters dans votre projet npm, vous pouvez
225
236
  ajouter le script suivant dans votre `package.json` :
226
237
 
@@ -234,6 +245,26 @@ ajouter le script suivant dans votre `package.json` :
234
245
 
235
246
  Metalint est maintenant utilisable avec la commande : `npm run lint`
236
247
 
248
+ ### GitHub Actions
249
+
250
+ Pour lancer Metalint dans vos GitHub Actions, vous pouvez utiliser le formateur
251
+ `github` pour rapporter les problèmes dans les pull requests.
252
+
253
+ ```YAML
254
+ jobs:
255
+ lint:
256
+ runs-on: ubuntu-latest
257
+ steps:
258
+ - uses: actions/setup-node@v4
259
+ - uses: actions/checkout@v4
260
+ with:
261
+ persist-credentials: false
262
+ - name: Install dependencies
263
+ run: npm ci
264
+ - name: Lint files
265
+ run: npm run lint -- --formatter github
266
+ ```
267
+
237
268
  [img-npm]: https://img.shields.io/npm/dm/metalint?label=npm&logo=npm&logoColor=whitesmoke
238
269
  [img-build]: https://img.shields.io/github/actions/workflow/status/regseb/metalint/ci.yml?branch=main&logo=github&logoColor=whitesmoke
239
270
  [img-coverage]: https://img.shields.io/endpoint?label=coverage&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fregseb%2Fmetalint%2Fmain&logo=stryker&logoColor=whitesmoke
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metalint",
3
- "version": "0.14.1",
3
+ "version": "0.15.0",
4
4
  "description": "Un linter pour les gouverner tous.",
5
5
  "keywords": [
6
6
  "checker",
@@ -24,7 +24,7 @@
24
24
  "exports": {
25
25
  ".": {
26
26
  "types": "./types/index.d.ts",
27
- "default": "./src/code/index.js"
27
+ "default": "./src/core/index.js"
28
28
  },
29
29
  "./api/formatter": {
30
30
  "types": "./types/formatter/formatter.d.ts",
@@ -47,7 +47,7 @@
47
47
  "lint:types": "tsc --project .tsconfig_lint.json",
48
48
  "test": "npm run test:unit",
49
49
  "test:unit": "mocha --config test/unit/mocharc.json",
50
- "test:coverage": "stryker run .stryker.config.js",
50
+ "test:coverage": "stryker run",
51
51
  "jsdocs": "typedoc --tsconfig .tsconfig_jsdocs.json",
52
52
  "prepare": "tsc --project .tsconfig_types.json",
53
53
  "clean": "node .script/clean.js"
@@ -59,51 +59,54 @@
59
59
  "devDependencies": {
60
60
  "@coffeelint/cli": "5.2.11",
61
61
  "@prantlf/jsonlint": "14.0.3",
62
- "@prettier/plugin-xml": "3.2.0",
63
- "@stryker-mutator/core": "7.1.1",
64
- "@stryker-mutator/mocha-runner": "7.1.1",
65
- "@types/eslint": "8.44.2",
66
- "@types/htmlhint": "1.1.2",
67
- "@types/jshint": "2.12.2",
68
- "@types/mocha": "10.0.1",
69
- "@types/mock-fs": "4.13.1",
70
- "@types/sinon": "10.0.16",
71
- "@types/yargs": "17.0.24",
72
- "addons-linter": "6.13.0",
62
+ "@prettier/plugin-xml": "3.2.2",
63
+ "@stryker-mutator/core": "8.0.0",
64
+ "@stryker-mutator/mocha-runner": "8.0.0",
65
+ "@types/eslint": "8.56.1",
66
+ "@types/htmlhint": "1.1.5",
67
+ "@types/jshint": "2.12.4",
68
+ "@types/mocha": "10.0.6",
69
+ "@types/sinon": "17.0.2",
70
+ "@types/yargs": "17.0.32",
71
+ "addons-linter": "6.19.0",
72
+ "ajv": "8.12.0",
73
73
  "csslint": "1.0.5",
74
+ "depcheck": "1.4.7",
74
75
  "doiuse": "6.0.2",
75
- "eslint": "8.49.0",
76
- "eslint-plugin-array-func": "3.1.8",
76
+ "eslint": "8.56.0",
77
+ "eslint-plugin-array-func": "4.0.0",
77
78
  "eslint-plugin-eslint-comments": "3.2.0",
78
- "eslint-plugin-import": "2.28.1",
79
- "eslint-plugin-jsdoc": "46.5.1",
80
- "eslint-plugin-mocha": "10.1.0",
81
- "eslint-plugin-n": "16.0.2",
79
+ "eslint-plugin-import": "2.29.1",
80
+ "eslint-plugin-jsdoc": "48.0.2",
81
+ "eslint-plugin-mocha": "10.2.0",
82
+ "eslint-plugin-n": "16.6.1",
82
83
  "eslint-plugin-no-unsanitized": "4.0.2",
83
84
  "eslint-plugin-promise": "6.1.1",
84
- "eslint-plugin-regexp": "1.15.0",
85
- "eslint-plugin-unicorn": "48.0.1",
85
+ "eslint-plugin-regexp": "2.1.2",
86
+ "eslint-plugin-unicorn": "50.0.1",
86
87
  "htmlhint": "1.1.4",
87
88
  "htmllint": "0.8.0",
88
89
  "jshint": "2.13.6",
89
90
  "jsonlint-mod": "1.7.6",
90
- "markdownlint": "0.31.0",
91
- "markuplint": "3.12.1",
91
+ "jszip": "3.10.1",
92
+ "markdownlint": "0.32.1",
93
+ "markuplint": "3.15.0",
92
94
  "mocha": "10.2.0",
93
- "mock-fs": "5.2.0",
94
- "npm-check-updates": "16.13.3",
95
- "npm-package-json-lint": "7.0.0",
96
- "prettier": "3.0.3",
95
+ "npm-check-updates": "16.14.12",
96
+ "npm-package-json-lint": "7.1.0",
97
+ "prettier": "3.1.1",
98
+ "publint": "0.2.7",
97
99
  "purgecss": "5.0.0",
98
- "sinon": "15.2.0",
99
- "sort-package-json": "2.5.1",
100
+ "sinon": "17.0.1",
101
+ "sort-package-json": "2.6.0",
100
102
  "standard": "17.1.0",
101
- "stylelint": "15.10.3",
102
- "typedoc": "0.25.1",
103
- "typescript": "5.2.2",
103
+ "stylelint": "16.1.0",
104
+ "svglint": "2.6.0",
105
+ "typedoc": "0.25.6",
106
+ "typescript": "5.3.3",
104
107
  "yaml-lint": "1.7.0"
105
108
  },
106
109
  "engines": {
107
- "node": ">=20.0.0"
110
+ "node": ">=20.6.0"
108
111
  }
109
112
  }
package/src/bin/index.js CHANGED
@@ -1,86 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
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
3
  import fs from "node:fs/promises";
8
- import path from "node:path";
9
4
  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";
13
- import metalint from "../core/index.js";
5
+ import { fileURLToPath } from "node:url";
6
+ import Metalint from "../core/index.js";
14
7
  import Severities from "../core/severities.js";
15
- import { exists } from "../core/utils/file.js";
16
- import Glob from "../core/utils/glob.js";
17
8
  import { parse } from "./argv.js";
18
9
 
19
- /**
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
24
- */
25
-
26
- if (undefined === import.meta.resolve) {
27
- /**
28
- * Résous un chemin relatif à partir du module.
29
- *
30
- * @param {string} specifier Le chemin relatif vers un fichier ou un
31
- * répertoire.
32
- * @returns {string} L'URL absolue vers le fichier ou le répertoire.
33
- * @see https://nodejs.org/api/esm.html#importmetaresolvespecifier-parent
34
- */
35
- import.meta.resolve = (specifier) => {
36
- return new URL(specifier, import.meta.url).href;
37
- };
38
- }
39
-
40
- /**
41
- * Vérifie (en appelant des linters) une liste de fichiers.
42
- *
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 élevée des
53
- * résultats.
54
- */
55
- const check = async function (files, checkers, root, reporters) {
56
- let severity;
57
-
58
- const formatters = reporters.map((reporter) => {
59
- // eslint-disable-next-line new-cap
60
- return new reporter.formatter(reporter.level, reporter.options);
61
- });
62
- const results = await metalint(files, checkers, root);
63
- for (const [file, notices] of Object.entries(results)) {
64
- // Déterminer la sévérité la plus élevée des résultats.
65
- if (undefined !== notices) {
66
- for (const notice of notices) {
67
- if (undefined === severity || severity > notice.severity) {
68
- severity = notice.severity;
69
- }
70
- }
71
- }
72
-
73
- // Afficher les notifications avec chaque rapporteur.
74
- for (const formatter of formatters) {
75
- await formatter.notify(file, notices);
76
- }
77
- }
78
-
79
- // Attendre tous les rapporteurs.
80
- await Promise.all(formatters.map((f) => f.finalize()));
81
- return severity;
82
- };
83
-
84
10
  const argv = await parse();
85
11
  if (argv.help) {
86
12
  process.stdout.write(
@@ -89,37 +15,16 @@ if (argv.help) {
89
15
  process.exit(0);
90
16
  }
91
17
 
92
- let root = process.cwd();
93
- // Rechercher le fichier de configuration dans le répertoire courant, puis dans
94
- // les parents, grands-parents...
95
- while (!(await exists(path.join(root, argv.config)))) {
96
- // Si on est remonté à la racine.
97
- if (path.join(root, "..") === root) {
98
- process.stderr.write("metalint: no such config file.\n");
99
- process.exit(10);
100
- }
101
- root = path.join(root, "..");
102
- }
103
-
104
18
  try {
105
- // eslint-disable-next-line no-unsanitized/method
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
- }),
113
- argv,
114
- );
115
-
116
- const glob = new Glob(patterns, { root });
117
- const files = [];
118
- for (const base of argv._) {
119
- files.push(...(await glob.walk(base)));
120
- }
19
+ const metalint = await Metalint.fromFileSystem({
20
+ config: argv.config,
21
+ fix: argv.fix,
22
+ formatter: argv.formatter,
23
+ level: argv.level,
24
+ });
25
+ const results = await metalint.lintFiles(argv._);
26
+ const severity = await metalint.report(results);
121
27
 
122
- const severity = await check(files, checkers, root, reporters);
123
28
  let code;
124
29
  switch (severity) {
125
30
  case Severities.FATAL:
@@ -255,16 +255,18 @@ export const flattenChecker = function (hierarchy, { fix, level }) {
255
255
  /**
256
256
  * Fusionne la configuration.
257
257
  *
258
- * @param {NormalizedConfig} hierarchy L'objet JSON normalisé contenant la
259
- * configuration.
260
- * @param {Object} argv Certaines options de la ligne de
261
- * commande.
262
- * @param {boolean|undefined} argv.fix L'option <code>--fix</code> de la
263
- * ligne de commande.
264
- * @param {TypeofFormatter} argv.formatter L'option <code>--formatter</code>
265
- * de la ligne de commande.
266
- * @param {Level} argv.level L'options <code>--level</code> de
267
- * la ligne de commande.
258
+ * @param {NormalizedConfig} hierarchy L'objet JSON normalisé
259
+ * contenant la configuration.
260
+ * @param {Object} argv Certaines options de la
261
+ * ligne de commande.
262
+ * @param {boolean|undefined} argv.fix L'option <code>--fix</code>
263
+ * de la ligne de commande.
264
+ * @param {TypeofFormatter|undefined} argv.formatter L'option
265
+ * <code>--formatter</code> de
266
+ * la ligne de commande.
267
+ * @param {Level|undefined} argv.level L'options
268
+ * <code>--level</code> de la
269
+ * ligne de commande.
268
270
  * @returns {FlattenedConfig} L'objet JSON fusionné.
269
271
  */
270
272
  export const flatten = function (hierarchy, argv) {
@@ -272,7 +274,6 @@ export const flatten = function (hierarchy, argv) {
272
274
  const level = flattenLevel(argv.level ?? Levels.INFO, {
273
275
  level: hierarchy.level,
274
276
  });
275
- // TODO Vérifier que checkers n'est pas vide.
276
277
  return {
277
278
  patterns: hierarchy.patterns,
278
279
  reporters: flattenReporters(hierarchy.reporters, {
@@ -112,14 +112,14 @@ const printCodeSource = function (locations, content, writer) {
112
112
  printCodeSourceLine(line - 1, content, false, writer);
113
113
  printCodeSourceLine(line, content, true, writer);
114
114
  if (0 !== columns.length) {
115
- let dashs = "-".repeat(6 + columns.at(-1));
115
+ let dashes = "-".repeat(6 + columns.at(-1));
116
116
  for (const column of columns) {
117
- dashs =
118
- dashs.slice(0, 6 + column) +
117
+ dashes =
118
+ dashes.slice(0, 6 + column) +
119
119
  "^" +
120
- dashs.slice(6 + column + 1);
120
+ dashes.slice(6 + column + 1);
121
121
  }
122
- print(writer, dashs + "\n");
122
+ print(writer, dashes + "\n");
123
123
  }
124
124
  printCodeSourceLine(line + 1, content, false, writer);
125
125
  printCodeSourceLine(line + 2, content, false, writer);
@@ -12,20 +12,6 @@ import { fileURLToPath } from "node:url";
12
12
  * @typedef {import("../../type/index.js").Notice} Notice
13
13
  */
14
14
 
15
- if (undefined === import.meta.resolve) {
16
- /**
17
- * Résous un chemin relatif à partir du module.
18
- *
19
- * @param {string} specifier Le chemin relatif vers un fichier ou un
20
- * répertoire.
21
- * @returns {string} L'URL absolue vers le fichier ou le répertoire.
22
- * @see https://nodejs.org/api/esm.html#importmetaresolvespecifier-parent
23
- */
24
- import.meta.resolve = (specifier) => {
25
- return new URL(specifier, import.meta.url).href;
26
- };
27
- }
28
-
29
15
  /**
30
16
  * La liste des fichiers JavaScript des formateurs.
31
17
  *
@@ -39,10 +25,11 @@ const scripts = await fs.readdir(fileURLToPath(import.meta.resolve("./")));
39
25
  * @constant {string[]} FORMATTERS
40
26
  */
41
27
  export const FORMATTERS = scripts
42
- // Enlever l'extension du fichier.
43
- .map((f) => f.slice(0, -3))
44
- // Enlever ce fichier qui n'est pas un vrai formateur.
45
- .filter((f) => "formatter" !== f);
28
+ // Garder seulement les fichiers JavaScript et enlever le fichier
29
+ // "formatter.js" qui n'est pas un vrai formateur.
30
+ .filter((f) => f.endsWith(".js") && "formatter.js" !== f)
31
+ // Enlever l'extension des fichiers.
32
+ .map((f) => f.slice(0, -3));
46
33
 
47
34
  /**
48
35
  * Le formateur parent.