Add @stylistic/eslint-plugin to ESLint configuration.

This commit is contained in:
David Anson 2024-09-01 16:16:05 -07:00
parent fe02674ce0
commit 164bbac651
21 changed files with 103 additions and 78 deletions

View file

@ -2540,11 +2540,13 @@ function lintInput(options, synchronous, callback) {
const config = options.config || { "default": true };
const configParsers = options.configParsers || null;
const frontMatter = (options.frontMatter === undefined) ?
helpers.frontMatterRe : options.frontMatter;
helpers.frontMatterRe :
options.frontMatter;
const handleRuleFailures = !!options.handleRuleFailures;
const noInlineConfig = !!options.noInlineConfig;
const resultVersion = (options.resultVersion === undefined) ?
3 : options.resultVersion;
3 :
options.resultVersion;
const getMarkdownIt = () => {
const markdownit = __webpack_require__(/*! markdown-it */ "markdown-it");
const md = markdownit({ "html": true });
@ -4027,14 +4029,14 @@ module.exports = {
codeBlock.children,
[ "codeFlowValue" ]
);
const dollarMatches = codeFlowValues.
map((codeFlowValue) => ({
const dollarMatches = codeFlowValues
.map((codeFlowValue) => ({
"result": codeFlowValue.text.match(dollarCommandRe),
"startColumn": codeFlowValue.startColumn,
"startLine": codeFlowValue.startLine,
"text": codeFlowValue.text
})).
filter((dollarMatch) => dollarMatch.result);
}))
.filter((dollarMatch) => dollarMatch.result);
if (dollarMatches.length === codeFlowValues.length) {
for (const dollarMatch of dollarMatches) {
// @ts-ignore
@ -4647,9 +4649,9 @@ const { filterByTypesCached } = __webpack_require__(/*! ./cache */ "../lib/cache
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": ["MD027", "no-multiple-space-blockquote"],
"names": [ "MD027", "no-multiple-space-blockquote" ],
"description": "Multiple spaces after blockquote symbol",
"tags": ["blockquote", "whitespace", "indentation"],
"tags": [ "blockquote", "whitespace", "indentation" ],
"parser": "micromark",
"function": function MD027(params, onError) {
for (const token of filterByTypesCached([ "linePrefix" ])) {
@ -4921,10 +4923,12 @@ const codeFencePrefixRe = /^(.*?)[`~]/;
function addError(onError, lines, lineNumber, top) {
const line = lines[lineNumber - 1];
const [ , prefix ] = line.match(codeFencePrefixRe) || [];
const fixInfo = (prefix === undefined) ? null : {
"lineNumber": lineNumber + (top ? 0 : 1),
"insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
};
const fixInfo = (prefix === undefined) ?
null :
{
"lineNumber": lineNumber + (top ? 0 : 1),
"insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
};
addErrorContext(
onError,
lineNumber,
@ -5122,8 +5126,6 @@ module.exports = {
if ((token.type === "literalAutolink") && !inHtmlFlow(token)) {
// Detect and ignore https://github.com/micromark/micromark/issues/164
const siblings = token.parent?.children;
// Commented-out due to not being able to exercise in test/code coverage
// || micromarkTokens;
const index = siblings?.indexOf(token);
// @ts-ignore
const prev = siblings?.at(index - 1);
@ -5274,8 +5276,8 @@ module.exports = {
punctuation = String((punctuation === undefined) ? allPunctuation : punctuation);
const punctuationRe = new RegExp("[" + punctuation + "]$");
const paragraphTokens =
filterByTypesCached([ "paragraph" ]).
filter((token) =>
filterByTypesCached([ "paragraph" ])
.filter((token) =>
(token.parent?.type === "content") && !token.parent?.parent && (token.children.length === 1)
);
for (const paragraphToken of paragraphTokens) {
@ -5556,10 +5558,12 @@ function addLabelSpaceError(onError, label, labelText, isStart) {
isStart,
!isStart,
range,
range ? {
"editColumn": range[0],
"deleteCount": range[1]
} : undefined
range ?
{
"editColumn": range[0],
"deleteCount": range[1]
} :
undefined
);
}
@ -5584,8 +5588,8 @@ module.exports = {
"parser": "micromark",
"function": function MD039(params, onError) {
const { definitions } = getReferenceLinkImageData();
const labels = filterByTypesCached([ "label" ]).
filter((label) => label.parent?.type === "link");
const labels = filterByTypesCached([ "label" ])
.filter((label) => label.parent?.type === "link");
for (const label of labels) {
const labelTexts = filterByTypes(
label.children,
@ -5685,9 +5689,9 @@ module.exports = {
"function": function MD041(params, onError) {
const level = Number(params.config.level || 1);
if (!frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title)) {
params.parsers.micromark.tokens.
filter((token) => !nonContentTokens.has(token.type) && !isHtmlFlowComment(token)).
every((token) => {
params.parsers.micromark.tokens
.filter((token) => !nonContentTokens.has(token.type) && !isHtmlFlowComment(token))
.every((token) => {
let isError = true;
if ((token.type === "atxHeading") || (token.type === "setextHeading")) {
isError = (getHeadingLevel(token) !== level);
@ -6906,7 +6910,7 @@ module.exports = {
}
}
}
}
};
/***/ }),

View file

@ -1,14 +1,24 @@
import js from "@eslint/js";
import eslintPluginJsdoc from "eslint-plugin-jsdoc";
import eslintPluginNode from "eslint-plugin-n";
import eslintPluginRegexp from "eslint-plugin-regexp"
import eslintPluginRegexp from "eslint-plugin-regexp";
import eslintPluginStylistic from "@stylistic/eslint-plugin";
import eslintPluginUnicorn from "eslint-plugin-unicorn";
export default [
js.configs.all,
eslintPluginJsdoc.configs['flat/recommended'],
eslintPluginJsdoc.configs["flat/recommended"],
eslintPluginNode.configs["flat/recommended"],
eslintPluginRegexp.configs["flat/recommended"],
eslintPluginStylistic.configs.customize({
"arrowParens": true,
"braceStyle": "1tbs",
"commaDangle": "never",
"jsx": false,
"quoteProps": "always",
"quotes": "double",
"semi": true
}),
eslintPluginUnicorn.configs["flat/all"],
{
"ignores": [
@ -27,17 +37,23 @@ export default [
},
{
"languageOptions": {
"sourceType": "commonjs",
"sourceType": "commonjs"
},
"linterOptions": {
"reportUnusedDisableDirectives": true
},
"rules": {
"@stylistic/array-bracket-spacing": [ "error", "always" ],
"@stylistic/indent": [ "error", 2 ],
"@stylistic/indent-binary-ops": [ "off" ],
"@stylistic/operator-linebreak": [ "error", "after" ],
"@stylistic/padded-blocks": "off",
"@stylistic/space-before-function-paren": [ "error", "never" ],
"capitalized-comments": "off",
"complexity": "off",
"func-style": "off",
"id-length": "off",
"jsdoc/tag-lines": [ "error", "never", { "startLines":1 } ],
"jsdoc/tag-lines": [ "error", "never", { "startLines": 1 } ],
"logical-assignment-operators": "off",
"max-depth": "off",
"max-lines-per-function": "off",

View file

@ -932,11 +932,13 @@ function lintInput(options, synchronous, callback) {
const config = options.config || { "default": true };
const configParsers = options.configParsers || null;
const frontMatter = (options.frontMatter === undefined) ?
helpers.frontMatterRe : options.frontMatter;
helpers.frontMatterRe :
options.frontMatter;
const handleRuleFailures = !!options.handleRuleFailures;
const noInlineConfig = !!options.noInlineConfig;
const resultVersion = (options.resultVersion === undefined) ?
3 : options.resultVersion;
3 :
options.resultVersion;
const getMarkdownIt = () => {
const markdownit = require("markdown-it");
const md = markdownit({ "html": true });

View file

@ -21,14 +21,14 @@ module.exports = {
codeBlock.children,
[ "codeFlowValue" ]
);
const dollarMatches = codeFlowValues.
map((codeFlowValue) => ({
const dollarMatches = codeFlowValues
.map((codeFlowValue) => ({
"result": codeFlowValue.text.match(dollarCommandRe),
"startColumn": codeFlowValue.startColumn,
"startLine": codeFlowValue.startLine,
"text": codeFlowValue.text
})).
filter((dollarMatch) => dollarMatch.result);
}))
.filter((dollarMatch) => dollarMatch.result);
if (dollarMatches.length === codeFlowValues.length) {
for (const dollarMatch of dollarMatches) {
// @ts-ignore

View file

@ -8,9 +8,9 @@ const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": ["MD027", "no-multiple-space-blockquote"],
"names": [ "MD027", "no-multiple-space-blockquote" ],
"description": "Multiple spaces after blockquote symbol",
"tags": ["blockquote", "whitespace", "indentation"],
"tags": [ "blockquote", "whitespace", "indentation" ],
"parser": "micromark",
"function": function MD027(params, onError) {
for (const token of filterByTypesCached([ "linePrefix" ])) {

View file

@ -23,10 +23,12 @@ const codeFencePrefixRe = /^(.*?)[`~]/;
function addError(onError, lines, lineNumber, top) {
const line = lines[lineNumber - 1];
const [ , prefix ] = line.match(codeFencePrefixRe) || [];
const fixInfo = (prefix === undefined) ? null : {
"lineNumber": lineNumber + (top ? 0 : 1),
"insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
};
const fixInfo = (prefix === undefined) ?
null :
{
"lineNumber": lineNumber + (top ? 0 : 1),
"insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
};
addErrorContext(
onError,
lineNumber,

View file

@ -21,8 +21,6 @@ module.exports = {
if ((token.type === "literalAutolink") && !inHtmlFlow(token)) {
// Detect and ignore https://github.com/micromark/micromark/issues/164
const siblings = token.parent?.children;
// Commented-out due to not being able to exercise in test/code coverage
// || micromarkTokens;
const index = siblings?.indexOf(token);
// @ts-ignore
const prev = siblings?.at(index - 1);

View file

@ -25,8 +25,8 @@ module.exports = {
punctuation = String((punctuation === undefined) ? allPunctuation : punctuation);
const punctuationRe = new RegExp("[" + punctuation + "]$");
const paragraphTokens =
filterByTypesCached([ "paragraph" ]).
filter((token) =>
filterByTypesCached([ "paragraph" ])
.filter((token) =>
(token.parent?.type === "content") && !token.parent?.parent && (token.children.length === 1)
);
for (const paragraphToken of paragraphTokens) {

View file

@ -29,10 +29,12 @@ function addLabelSpaceError(onError, label, labelText, isStart) {
isStart,
!isStart,
range,
range ? {
"editColumn": range[0],
"deleteCount": range[1]
} : undefined
range ?
{
"editColumn": range[0],
"deleteCount": range[1]
} :
undefined
);
}
@ -57,8 +59,8 @@ module.exports = {
"parser": "micromark",
"function": function MD039(params, onError) {
const { definitions } = getReferenceLinkImageData();
const labels = filterByTypesCached([ "label" ]).
filter((label) => label.parent?.type === "link");
const labels = filterByTypesCached([ "label" ])
.filter((label) => label.parent?.type === "link");
for (const label of labels) {
const labelTexts = filterByTypes(
label.children,

View file

@ -16,9 +16,9 @@ module.exports = {
"function": function MD041(params, onError) {
const level = Number(params.config.level || 1);
if (!frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title)) {
params.parsers.micromark.tokens.
filter((token) => !nonContentTokens.has(token.type) && !isHtmlFlowComment(token)).
every((token) => {
params.parsers.micromark.tokens
.filter((token) => !nonContentTokens.has(token.type) && !isHtmlFlowComment(token))
.every((token) => {
let isError = true;
if ((token.type === "atxHeading") || (token.type === "setextHeading")) {
isError = (getHeadingLevel(token) !== level);

View file

@ -53,4 +53,4 @@ module.exports = {
}
}
}
}
};

View file

@ -70,6 +70,7 @@
},
"devDependencies": {
"@eslint/js": "9.9.1",
"@stylistic/eslint-plugin": "2.7.2",
"ajv": "8.17.1",
"ava": "6.1.3",
"c8": "10.1.2",

View file

@ -529,7 +529,7 @@ for (const rule of rules) {
"description": "Allow URLs as inline links",
"type": "boolean",
"default": true
},
}
};
break;
case "MD055":

View file

@ -77,8 +77,8 @@ test("filterByTypes, htmlFlow false", async(t) => {
// Not using flat tokens
t.deepEqual(
filtered,
filterByTypes([ ...tokens], types)
)
filterByTypes([ ...tokens ], types)
);
});
test("filterByTypes, htmlFlow true", async(t) => {
@ -95,8 +95,8 @@ test("filterByTypes, htmlFlow true", async(t) => {
// Not using flat tokens
t.deepEqual(
filtered,
filterByTypes([ ...tokens], types, true)
)
filterByTypes([ ...tokens ], types, true)
);
});
test("filterByPredicate/filterByTypes", async(t) => {

View file

@ -23,7 +23,7 @@ function markdownlintParallel(options) {
const workerData = {
...options,
"files": files.slice(i * chunkSize, (i + 1) * chunkSize)
}
};
const worker = new Worker(__filename.replace(/parallel\.js$/, "worker.js"), { workerData });
worker.on("message", resolve);
worker.on("error", reject);

View file

@ -33,8 +33,8 @@ async function lintTestRepo(t, globPatterns, configPath, parallel) {
// eslint-disable-next-line no-console
console.log(`${t.title}: Linting ${files.length} files...`);
const config = Object.fromEntries(
Object.entries(rawConfig).
map(([ k, v ]) => [
Object.entries(rawConfig)
.map(([ k, v ]) => [
k.replace(/header/, "heading"),
v
])

View file

@ -64,8 +64,8 @@ test("resultFormattingV0", (t) => new Promise((resolve) => {
"./test/atx_heading_spacing.md: 1: MD041" +
" First line in a file should be a top-level heading\n" +
"./test/first_heading_bad_atx.md: 1: MD041" +
" First line in a file should be a top-level heading"
t.is(actualMessage, expectedMessage, "Incorrect message (name).");
" First line in a file should be a top-level heading";
t.is(actualMessage, expectedMessage, "Incorrect message (name).");
// @ts-ignore
actualMessage = actualResult.toString(true);
expectedMessage =
@ -78,8 +78,8 @@ test("resultFormattingV0", (t) => new Promise((resolve) => {
"./test/atx_heading_spacing.md: 1: first-line-heading" +
" First line in a file should be a top-level heading\n" +
"./test/first_heading_bad_atx.md: 1: first-line-heading" +
" First line in a file should be a top-level heading"
t.is(actualMessage, expectedMessage, "Incorrect message (alias).");
" First line in a file should be a top-level heading";
t.is(actualMessage, expectedMessage, "Incorrect message (alias).");
resolve();
});
}));
@ -121,7 +121,7 @@ test("resultFormattingSyncV0", (t) => {
"./test/atx_heading_spacing.md: 1: MD041" +
" First line in a file should be a top-level heading\n" +
"./test/first_heading_bad_atx.md: 1: MD041" +
" First line in a file should be a top-level heading"
" First line in a file should be a top-level heading";
t.is(actualMessage, expectedMessage, "Incorrect message (name).");
// @ts-ignore
actualMessage = actualResult.toString(true);
@ -135,7 +135,7 @@ test("resultFormattingSyncV0", (t) => {
"./test/atx_heading_spacing.md: 1: first-line-heading" +
" First line in a file should be a top-level heading\n" +
"./test/first_heading_bad_atx.md: 1: first-line-heading" +
" First line in a file should be a top-level heading"
" First line in a file should be a top-level heading";
t.is(actualMessage, expectedMessage, "Incorrect message (alias).");
});

View file

@ -8,9 +8,9 @@ const markdownlint = require("../lib/markdownlint").promises.markdownlint;
// eslint-disable-next-line unicorn/prefer-top-level-await
markdownlint(workerData).then((lintResults) => {
// @ts-ignore
parentPort.
parentPort
// eslint-disable-next-line unicorn/require-post-message-target-origin
postMessage(lintResults);
.postMessage(lintResults);
// eslint-disable-next-line n/no-process-exit
process.exit();
});

View file

@ -13,8 +13,8 @@ module.exports = {
"tags": [ "test" ],
"parser": "markdownit",
"function": (params, onError) => {
const blockquotes = params.parsers.markdownit.tokens.
filter((token => token.type === "blockquote_open"));
const blockquotes = params.parsers.markdownit.tokens
.filter(((token) => token.type === "blockquote_open"));
for (const blockquote of blockquotes) {
const lines = blockquote.map[1] - blockquote.map[0];
onError({

View file

@ -14,8 +14,8 @@ module.exports = {
"tags": [ "test", "lint", "javascript" ],
"parser": "markdownit",
"function": (params, onError) => {
const fences = params.parsers.markdownit.tokens.
filter((token => token.type === "fence"));
const fences = params.parsers.markdownit.tokens
.filter(((token) => token.type === "fence"));
for (const fence of fences) {
if (languageJavaScript.test(fence.info)) {
const results = linter.verify(fence.content, js.configs.recommended);

View file

@ -12,8 +12,8 @@ module.exports = {
"parser": "markdownit",
"asynchronous": true,
"function": (params, onError) => {
const fences = params.parsers.markdownit.tokens.
filter((token => token.type === "fence"));
const fences = params.parsers.markdownit.tokens
.filter(((token) => token.type === "fence"));
for (const fence of fences) {
if (/jsonc?/i.test(fence.info)) {
const errors = [];