-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
test(theme-common): Add tests for getLineNumbersStart #11017
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
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
4fb89c4
to
4a357c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but please use functional style code like before, and don't mutate function inputs
4a357c6
to
9e842ae
Compare
I decided to revert my code changes. Looking at the remarks you rather prefer to stay on the old function implementation as it was. While your arguments might be valid, I'm not sure if I can invest so much time in satisfying all your wishes on code style, hence I'm rather removing changes not focusing on the direct goal of the new feature. |
Some revert was not strictly needed, I'm fine if we extract option/return types for example
No I think it's fine to split the logic in 2 parts as you did, but useless side effects like this are a common anti-pattern I'd like to avoid. Functions should be self-encapsulated. I'll see if I can add an eslint to forbid this style by default.
As you want, I can as well refactor it myself. External contributor PRs also take time to review, and often it's faster if you tell me what you want exactly, and I implement it myself. Only invest time if you care about contributing (and agree to meet project standards to do so), and/or want to be progressively onboarded as a regular contributor. |
Considering the motivation and focus of my PRs it somehow has become out-of-scope for me. Also the added value is fairly limited as the related types are purely for internal use. So I went the simple path here of reverting it fully. If its really a valueable change for the project it could become an own PR though.
I personally do not fully agree on this statement, but only as it might be a bit over-generalizing. Not every function on every level has to be pure, I'd rather consider that a anti-pattern as it should be a proper case-by-case decision. In this specific scenario:
Of course it might be possible to refactor things even further here to have only pure functions even for the sub-parts of the exposed function. For my planned contribution its simply out of scope to invest so much energy in refactoring those (fairly insignificant) bits as they do not contribute to the motivation and goals of the PR-series. 😉
The commit hashes are still linked in the PR history and AFAIK GitHub will not clean them. Feel free to cherry-pick any changes in this area into a new PR 😁
Sure it takes time, and external contributors have to take higher hurdles than direct team members. External contributors have to take typically higher hurdles than core members and that's not bad in itself. At the end of the day the maintainers have to live with the code they pull in and maintain it further so it's only natural to have some higher expectations. Many good articles exist around the matter of healthy code reviews and why they are hard to do, and there is no "correct" way. 😁 I have no hard feelings in reworking or reverting changes until some extend. On my general needs things might get a bit clearer across the PRs, but talking in "solution space" and not in "requirements":
|
Thanks I guess we won't easily agree on everything, but I can probably refactor things in a way I want that matches your goal Will look at this later, but we can already merge this PR |
Going to close the current PRs as I did refactor and made the whole CodeBlock thing easier to swizzle and customize. See:
You can use this hook anywhere in the code block tree to get useful data/apis: import {useCodeBlockContext} from '@docusaurus/theme-common/internal';
const {metadata, wordWrap} = useCodeBlockContext() I'll refactor the live code block next week |
The Live Code Block component is being refactored here: #11077 It is being split into many smaller components, easier to swizzle and customize. The original and live code blocks components have not much in common so to me it didn't really make sense to build an abstraction over both. The metastring of one is totally different from the metastring of the other, so I don't think it makes sense to use a shared type for both for example. For now the live code block keeps metastring parsing as is. We only need I'll see later how to eventually parse the metastring with a remark plugin once we have better global markdown plugin lifecycles (related to #5999) |
Pre-flight checklist
Motivation
This PR is part of a series related to #11008 and it superceeds #11011 in the goal to splitup the work into more isolated refactoring/feature parts.
Step 1 (this PR): Splitup current parseLines logic
Step 2 (#11019): Parse metastring into metaOptions and use it across components.
Step 3 (#11021): Add parsing of any options specified in the metastring.
Step 4 (#11022): Add CodeBlockToken component to customize DOM of highlighted tokens.
Step 5 (#11023): Pass
metaOptions
to whole codeblock component tree.The motivation of this part
iswas to prepare the codebase for the upcoming extensions and adaptions. Initially step 2 had the parsing added toparseLines
so splitting things up and defining types was a good preparation for extension.With the final version of all changes,
parseLines
is not used for this purpose. I still kept this PR for two purposes:Test Plan
The code change aims to have 0 functional impact and is therefore covered by the current unit/integration tests. These tests are green.
Manual testing by checking
/docs/markdown-features/code-blocks
showed no impact of the change.Additional tests for
getLineNumbersStart
were added to avoid regression bugs in upcoming PRs. more tests likely come in every step.Test links
Deploy preview: https://deploy-preview-11017--docusaurus-2.netlify.app
Code Blocks: https://deploy-preview-11017--docusaurus-2.netlify.app/docs/markdown-features/code-blocks/
Related issues/PRs