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

docs: add playground links to correct and incorrect code blocks #17306

Merged
merged 7 commits into from Jul 14, 2023

Conversation

JoshuaKGoldberg
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg commented Jun 23, 2023

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[x] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

Adds a markdown-it-container render method for :::correct and :::incorrect blocks that adds a playground link. That link is hidden when not focused or hovered.

Is there anything you'd like reviewers to focus on?

@eslint-github-bot eslint-github-bot bot added the documentation Relates to ESLint's documentation label Jun 23, 2023
docs/.eleventy.js Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Jul 3, 2023

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

@github-actions github-actions bot added the Stale label Jul 3, 2023
@Rec0iL99
Copy link
Member

Rec0iL99 commented Jul 4, 2023

Not stale. @mdjermanovic there is a comment for you to look into #17306 (comment). Thanks.

@Rec0iL99 Rec0iL99 removed the Stale label Jul 4, 2023
@mdjermanovic
Copy link
Member

I'll close-reopen to see if that will now generate a preview.

@mdjermanovic mdjermanovic reopened this Jul 6, 2023
@mdjermanovic
Copy link
Member

It didn't trigger a preview. Perhaps it will appear after the next commit.

@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jul 6, 2023
@harish-sethuraman
Copy link
Member

Im guessing its because its still in draft? may be moving out of draft will generate a preview?

@mdjermanovic
Copy link
Member

Im guessing its because its still in draft? may be moving out of draft will generate a preview?

I think it creates previews for drafts, for example: #17053

I'd expect the preview to appear after the next commit, but we'll see.

docs/.eleventy.js Outdated Show resolved Hide resolved
@mdjermanovic
Copy link
Member

As for the visual design, per #17018 (comment) it seems we already have some styles prepared:

// button.classList.add('c-btn--playground');
// button.classList.add('c-btn');
// button.classList.add('c-btn--secondary');

@netlify
Copy link

netlify bot commented Jul 7, 2023

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit 538ec30
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/64aed66ab64cf500080119fa
😎 Deploy Preview https://deploy-preview-17306--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.


@media all and (max-width: 768px) {
display: none;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be an accessibility issue. Users on less-wide screens, such as mobile phones and zoomed-in desktop displays, still would want to be able to access the Open in Playground button.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, I'll have to ask @nzakas what the original intention was.

The Playground is quite good on small screens, but this button is very likely to cover the code:

Screenshot_2023-07-08-16-45-43-843_com android chrome

Though that can happen on wider screens too, depending on the text. Perhaps the button should be below the code block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of moving the button below in mobile screens, yeah. Will wait to implement until directed to 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the intent was that smaller screens (mobile) would probably not want to use the playground as it's a bit clunky without a keyboard.

However, I'm not opposed to moving the button underneath the code block. That seems like a nice compromise to keep the functionality available without disrupting the UI too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super, that's two votes in favor - I had a 💡 moment and moved the button to be half overlapping, half under the code block. That way it takes up much less vertical space and doesn't overlap lines of code.

const { content } = tokens[index + 1];
const state = encodeToBase64(
JSON.stringify({
...(options && { options: JSON.parse(options) }),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this hits what looks like an existing bug in the playground: eslint/eslint.org#450. My intuition is that it'd be better to fix the bug there and allow smaller URLs, rather than backfill in playground-specific default information here.

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review July 7, 2023 18:53
@JoshuaKGoldberg JoshuaKGoldberg requested a review from a team as a code owner July 7, 2023 18:53
@@ -100,7 +100,7 @@ This does not apply to ES modules since the module code is implicitly in `strict

Examples of **incorrect** code for this rule:

::: incorrect
::: incorrect { "parserOptions": { "sourceType": "script" } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can make this configuration as the default value to reduce duplicate definitions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amusingly, right now there are exactly equal amounts of manual "sourceType": "module" as "sourceType": "script".

eslint/docs/src/rules/no-implicit-globals.md
  61,1: ::: correct { "parserOptions": { "sourceType": "script" } }
  82,1: ::: correct { "parserOptions": { "sourceType": "script" } }
  158,1: ::: correct { "parserOptions": { "sourceType": "script" } }
  190,1: ::: correct { "parserOptions": { "sourceType": "script" } }
  242,1: ::: correct { "parserOptions": { "sourceType": "script" } }
  264,1: ::: correct { "parserOptions": { "sourceType": "script" } }

eslint/docs/src/rules/no-restricted-imports.md
  271,1: ::: correct { "parserOptions": { "sourceType": "module" } }
  282,1: ::: correct { "parserOptions": { "sourceType": "module" } }
  294,1: ::: correct { "parserOptions": { "sourceType": "module" } }
  304,1: ::: correct { "parserOptions": { "sourceType": "module" } }
  318,1: ::: correct { "parserOptions": { "sourceType": "module" } }
  331,1: ::: correct { "parserOptions": { "sourceType": "module" } }
  344,1: ::: correct { "parserOptions": { "sourceType": "module" } }

...and a few more incorrects with "module":

eslint/docs/src/rules/no-implicit-globals.md
  47,1: ::: incorrect { "parserOptions": { "sourceType": "script" } }
  103,1: ::: incorrect { "parserOptions": { "sourceType": "script" } }
  130,1: ::: incorrect { "parserOptions": { "sourceType": "script" } }
  174,1: ::: incorrect { "parserOptions": { "sourceType": "script" } }
  224,1: ::: incorrect { "parserOptions": { "sourceType": "script" } }

eslint/docs/src/rules/no-restricted-imports.md
  133,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }
  143,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }
  153,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }
  163,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }
  173,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }
  183,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }
  197,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }
  215,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }
  229,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }
  242,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }
  255,1: ::: incorrect { "parserOptions": { "sourceType": "module" } }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, looking at https://github.com/eslint/eslint.org/pull/451/files#r1257245140, sourceType: "script" is the default in the playground & we can go with that!

docs/.eleventy.js Outdated Show resolved Hide resolved
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for doing this!

The one thing I'd like to change is to remove the blue arrow to the right of "Open in Playground". Because it always appears inside of code blocks with a big red X or big green checkmark, this is creating a visually busy area on the right. I think the button and text alone will suffice.

@nzakas
Copy link
Member

nzakas commented Jul 12, 2023

Some visual stuff:

  1. When there's a horizontal scrollbar the button is very tight against it vertically. Can we add a bit of padding?
  2. Let's remove that arrow icon. :)

Screenshot 2023-07-12 at 12-04-17 no-await-in-loop - ESLint - Pluggable JavaScript Linter

@harish-sethuraman
Copy link
Member

Screenshot 2023-07-12 at 11 50 12 PM

While on mobile this open in playground seems to be very near to the code. Just wanted to confirm on that alone.
Other than that everything else LGTM.

@JoshuaKGoldberg
Copy link
Contributor Author

very near to the code

Yeah. I was torn on this - on the one hand, I didn't want to (nearly/slightly) overlap the code. But on the other hand, I didn't want to add extra vertical space below the code block that increased the overall height of the page...

Copy link
Member

@harish-sethuraman harish-sethuraman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

note: move eslint/eslint.org#451 to prod before this

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty good overall. I think we may want to tweak it further for mobile browsers, but this is a good first step that we can iterate on in the future.

@nzakas nzakas merged commit 89f3225 into eslint:main Jul 14, 2023
22 checks passed
@nzakas
Copy link
Member

nzakas commented Jul 14, 2023

Thanks @JoshuaKGoldberg for doing this and sorting through the playground issues.

@JoshuaKGoldberg JoshuaKGoldberg deleted the docs-rules-open-in-playground branch July 14, 2023 15:40
bmish added a commit to bmish/eslint that referenced this pull request Jul 23, 2023
* main: (101 commits)
  docs: Migrating `eslint-env` configuration comments (eslint#17390)
  Merge pull request from GHSA-qwh7-v8hg-w8rh
  feat: adds option for allowing empty object patterns as parameter (eslint#17365)
  fix: FlatESLint#getRulesMetaForResults shouldn't throw on unknown rules (eslint#17393)
  docs: fix Ignoring Files section in config migration guide (eslint#17392)
  docs: Update README
  feat: Improve config error messages (eslint#17385)
  fix: Update no-loop-func to not overlap with no-undef (eslint#17358)
  docs: Update README
  docs: Update README
  8.45.0
  Build: changelog update for 8.45.0
  chore: package.json update for @eslint/js release
  docs: add playground links to correct and incorrect code blocks (eslint#17306)
  docs: Expand rule option schema docs (eslint#17198)
  docs: Config Migration Guide (eslint#17230)
  docs: Update README
  fix: Fix suggestion message in `no-useless-escape` (eslint#17339)
  docs: Update README
  chore: update eslint-config-eslint exports (eslint#17336)
  ...
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jan 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 Jan 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants