-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add option for custom error messages #1358
Comments
If you want to add |
Thanks for raising this issue. There are a couple of things to address here. Snake CaseI'm glad that you found a regex that works for you to implement IEEE ErrorYou mentioned that you were seeing errors telling you to change case_exceptions: [IEEE] This line of your config is telling the VSG to ignore the regex for the string Custom Error MessagesI'm afraid that I don't think that it is a good idea to open up error messages to user configuration. Each rule should have a solution message that is relevant, clear and helpful. We are all using the same set of rules, so the solution message for each rule should be relevant to everyone's use case. If the solution message is not relevant, clear and helpful enough, then, ideally, the user should raise an issue here, so that VSG can be improved and everyone who uses it can benefit. The main concern that I have is that users could misunderstand the rule and rewrite the solution message to be less helpful. In an extreme case, a user could accidentally rewrite the message for It also has the potential to end up being a lot of work. Currently there are solution messages that are dynamically changed to be more helpful, e.g. So users might want to be able to make their own dynamic solution messages. We then need to define a syntax that can be used to specify the original string, the corrected string, the number of indents, etc. And then we'd need to validate all of those different possible custom solution messages ("What does the tool do if you try to include the number of indents in a solution message for a rule that is about the case?"). In summary, if it were up to me, I would say that we shouldn't go ahead with this feature request. |
Morning @PelleEikeberg and @JHertz5 , YAML configurationI think you might want to change your YAML file to be this: rule:
group:
case:
case::name:
disable: false
phase: 6
case: regex
regex: (?![a-z||0-9]\u005F)(?!.*\u005F[a-z||0-9]$)([a-z||0-9]+(?:\u005F[a-z||0-9]+)*)
suffix_exceptions: [_n,_a,_s,_s1,_s2,_s3,_s4,_s5,_d,_d1,_d2,_d3,_d4,_d5,_p,_p1,_p2,_p3,_p4,_p5,_dp,_dn]
case_exceptions: [IEEE]
error_msg: "Group name must be in snake_case" This would ensure the regex does not apply to keywords, which do not have any underscores in it. VSG defaults all case to lowercase. Snake CaseThere is a discussion in issue #1202 on changing the definition of camelCase and PascalCase which might be of interest. What is your goal with the snake_case regex? Are you looking to force snake_case? I ask because I put your regex examples into regex101.com and put in some example strings: A string without an underscore still passes the regex. As @JHertz5 mentioned, identifiers are limited to numbers, letters, and underscores as defined by this production:
I think @JHertz5 is correct that just using lower case would meet your case needs. Unless you want to force at least one underscore, but then it appears you may need to change your regex. Custom Error Messages@JHertz5 makes a compelling argument to not allow users to change the error message. Could you elaborate on your use case? There may be a better alternative to meet your need. Regards, --Jeremy |
Thanks so much, @JHertz5 for a thorough explanation! Snake Case:You make a compelling point of using only IEEE Error:Thank you so much for explaining how it works! That was helpful :) Custom Error Messages:I understand your explanation for not using the existing message. However, in the case of
As the default could be nothing, this would only add functionality and not restrict it. I would also make it clear what is the VSG message, and the user custom config message, thus not "blaming" VSG for confusing messages. |
Evening @PelleEikeberg , Custom Error Messages
Ah. That makes sense. Since the regex is supplied by the user, then only the user understands what is required to pass the regex.
That seems like a reasonable solution. The only other solution I can see would be to report it at the end of the output, but then the user must bounce back and forth between lines to understand what to do. Maybe we use rule:
group:
case::name:
disable: false
case: regex
regex: (?![a-z||0-9]\u005F)(?!.*\u005F[a-z||0-9]$)([a-z||0-9]+(?:\u005F[a-z||0-9]+)*)
suffix_exceptions: [_n,_a,_s,_s1,_s2,_s3,_s4,_s5,_d,_d1,_d2,_d3,_d4,_d5,_p,_p1,_p2,_p3,_p4,_p5,_dp,_dn]
case_exceptions: [IEEE]
custom_error_message_author: PelleEikeberg
custom_error_message: "UPPERCASE and single letter prefix/suffix not allowed"
Hmm...maybe just the custom_error_message? rule:
group:
case:
case::name:
disable: false
case: regex
regex: (?![a-z||0-9]\u005F)(?!.*\u005F[a-z||0-9]$)([a-z||0-9]+(?:\u005F[a-z||0-9]+)*)
suffix_exceptions: [_n,_a,_s,_s1,_s2,_s3,_s4,_s5,_d,_d1,_d2,_d3,_d4,_d5,_p,_p1,_p2,_p3,_p4,_p5,_dp,_dn]
case_exceptions: [IEEE]
custom_error_message: "PelleEikeberg: UPPERCASE and single letter prefix/suffix not allowed" I believe appending a custom error message would be the correct solution. Just struggling with how to complex to make the implementation. How about rule:
group:
case:
case::name:
disable: false
case: regex
regex: (?![a-z||0-9]\u005F)(?!.*\u005F[a-z||0-9]$)([a-z||0-9]+(?:\u005F[a-z||0-9]+)*)
suffix_exceptions: [_n,_a,_s,_s1,_s2,_s3,_s4,_s5,_d,_d1,_d2,_d3,_d4,_d5,_p,_p1,_p2,_p3,_p4,_p5,_dp,_dn]
case_exceptions: [IEEE]
user_error_message: "UPPERCASE and single letter prefix/suffix not allowed"
I think I like your idea to put the message in brackets. It helps to indicate to the user that this is something unique. What do think? Regards, --Jeremy |
This would server my purpose well. I agree with having user-defined messages in brackets to separate the message. I like the naming I can see about making a pull request with this change, but I am no Python expert and thought it was better to just come with the suggestion. |
Morning @PelleEikeberg ,
I can implement the solution for this. If you would like to contribute there are still a number of rules that could be implemented. If you are interested, just let me know, I can guide you through the process. Regards, --Jeremy |
Afternoon @PelleEikeberg , I pushed an update for this issue to the Thanks, --Jeremy |
Morning @PelleEikeberg , Just wanted to ping you on this issue to see if you had a chance to check it out. Thanks, --Jeremy |
Evening @PelleEikeberg ,
Awesome.
I will keep this issue open until February 3rd. If I do not hear anything from you I will assume everything is okay and merge to master. Regards, --Jeremy |
Is your feature request related to a problem? Please describe.
I made a VSG yaml ruleset for following some coding conventions I had, and saw that you did not have an option for
snake_case
. This was no issue as I could easily make a regex for solving this. For note: the regex under will not catch single letter prefixes or single letter suffixes, as I have separate rules for these (e.ginstantiation_008: case:lower
instantiation_601: prefixes: [i_]
.Describe the solution you'd like
My request is not about the
snake_case
(although it would be nice), but rather that there is an optional field for custom error message So that I can choose what error is displayed when the rule fails. (exemplified by the "error_msg:" option under). And that this field can be set in the json/yaml file.Describe alternatives you've considered
I guess I could do something like this using Python and/or change the VSG code, but it would be nice to have it as part of the config file.
Additional context
While running through my new rules, I noticed that the rules:
library_500
anduse_clause_500
gives the error:This is not according to the group rules I've set, but they are enabled because of the group (i disabled all rules in
global
). Why they break when they pass the regex is beyond me, but I feel like the error format should be the same as the rest of the error messages set by the regex:Format **** to match defined regex
.If you are to implement the
error_msg
then obviously I want them to follow the same hierarchy rule and be superseded by the lower lever rule (global message is removed and the group is applied if both as present)The text was updated successfully, but these errors were encountered: