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

Change Request: Remove bogus newline at the end of code in rule examples #17627

Closed
1 task done
fasttime opened this issue Oct 7, 2023 · 3 comments · Fixed by #17641
Closed
1 task done

Change Request: Remove bogus newline at the end of code in rule examples #17627

fasttime opened this issue Oct 7, 2023 · 3 comments · Fixed by #17641
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 documentation Relates to ESLint's documentation enhancement This change enhances an existing feature of ESLint

Comments

@fasttime
Copy link
Member

fasttime commented Oct 7, 2023

ESLint version

v8.51.0

What problem do you want to solve?

I haven't been able to create an incorrect code example for the rule eol-last or for the rule no-multiple-empty-lines with option "maxEOF": 0 because the Playground links generated by Eleventy always append a newline at the end of the text.

For visual clarity, this markdown code block does not include a visible trailing empty line.

image

I can copy its content from the rendered page in the browser, and pasting into an empty editor again confirms that there is no trailing line break. By contrast, the code of the Playground link in the rule docs, includes an additional empty line at the end.

image

What do you think is the correct solution?

There should be no extra newline at the end of the code in Playground links.

Participation

  • I am willing to submit a pull request for this change.

Additional comments

The rules eol-last and no-multiple-empty-lines are scheduled for deprecation in v9 per #17522, so fixing the code examples for those rules is arguably not very important, but I would still recommend removing the trailing newline from all code examples for correctness and consistency.

@fasttime fasttime added enhancement This change enhances an existing feature of ESLint core Relates to ESLint's core APIs and features documentation Relates to ESLint's documentation and removed core Relates to ESLint's core APIs and features labels Oct 7, 2023
@mdjermanovic
Copy link
Member

Technically, there is a newline character in the last line of code in code blocks, but it's necessary before the closing ``` and is therefore usually not considered as part of the code. We're indeed currently passing that newline character to the playground, and then the playground renders an extra empty line like most editors do.

There should be no extra newline at the end of the code in Playground links.

I think it's fine to remove it from the code we're passing to the playground 👍

Just not sure how it was causing problems for no-multiple-empty-lines?

@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label Oct 8, 2023
@fasttime
Copy link
Member Author

fasttime commented Oct 9, 2023

Just not sure how it was causing problems for no-multiple-empty-lines?

Sorry for not being very clear. The problem I with no-multiple-empty-lines is that it is currently not possible to create an example that looks in the Playground the same as in the browser due to the appended newline. Quoting the docs:

There is no empty line at the end of a file after the last \n, although editors may show an additional line. A true additional line would be represented by \n\n.

According to that description, a correct example with "maxEOF": 0 could be maybe:

/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/

var foo = 1;

But that would show up in the Playground with two empty lines at the end and report an error. Clearly, we could remove the last newline to get something that works in the Playground, but that feels to me more like a workaround than a correct example, and it would still look different when viewed in the browser.

BTW GitHub itself is trimming the last (two?) newlines from JavaScript Markdown blocks (tagged js, javascript, etc.), but only visually. The newlines are still there when copy-pasting. This should not be an issue for the generated docs pages or the playground.

@mdjermanovic
Copy link
Member

The problem I with no-multiple-empty-lines is that it is currently not possible to create an example that looks in the Playground the same as in the browser due to the appended newline.

I agree, for this rule especially it's confusing that the example in the playground doesn't look the same as in the documentation, although both zero and one trailing \n are valid for "maxEOF": 0.

Looks like the best solution is to remove the trailing \n from the content.

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Apr 11, 2024
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 11, 2024
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 documentation Relates to ESLint's documentation enhancement This change enhances an existing feature of ESLint
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants
@fasttime @mdjermanovic and others