eslint-plugin-header icon indicating copy to clipboard operation
eslint-plugin-header copied to clipboard

Better error message

Open sboudrias-aa opened this issue 7 years ago • 2 comments

Hey Stewart!

It'd be nice to have clearer error messages. Right now "header error" is a bit generic and might be confusing.

We're ready to provide a PR, but I wanted to discuss solutions. Would it make sense to make an expectedHeader option to provide an exact expected message value?

Expected file to start with:
// Copyright 2017 Cie Name Ltd.

This would allow to pass filled copyright message that is easy to copy/paste.

I feel an auto-fixer (eg eslint --fix) would also require such an option.

sboudrias-aa avatar Mar 03 '17 05:03 sboudrias-aa

Hey Simon!

Yeah, I agree they're a bit generic, mainly because I didn't put in the effort to make them better!

One thing that seems ideal would be to use the existing configuration header in the error message, however I'm guessing you're using the regex configuration, which isn't copy and paste-able?

The concern I have is that the copyright headers I've seen span many lines, and having a duplicate matcher and ideal copyright header seems redundant, and also including a multi-line header in the ESLint output could be a bit verbose.

The examples I've seen so far mainly need a regex to match the year, so I'm now wondering if it would be worth having a "templated" header that allows you to embed {year} (or something) in the expected header. This could act as \d{4} in the matcher, then be replaced with the current year in the error message/--fix functionality. This would reduce the duplication within the configuration.

What do you think?

Stuk avatar Mar 03 '17 06:03 Stuk

year would be good. Actually, you could have {year} (match any year, default to current year), {initialYear} (file create year from git/etc), {currentYear} (file update year from git/etc, falling back to the current year)

srl295 avatar Feb 08 '18 15:02 srl295