Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error text more helpful? #8

Closed
bevacqua opened this issue May 2, 2018 · 4 comments
Closed

Make error text more helpful? #8

bevacqua opened this issue May 2, 2018 · 4 comments

Comments

@bevacqua
Copy link

bevacqua commented May 2, 2018

Would be better if it were configurable, or if it included a suggested fix:

  • Could not find a match for the mustMatch pattern. Are you missing the header text? notice/notice
  • Alternatively, make it configurable
notice/notice:
  - error
  - errorMessage: 'Missing license header'
  - templateFile: config/copyright.js
@nickdeis
Copy link
Owner

nickdeis commented May 3, 2018

Hey @bevacqua,
Thanks for filing an issue.
I like this idea a lot. There is a lot of information not being displayed to the user which may help them debug a header issue. An issue a ran into recently was trying to figure out why a big license header wasn't near enough to the template using the nonMatchingTolerance setting. Might of been useful to see what the edit distance was in the error message.
Hence, I'll probably make it configurable with good defaults. Not sure what those will be so if you have any idea about what you want to see in terms of available template variables or defaults feel free to pitch it.
Best,
Nick
PS: Huge fan of your writing!

@bevacqua
Copy link
Author

bevacqua commented May 3, 2018

Thanks!

I think the ability to set a custom message (I'd say plain text, but I guess you could later make it into a template if you think that's worthwhile) plus a default other than Could not find a match for the mustMatch pattern. which is not very descriptive would really help.

Maybe default to Missing notice header, which is closer to what other lint rules do? (It took me a bit to figure out the rule came from notice/notice, because the message itself was cryptic. Kind of like if the no-semi rule talked about tokens not being what it expected instead of just saying "missing semicolon")

@nickdeis
Copy link
Owner

nickdeis commented May 5, 2018

Great suggestions!
Missing notice header is probably the most appropriate when it fails to match, because often there is other stuff in a header.
For nonMatchingTolerance it can be a bit more complicated. Something like Found a header comment which was too different from the required notice header ({{ dist }}).
The other case of finding a header comment and choosing to fail would stay as is (Found a header comment which did not have a notice header, skipping fix and reporting).
Thanks for the help!

nickdeis added a commit that referenced this issue May 5, 2018
- Changed default error messages
- Added configurable error messages
@nickdeis
Copy link
Owner

nickdeis commented May 5, 2018

Changes are in version 0.7.7.
Relevant documentation

messages

The messages option allows you to change the default error messages.
There are three messages you can change by passing in an object with the pairs you wish to change.
For example, if you want to change the default message for when a header does not match mustMatch:

{
    "notice/notice":["error",
        {
            "mustMatch":"Apache License",
            "templateFile":"config/apache.js",
            "messages":{
                "whenFailedToMatch":"Couldn't find 'Apache License', are you sure you added it?"
            }
        }
    ]
}

The three configurable messages are:

  • whenFailedToMatch: When the header fails to match the mustMatch pattern.
  • reportAndSkip: When using "onNonMatchingHeader":"report" and a non-matching notice is found.
  • whenOutsideTolerance: When you using nonMatchingTolerance to check for notice similarity and it fails to be similar enough. Passes in similarity as a template variable (eg "The similarity is {{ similarity }}")

@nickdeis nickdeis closed this as completed May 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants