Skip to content

docs: use custom diff code blocks #5099

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

Merged
merged 8 commits into from
Jun 10, 2022

Conversation

Josh-Cena
Copy link
Member

@Josh-Cena Josh-Cena commented May 30, 2022

PR Checklist

Overview

The diff makes the code not directly copyable, which is not something you want for tutorial examples.

See related discussions at:

@nx-cloud
Copy link

nx-cloud bot commented May 30, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit ff80b53. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 47 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @Josh-Cena!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@netlify
Copy link

netlify bot commented May 30, 2022

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit ff80b53
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6295cd520581c60009c95108
😎 Deploy Preview https://deploy-preview-5099--typescript-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 settings.

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

Is this something we can build a docusaurus plugin for? To add the +/- in via css so the content is copyable?

I personally like diffs as it clearly shows what changes should be made which helps tell the story of how to configure things, IMO

@Josh-Cena
Copy link
Member Author

Josh-Cena commented May 30, 2022

We can, absolutely. but it would still mean showing two competing lines and when users copy, they have to delete the "-" line. Using highlighted lines makes it quite clear as well.

@Josh-Cena
Copy link
Member Author

I don't know what's going on with the Netlify preview, though—it's not showing the latest content😕

@armano2
Copy link
Collaborator

armano2 commented May 30, 2022

I personally like diffs as it clearly shows what changes should be made which helps tell the story of how to configure things

i do agree with that, if we want to make file copyable, maybe user-select: none; could be used instead? for + and -

https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/website/src/css/prism.css

.token.prefix {
    user-select: none;
}

@codecov
Copy link

codecov bot commented May 30, 2022

Codecov Report

Merging #5099 (ff80b53) into main (c9c0569) will decrease coverage by 0.38%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #5099      +/-   ##
==========================================
- Coverage   91.70%   91.32%   -0.39%     
==========================================
  Files         362      132     -230     
  Lines       12181     1487   -10694     
  Branches     3530      224    -3306     
==========================================
- Hits        11171     1358    -9813     
+ Misses        661       65     -596     
+ Partials      349       64     -285     
Flag Coverage Δ
unittest 91.32% <ø> (-0.39%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...plugin-internal/src/rules/prefer-ast-types-enum.ts
packages/utils/src/eslint-utils/RuleTester.ts
...es/eslint-plugin/src/rules/no-floating-promises.ts
...s/utils/src/ast-utils/eslint-utils/astUtilities.ts
packages/utils/src/ts-eslint-scope/Referencer.ts
...int-plugin/src/rules/strict-boolean-expressions.ts
packages/type-utils/src/getDeclaration.ts
packages/utils/src/ts-eslint-scope/ScopeManager.ts
...ckages/eslint-plugin/src/rules/no-throw-literal.ts
packages/type-utils/src/typeFlagUtils.ts
... and 220 more

@bradzacher bradzacher added package: website Issues related to the @typescript-eslint website documentation Documentation ("docs") that needs adding/updating and removed package: website Issues related to the @typescript-eslint website labels May 30, 2022
@bradzacher
Copy link
Member

https://jsfiddle.net/fp2jrnmv/
Just to show a quick-and-dirty POC of this working in a fiddle.
There is one small issue - we can't prevent copying empty newlines[1] - but it's otherwise perfect.

[1] copying the above example yields:

  module.exports = {
    root: true,
    parser: '@typescript-eslint/parser',
    plugins: [
      '@typescript-eslint',
    ],
    extends: [


     'airbnb-typescript',
    ],
  };

Another option (or an additional option) could be to use JS to add a copy button which completely deletes the deleted lines from the copied contents.

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label May 30, 2022
@armano2
Copy link
Collaborator

armano2 commented May 30, 2022

There is one small issue - we can't prevent copying empty newlines[1]

.language-diff .token-line > .prefix, /* you want to remove all prefixes, as non modifed lines have extra space */
.language-diff .token-line > .deleted, /* remove deleted elements */
.language-diff .token-line > .deleted + br { /* remove new line after deleted elements */
  user-select: none;
}

@bradzacher
Copy link
Member

@armano2 - ah I missed the brs!

The result of the copy paste with armano's updated css

https://jsfiddle.net/fmt0h31z/

  module.exports = {
    root: true,
    parser: '@typescript-eslint/parser',
    plugins: [
      '@typescript-eslint',
    ],
    extends: [
     'airbnb-typescript',
    ],
  }

This is exactly what we want - you can copy paste the true snipped AND we get to show the changes to tell a story.
I love it!

@Josh-Cena
Copy link
Member Author

Josh-Cena commented May 31, 2022

Great, I'll implement this and you can see the effect (hopefully—if the deploy preview updates)

Also, what do we do about the copy button? Should we hide it entirely, or do you want it to have custom behavior as well?

@Josh-Cena Josh-Cena requested a review from bradzacher May 31, 2022 06:55
@bradzacher
Copy link
Member

Also, what do we do about the copy button? Should we hide it entirely, or do you want it to have custom behavior as well?

If it's not too difficult - having it do the same thing (copy the "intended" code) would be great!
Otherwise I'm happy for it to be hidden if it's too hard to customise.

Comment on lines +142 to +158
magicComments: [
{
className: 'theme-code-block-highlighted-line',
line: 'highlight-next-line',
block: { start: 'highlight-start', end: 'highlight-end' },
},
{
className: 'code-block-removed-line',
line: 'Remove this line',
block: { start: 'Removed lines start', end: 'Removed lines end' },
},
{
className: 'code-block-added-line',
line: 'Add this line',
block: { start: 'Added lines start', end: 'Added lines end' },
},
],
Copy link
Member Author

Choose a reason for hiding this comment

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

New Docusaurus feature to add custom metadata to lines—suits this use-case quite well.

I prefer using human-readable identifiers like "Remove this line", but if you want something that stands out more like for machines (e.g. "remove-next-line") just let me know

@Josh-Cena
Copy link
Member Author

Josh-Cena commented May 31, 2022

Ahhh... Customizing the copy button, even hiding it, is a bit hard at this stage. This would need some refactors in Docusaurus, but I'm not sure how. I hope the current solution is good enough.

@Josh-Cena
Copy link
Member Author

Current UI/UX is quite good IMO. We have syntax highlighting which is missed in diff code blocks. It's also more obvious that the +/- are non-text tokens because they are shifted left.

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

Whilst I would love if we could just use diff cos it's concise - i think the syntax highlighting we get from using js is better and paired with the new UX is well worth it.

keanubeautiful

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Jun 10, 2022
@bradzacher bradzacher changed the title docs: avoid using diff code blocks docs: use custom diff code blocks Jun 10, 2022
@bradzacher bradzacher merged commit 331ff3b into typescript-eslint:main Jun 10, 2022
@Josh-Cena Josh-Cena deleted the avoid-diff branch June 10, 2022 04:19
@Josh-Cena
Copy link
Member Author

Josh-Cena commented Jun 10, 2022

Cross-posting from facebook/react-native-website#2984 — we'll probably consider making this the default behavior in Docusaurus.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation ("docs") that needs adding/updating
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants