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

Fix: Formatters keep trailing '.' if preceded by a space (fixes #9154) #9247

Merged
merged 2 commits into from Sep 9, 2017
Merged

Conversation

i-ron-y
Copy link
Contributor

@i-ron-y i-ron-y commented Sep 7, 2017

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

@eslintbot
Copy link

LGTM

@mention-bot
Copy link

@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.

Copy link
Member

@not-an-aardvark not-an-aardvark left a 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.

@@ -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(/\.$/, ""))}`;
Copy link
Member

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.

@@ -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(/\.$/, ""),
Copy link
Member

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.

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features labels Sep 7, 2017
@i-ron-y
Copy link
Contributor Author

i-ron-y commented Sep 7, 2017

Hmm... I just tried it out and message.message.replace(/[^ ]\.$/, "") seems to be replacing both the character that precedes the full stop and the full stop with "". So "Unexpected foo." becomes "Unexpected fo".

@not-an-aardvark
Copy link
Member

Oops, you're right. I think something like this would work:

message.message.replace(/([^ ])\.$/, "$1")

Alternatively, instead of using .search you could use endsWith:

message.message.endsWith(" .")

@i-ron-y
Copy link
Contributor Author

i-ron-y commented Sep 7, 2017

That regex works perfectly, thank you so much!

Is it okay if I commit again with the sleeker code incorporating your solution?

@not-an-aardvark
Copy link
Member

Sure, fine by me.

@eslintbot
Copy link

LGTM

@not-an-aardvark not-an-aardvark merged commit 51132d6 into eslint:master Sep 9, 2017
@not-an-aardvark
Copy link
Member

Thanks for contributing!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 9, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants