Skip to content

handle "Resources" section #808

@Zamiell

Description

@Zamiell

It appears that ESLint and TSESLint use an identical format, with the small exception of ESLint using "Tests" and TSESLint using "Test".

In any case, I think that this establishes that having a "Resources" section in your rule documentation is considered best practice. Thus, I propose that this doc generator should automatically create a section in the same format.

Other Solutions Considered

Right now, I use eslint-doc-generator to append a resources section at the end using a postprocess function like this:

/**
 * Add a "Resources" section as the final section.
 *
 * @param content {string}
 * @param pathToFile {string}
 * @returns {string}
 */
function getContentWithResourcesSection(content, pathToFile) {
  const ruleName = pathToFile.split(path.sep).pop().replace(".md", "");

  const resourcesSection = `## Resources

- [Rule source](https://github.com/complete-ts/complete/blob/main/packages/eslint-plugin-complete/src/rules/${ruleName}.ts)
- [Test source](https://github.com/complete-ts/complete/blob/main/packages/eslint-plugin-complete/tests/rules/${ruleName}.test.ts)
`;

  const resourcesIndex = content.indexOf("## Resources");
  if (resourcesIndex !== -1) {
    content = content.slice(0, resourcesIndex);
  }

  return `${content.trim()}\n\n${resourcesSection}`;
}

However, this is quite verbose, and I think this should just be handled automatically by eslint-doc-generator itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions