-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Fix: Formatters keep trailing '.' if preceded by a space (fixes #9154) #9247
Conversation
LGTM |
@i-ron-y, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vitorbal, @sindresorhus and @not-an-aardvark to be potential reviewers. |
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.
Thanks for the PR! This looks good to me aside from a small nitpick.
lib/formatters/codeframe.js
Outdated
@@ -47,7 +47,7 @@ function formatFilePath(filePath, line, column) { | |||
*/ | |||
function formatMessage(message, parentResult) { | |||
const type = (message.fatal || message.severity === 2) ? chalk.red("error") : chalk.yellow("warning"); | |||
const msg = `${chalk.bold(message.message.replace(/\.$/, ""))}`; | |||
const msg = message.message.search(/ \.$/) >= 0 ? `${chalk.bold(message.message)}` : `${chalk.bold(message.message.replace(/\.$/, ""))}`; |
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.
Nitpick: I think it would be simpler to do something like
const msg = chalk.bold(message.message.replace(/[^ ]\.$/, "");
rather than using a ternary expression and another regex.
lib/formatters/stylish.js
Outdated
@@ -65,7 +65,7 @@ module.exports = function(results) { | |||
message.line || 0, | |||
message.column || 0, | |||
messageType, | |||
message.message.replace(/\.$/, ""), | |||
message.message.search(/ \.$/) >= 0 ? message.message : message.message.replace(/\.$/, ""), |
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.
Nitpick: I think it would be simpler to do something like
message.message.replace(/[^ ]\.$/, "")
rather than using a ternary expression and another regex.
Hmm... I just tried it out and |
Oops, you're right. I think something like this would work: message.message.replace(/([^ ])\.$/, "$1") Alternatively, instead of using message.message.endsWith(" .") |
That regex works perfectly, thank you so much! Is it okay if I commit again with the sleeker code incorporating your solution? |
Sure, fine by me. |
LGTM |
Thanks for contributing! |
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[X] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
For codeframe.js and stylish.js, I checked if the reported messages end with a " ." - if they do, the " ." is kept in the output. For "."s that aren't preceded by a space, the "." is removed in the output (how all "."s were handled by codeframe.js and stylish.js originally). I also added tests for the new behaviour.
Is there anything you'd like reviewers to focus on?
N/A