htmllint / htmllint-cli

A command line interface for htmllint.
ISC License
59 stars 32 forks source link

Add format & stdin options #30

Closed tengattack closed 6 years ago

tengattack commented 6 years ago

Hi,

I add formatter and stdin options to this cli command line interface.

I think it would help if we can specify lint result output format to JSON format.

Usage shown as blow:

Lints html files with htmllint.
Usage: cli.js [OPTIONS] [ARGS]

Options:
  --help             Show help                                         [boolean]
  --version          Show version number                               [boolean]
  --rc               path to a htmllintrc file to use (json)     [default: null]
  --format           output formatter (default: simple)      [default: "simple"]
  --cwd              path to use for the current working directory
                                                                 [default: null]
  --stdin-file-path  read html content from stdin and specify its file path
                                                                 [default: null]
mlochbaum commented 6 years ago

Nice! I think the --stdin-file-path option is kind of confusing, since there's not a real file involved (the path is just used as a name for output, right?). It's also kind of strange that it works with no file name given but then uses the name "true". I will probably change it to --stdin and use a default filename of "stdin".

The --format option should also list possible values in the help. It would be nice if it got these dynamically from lib/formatters, but I doubt there will be too many formatters so that's probably overkill.

tengattack commented 6 years ago

I use the option --stdin-file-path by extracting HTML content from other kinds of language or template (like EJS, PHP). I think providing full file path can help us to identify the original source file name (like path, extension, etc.) for rules and plugins so that they could be enabled or not through the config file based on the path pattern or the file name extension.

mlochbaum commented 6 years ago

I definitely agree that the name option to --stdin-file-path is useful. It's just that calling it --stdin-file-path rather than --stdin is confusing: it seems like it's purpose is just to set the file path for stdin and there should be some other option to enable it in the first place.

I changed the option name to --stdin and changed the help text to something I find clearer. I also changed the behavior when --stdin is used without a value so that the filename "stdin" is used, rather than "true". Does that work for you?

tengattack commented 6 years ago

Oh I see, I misunderstood before. That’s work for me.

fchiumeo commented 5 years ago

version 0.0.7 not contains this feature and how write custom formatter ?

tengattack commented 5 years ago

Hi, I didn't know why 0.0.7 not contains this feature, maybe we could ask the maintainer @mlochbaum

If you need to write custom formatter, you could take a look at: https://github.com/htmllint/htmllint-cli/blob/acb3029dbd7a5000407bfb474d522d3c9f714eb2/lib/formatters/index.js#L2-L5 formatter predefined there.

And then, you can take a look at the simple formatter: https://github.com/htmllint/htmllint-cli/blob/master/lib/formatters/simple.js

It contains two functions only, and I think it's easy to understand.

fchiumeo commented 5 years ago

how call the custom formatter? only accept this two format

tengattack commented 5 years ago

Currently, we can only call the custom formatter by adding it to the source code like above json formatter.