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

chore: add doc-renderer for generating & updating detailed rule docs #442

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

Foxeye-Rinx
Copy link
Contributor

@Foxeye-Rinx Foxeye-Rinx commented Oct 31, 2024

Problems:

  • The new rule document (generated by npm run new) was unclear about which part is the header and which part is the body.

  • In tools/update-docs.ts, when generating notes and adding them to the header section:

    • The process is too much like cutting and pasting manually on the string, it reduces the readability
    • The code for producing the new header (with notes included) is quite fragmented and long
    • Includes legacy/redundant code header.replace(/\$/g, "$$$$")
    • Inefficient and fragmented code, it creates two new items for the notes then join() it with '\n' later to create the trailing '\n\n'
        if (notes.length >= 1) {
          notes.push("", "")
        }
        ...
        const header = `\n${title}\n\n${notes.join("\n")}`

This PR:

  • Create renderRuleHeader function and a RuleDocHeader type to clarify the structure of the header. Then applies this to both the generation and update tools for the detailed rule Markdown files
type RuleDocHeader = {
  ruleId: string
  description: string
  notes: string[]
}
const header = renderRuleHeader({ ruleId, description, notes })
  • Make it clear there are \n\n between each part of the header in the renderRuleHeader function

Overview of this PR with image:

This renderer can be used anywhere to produce the header part of the md(x) files

image

Tested step:

  • I ran npm run update and saw no changes, which is my expectation.

Copy link

changeset-bot bot commented Oct 31, 2024

⚠️ No Changeset found

Latest commit: 0f44c8a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Foxeye-Rinx Foxeye-Rinx changed the title chore: create doc-renderer for generating and updating single rule docs chore: add doc-renderer for generating & updating detailed rule docs Oct 31, 2024
### Problems:

- The new rule document (generated by `npm run new`) was unclear about which part is the header and which part is the body.
       
- In `tools/update-docs.ts`, when generating notes and adding them to the header section:
  - The process is too much like cutting and pasting manually on the string, it reduces the readability
  - The code for producing the new header (with notes included) is quite fragmented and long
  - Includes legacy/redundant code `header.replace(/\$/g, "$$$$")`
  - Inefficient code, it creates two new items for the notes then `join()` it with `'\n'` later to create the trailing `'\n\n'`
  
   ```ts
       if (notes.length >= 1) {
         notes.push("", "")
       }
       ...
       const header = `\n${title}\n\n${notes.join("\n")}`

    ```

### This PR:
  - Create renderRuleHeader function and a RuleDocHeader type to clarify the structure of the header. Then applies this to both the generation and update tools for the detailed rule Markdown files

```ts
type RuleDocHeader = {
  ruleId: string
  description: string
  notes: string[]
}
const header = renderRuleHeader({ ruleId, description, notes })
```
 - Make it clear there are `\n\n` between each part of the header in the `renderRuleHeader` function
Copy link
Owner

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

That's great! Thank you!

@ota-meshi ota-meshi merged commit db90a41 into ota-meshi:main Nov 1, 2024
8 checks passed
@Foxeye-Rinx Foxeye-Rinx deleted the create-doc-header-renderer branch November 1, 2024 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants