-
Notifications
You must be signed in to change notification settings - Fork 421
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 a warning for invalid string sequences #694
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
warn/warn_operation.go
Outdated
var problems []int // positions of the problems | ||
|
||
escaped := false | ||
// This for-loop doesn't correclty check for a backlash at the end of the string literal, but |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
} | ||
|
||
switch ch { | ||
case '\n', '\\', 'n', 'r', 't', 'x', '\'', '"', '0', '1', '2', '3', '4', '5', '6', '7': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the list come from?
Can you include a link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
warn/warn_operation.go
Outdated
|
||
var msg string | ||
if len(problems) == 1 { | ||
msg = fmt.Sprintf("Invalid quote sequences at position %d.", problems[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users might be confused by the message. Include at least the character that's incorrectly escaped.
Suggested:
Invalid quote sequence '\w' at position 18.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
warn/warn_operation.go
Outdated
} else { | ||
msg = fmt.Sprintf( | ||
"Invalid quote sequences at positions %s.", | ||
strings.Trim(strings.Join(strings.Fields(fmt.Sprint(problems)), ", "), "[]"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested:
Invalid quote sequences:
'\w' at position 18
'\z' at position 23
or:
Invalid quote sequences '\w', '\z' at positions 18, 23
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (multiline warnings).
Fixes #688.