feat: allow to strip ANSI for the result of `formatMessage`
import { formatMessage } from 'publint/utils'
import fs from 'node:fs/promises'
const pkg = JSON.parse(
await fs.readFile('./path/to/package/package.json', 'utf8')
)
for (const message of messages) {
console.log(formatMessage(message, pkg)) // Color
}
I'm creating a eslint plugin eslint-plugin-publint. I don't need ANSI in the result of formatMessage. Support an option to strip ANSI. Otherwise, I have to use (or copy the code of) strip-ansi to strip it. :)
I guess it's not hard to add a ,color = false option to disable colors, feel free to send a PR for that if you'd like. But at the same time, I'm not sure if eslint-plugin-publint makes sense to me. publint is mean to run of published files, not source code, which eslint covers. So you'd usually run publint separately as its own process.
publintis mean to run of published files, not source code, which eslint covers. So you'd usually runpublintseparately as its own process.
Generally, publint report suggestion/warning/error on package.json file, so does eslint. From this point of view, eslint plugin for publint is possible. Am I wrong?
It does currently only reports on the package.json, but I'd like to expand it towards more files as well, particularly on published files (something I'm working on in the next version). So while you could make it work as an ESLint plugin today, it might not be suitable to do so in the future.
i use it to replace colors
// inspired by https://github.com/chalk/ansi-regex/blob/main/index.js#L1
export const ANSI_COLORS_REGEXP =
/[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))/g;
But then i just replace functions which add ANSI colors
picocolors: {
default: `{
bold: (s) => s,
yellow: (s) => s
}`,
},
Glad to see that now i can just color: false with https://github.com/bluwy/publint/pull/110