mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Update to ESLint 9's "flat" configuration file format.
This commit is contained in:
parent
36844eefef
commit
c6716f9bac
9 changed files with 155 additions and 191 deletions
|
|
@ -1598,22 +1598,12 @@ test("customRulesLintJavaScript", (t) => new Promise((resolve) => {
|
|||
t.falsy(err);
|
||||
const expected = {
|
||||
"test/lint-javascript.md": [
|
||||
{
|
||||
"lineNumber": 10,
|
||||
"ruleNames": [ "lint-javascript" ],
|
||||
"ruleDescription": "Rule that lints JavaScript code",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Unexpected var, use let or const instead.",
|
||||
"errorContext": "var x = 0;",
|
||||
"errorRange": null,
|
||||
"fixInfo": null
|
||||
},
|
||||
{
|
||||
"lineNumber": 12,
|
||||
"ruleNames": [ "lint-javascript" ],
|
||||
"ruleDescription": "Rule that lints JavaScript code",
|
||||
"ruleInformation": null,
|
||||
"errorDetail": "Unexpected console statement.",
|
||||
"errorDetail": "'console' is not defined.",
|
||||
"errorContext": "console.log(x);",
|
||||
"errorRange": null,
|
||||
"fixInfo": null
|
||||
|
|
|
|||
|
|
@ -2,54 +2,31 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const js = require("@eslint/js");
|
||||
const { filterTokens } = require("../../helpers");
|
||||
const eslint = require("eslint");
|
||||
const eslintInstance = new eslint.ESLint();
|
||||
const linter = new eslint.Linter();
|
||||
const languageJavaScript = /js|javascript/i;
|
||||
|
||||
/**
|
||||
* Remove references to rules from eslint-plugin-jsdoc.
|
||||
*
|
||||
* @param {Object} config ESLint configuration object.
|
||||
* @returns {Object} ESLint configuration object.
|
||||
*/
|
||||
function cleanJsdocRulesFromEslintConfig(config) {
|
||||
const cleanedConfig = { ...config };
|
||||
for (const rule in config.rules) {
|
||||
if (/^(?:jsdoc|n|regexp|unicorn)\//.test(rule)) {
|
||||
delete cleanedConfig.rules[rule];
|
||||
}
|
||||
}
|
||||
return cleanedConfig;
|
||||
}
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule */
|
||||
module.exports = {
|
||||
"names": [ "lint-javascript" ],
|
||||
"description": "Rule that lints JavaScript code",
|
||||
"tags": [ "test", "lint", "javascript" ],
|
||||
"parser": "markdownit",
|
||||
"asynchronous": true,
|
||||
"function": (params, onError) => {
|
||||
filterTokens(params, "fence", (fence) => {
|
||||
if (languageJavaScript.test(fence.info)) {
|
||||
return eslintInstance.calculateConfigForFile(params.name)
|
||||
.then((config) => {
|
||||
config = cleanJsdocRulesFromEslintConfig(config);
|
||||
const results = linter.verify(fence.content, config);
|
||||
for (const result of results) {
|
||||
// @ts-ignore
|
||||
const lineNumber = fence.lineNumber + result.line;
|
||||
onError({
|
||||
"lineNumber": lineNumber,
|
||||
"detail": result.message,
|
||||
"context": params.lines[lineNumber - 1]
|
||||
});
|
||||
}
|
||||
const results = linter.verify(fence.content, js.configs.recommended);
|
||||
for (const result of results) {
|
||||
const lineNumber = fence.lineNumber + result.line;
|
||||
onError({
|
||||
"lineNumber": lineNumber,
|
||||
"detail": result.message,
|
||||
"context": params.lines[lineNumber - 1]
|
||||
});
|
||||
}
|
||||
}
|
||||
return Promise.resolve();
|
||||
});
|
||||
// Unsupported:
|
||||
// filterTokens("code_block"), language unknown
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue