Skip to content

[Feature] Each formatter should generate separate output. #6036

@quisido

Description

@quisido

🚀 Feature request

Description

I want to use multiple formatters for my report, e.g.

  • html formatter to generate hint-report/mysite.html
  • json formatter to generate hint-report/output.json
  • codeframe formatter for logs during execution
  • summary formatter for logs during execution

Details

Today, if I specify a --output parameter, then this will throw errors, because json codeframe and summary all try to write to the same file.

html correctly generates a dynamic file name, allowing me to use it + another one.

I need to be able to tell each formatter whether to output to file: html yes, json yes (preferably with a different path than html), codeframe no, and summary no; because I want the latter two to output to console.

As a workaround, I've had to replace formatters: ["html"] with formatters: ["./path/to/custom-html.js"] and this implementation:

import HTMLFormatter from '@hint/formatter-html';
import type { Problem } from '@hint/utils-types';
import type { FormatterOptions } from 'hint';

export default class PatchedHTMLFormatter extends HTMLFormatter.default {
  override format(
    problems: Problem[],
    options: FormatterOptions = {},
  ): ReturnType<HTMLFormatter.default['format']> {
    return super.format(problems, {
      ...options,
      output: options.output ?? 'MY/CUSTOM/PATH/HERE', // <-- ⚠️
    });
  }
}

This isn't ideal, but hopefully it unblocks anyone else experiencing this error.

The optimal solution is likely to pass { "name": "html", "options": { "output": "..." } } the same way connectors supports options.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions