{"size": 1433, "ext": "js", "max_stars_repo_path": "src/core/wrapper/jshint.js", "max_stars_repo_name": "regseb/metalint", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/core/wrapper/jshint.js", "max_issues_repo_name": "regseb/metalint", "max_issues_repo_issues_event_min_datetime": "2020-03-17T00:31:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T13:37:23.000Z", "max_forks_repo_path": "src/core/wrapper/jshint.js", "max_forks_repo_name": "regseb/metalint", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 31.152173913, "max_line_length": 75, "alphanum_fraction": 0.5624563852}
/**
 * @module
 * @see {@link https://www.npmjs.com/package/jshint|JSHint}
 */

import fs from "node:fs/promises";
import { JSHINT } from "jshint";
import SEVERITY from "../severity.js";

/**
 * @typedef {import("../../types").Notice} Notice
 */

/**
 * Vérifie un fichier avec le linter <strong>JSHint</strong>.
 *
 * @param {string}  file    Le fichier qui sera vérifié.
 * @param {number}  level   Le niveau de sévérité minimum des notifications
 *                          retournées.
 * @param {?Object} options Les options qui seront passées au linter ou
 *                          <code>null</code> pour les options par défaut.
 * @returns {Promise<Notice[]>} Une promesse retournant la liste des
 *                              notifications.
 */
export const wrapper = async function (file, level, options) {
    if (SEVERITY.ERROR > level) {
        return [];
    }

    const source = await fs.readFile(file, "utf8");
    // eslint-disable-next-line new-cap
    JSHINT(source, options);
    return JSHINT.errors.map((result) => ({
        file,
        linter:    "jshint",
        rule:      result.code,
        severity:  result.code.startsWith("W") ? SEVERITY.WARN
                                               : SEVERITY.ERROR,
        message:   result.reason,
        locations: [{
            line:   result.line,
            column: result.character,
        }],
    })).filter((n) => level >= n.severity);
};
