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: Fix or remove code examples that require tabs #17629

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

Change Request: Fix or remove code examples that require tabs #17629

fasttime opened this issue Oct 7, 2023 · 14 comments · Fixed by #17653
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?

Some of our formatting rules have code examples that would have to contain tab characters in order to show the intended behavior. These code examples are currently messed up and it is not possible to fix them because Markdownlint forbids tabs and replaces them automatically with whitespaces in the lint-staged commit hook. The rules affected are at least:

Out of those, indent and indent-legacy are using a mix of whitespaces and comments like /*tab*/ to indicate a position where a tab is expected. max-len and no-tabs are using the sequence \t which is a syntax error outside of literals. no-mixed-spaces-and-tabs has whitespaces with explanatory comments on top. None of these workarounds behaves well in the Playground.

What do you think is the correct solution?

I don't think we want to allow tabs in Markdown files, and the problematic rules are all going to be deprecated (indent-legacy is already), so the simplest approach would be removing the code examples that cannot work because tabs are not available.

Alternatively we could selectively disable the Markdownlint rule that forbids tabs (MD010/no-hard-tabs) for some code examples, so we could put real tabs into them.

Or we could keep the broken code examples, declare them pseudocode, and remove the :::correct/:::incorrect fences. This would remove the "Open in Playground" buttons and exempt the code blocks from validation when we will start to validate code examples.

There are clearly other ways to address this, and there are possibly aspects I haven't considered, so I would like to hear what the team suggests.

Participation

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

Additional comments

No response

@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

Maybe we could represent tabs with something like <TAB> and replace it with real tabs in the code we're passing to the playground?

@fasttime
Copy link
Member Author

fasttime commented Oct 9, 2023

Good idea, but a search for <TAB> finds this:

new RegExp("\t"); // disallowed since the pattern is: <TAB>

So maybe better something like <<TAB>>, [TAB], <HT>, etc. ?

@nzakas
Copy link
Member

nzakas commented Oct 9, 2023

If the concern is just what happens when opened in the playground, we could also add an option that hides the "Open in Playground" button.

@mdjermanovic
Copy link
Member

I think it's good to have a consistent visual presentation of tabs (e.g., <<TAB>>) in our documentation anyways, and with that it looks simple to replace it with real tab characters in the code we're passing to the playground.

@nzakas
Copy link
Member

nzakas commented Oct 10, 2023

Okay, I don't feel strongly about this, so happy to defer to what you're thinking.

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Oct 11, 2023

it is not possible to fix them because Markdownlint forbids tabs and replaces them automatically with whitespaces in the lint-staged commit hook

Err, what about ignoring with <!-- markdownlint-disable --> or similar? https://github.com/DavidAnson/markdownlint#configuration

Edit: just to be clear, this is what @fasttime proposed in the OP 😄 I was confused why it wasn't being considered.

@fasttime
Copy link
Member Author

Err, what about ignoring with <!-- markdownlint-disable --> or similar? https://github.com/DavidAnson/markdownlint#configuration

That's what I had in mind when I suggested to selectively disable MD010/no-hard-tabs for some of the code examples, but there seems to be an argument that <<TAB>> in place of a tab character would provide a more consistent visual presentation?

@fasttime
Copy link
Member Author

Thanks everybody for sharing your ideas. I have drafted a PR to show on different pages how things would look like after each of the suggested solutions, hopefully this will help us to better evaluate the results and take a decision.

Opinions?

@nzakas
Copy link
Member

nzakas commented Oct 16, 2023

Thanks for putting those together! I'm definitely not a fan of the <<TAB>> approach, and it seems like the markdown-disable ones gives us everything we need, so I think that's my favorite.

@mdjermanovic
Copy link
Member

I'm in favor of visible characters as, in my opinion, examples would look better on the docs site, and there would be no problems with formatting markdown files. If <<TAB>> doesn't look good, then maybe a right arrow character. The examples we have with look nice to me.

Though, if others are strongly in favor of <!-- markdownlint-disable -->, I'm fine with that approach too.

@fasttime
Copy link
Member Author

I'm in favor of visible characters as, in my opinion, examples would look better on the docs site, and there would be no problems with formatting markdown files. If <<TAB>> doesn't look good, then maybe a right arrow character. The examples we have with look nice to me.

@mdjermanovic Can you show an example of a line with a right arrow character so I can update the PR?

@nzakas
Copy link
Member

nzakas commented Oct 17, 2023

@mdjermanovic keep in mind that all of the rules where this matters will be deprecated, so I'm less concerned about them than I would otherwise.

@mdjermanovic
Copy link
Member

I'm fine with the <!-- markdownlint-disable --> approach.

Just for reference, I was thinking about something like this:

function add(x, y) {
➝return x + y;
}
Examples with different arrows and horizontal tabulation symbol

image

@fasttime
Copy link
Member Author

It looks like there's agreement on using tab characters with <!-- markdownlint-disable --> comments. I have updated PR #17653 to use this approach. This change will also fix the last syntax errors left in our rule examples.

@fasttime fasttime added the accepted There is consensus among the team that this change meets the criteria for inclusion label Oct 25, 2023
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Apr 24, 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 24, 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.

5 participants
@nzakas @JoshuaKGoldberg @fasttime @mdjermanovic and others