Files
Nikolay Vitkov 2a1b3b34b1 Update StyleLint to v16
Stylelint v16 deprecated CJS so I moved our lint script to ESM,
and fixed all the deprecation warning.
The only place I needed to silence them were tests,
as we import CJS there.

Bug: none
Change-Id: Iae4d2df76c855a9738b774a2d035f22509770215
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6138610
Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
2025-01-03 02:57:06 -08:00

53 lines
1.5 KiB
JavaScript

import preprocessWarnings from './preprocessWarnings.mjs';
/**
* @see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
*
* @type {import('stylelint').Formatter}
*
* @deprecated See https://stylelint.io/awesome-stylelint#formatters for alternative formatters.
*/
export default function githubFormatter(results, returnValue) {
const title = 'Stylelint problem';
const metadata = returnValue.ruleMetadata;
const lines = results.flatMap((result) => {
const { source, warnings } = preprocessWarnings(result);
return warnings.map(({ line, column, endLine, endColumn, text, severity, rule }) => {
const msg = buildMessage(text, metadata[rule]);
return endLine === undefined
? `::${severity} file=${source},line=${line},col=${column},title=${title}::${msg}`
: `::${severity} file=${source},line=${line},col=${column},endLine=${endLine},endColumn=${endColumn},title=${title}::${msg}`;
});
});
lines.push(`::notice title=Stylelint deprecation::The github formatter is deprecated`);
lines.push('');
return lines.join('\n');
}
/**
* @param {string} msg
* @param {Partial<import('stylelint').RuleMeta> | undefined} metadata
* @returns {string}
*/
function buildMessage(msg, metadata) {
if (!metadata) return msg;
const url = metadata.url ? ` - ${metadata.url}` : '';
let additional = [
metadata.fixable ? 'maybe fixable' : '',
metadata.deprecated ? 'deprecated' : '',
]
.filter(Boolean)
.join(', ');
additional = additional ? ` [${additional}]` : '';
return `${msg}${additional}${url}`;
}