GithubHelp home page GithubHelp logo

bmish / eslint-doc-generator Goto Github PK

View Code? Open in Web Editor NEW
89.0 89.0 4.0 2.82 MB

Automatic documentation generator for ESLint plugins and rules.

JavaScript 1.04% TypeScript 98.96%
documentation eslint eslint-plugin generator javascript lint linter linting typescript

eslint-doc-generator's People

Contributors

bmish avatar ddzz avatar dependabot[bot] avatar g-rath avatar hyoban avatar joshuakgoldberg avatar michaeldeboey avatar simenb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

eslint-doc-generator's Issues

Link to config section of README in rule notices

[MESSAGE_TYPE.CONFIGS]: `${EMOJI_CONFIGS} This rule is enabled in the following configs:`, // TODO: include link to configs in the plugin's README.

Might need an option to specify this URL.

Example current:

๐Ÿ’ผ This rule is enabled in the following configs: all, recommended.

Example desired:

๐Ÿ’ผ This rule is enabled in the following configs: all, recommended.

Option:

  • --url-configs https://github.com/ember-cli/eslint-plugin-ember#-configurations

Option to disable options section check

By default, we check for a ## Options or ## Config section that mentions all the named options of a rule.

We could make this configurable through an option like:

Option Desc
--rule-doc-section-options (default true) Whether to check for a rule doc ## Options or ## Config section and any named options when a rule has options.

Add options for non-standard paths for README.md or rule doc files

Might need a config option to specify the path to these if non-standard:

Standard paths:

  • README.md
  • docs/rules/[rule-name].md

Override options:

  • --path-readme
  • --path-rule-doc

Also considered:

  • --rule-doc-path for grouping with existing rule doc options
  • --rule-list-path for grouping with existing rule list options

Leaky unit test is modifying the README

Each of our tests sets up a mock filesystem using mock-fs in beforeEach() and then tears it down with mockFs.restore(); in afterEach(). This way, the tests can see the desired files, modify, and test them without affecting the actual filesystem.

For some reason, there seems to be a leak from the tests to the actual filesystem. The doc generator is inserting a rules list into README.md in between the marker comments.

<!-- begin rules list -->
<!-- end rules list -->

It's easy to accidentally check this change in. We need to figure out how to avoid this leak.

Configurable allowed or disallowed sections enforcement

We currently only check for an ## Options section. Some users may also want to check for other sections like:

  • ## Examples
  • ## Rule details

Or even disallow certain sections.

This helps enforce documentation consistency.

We could have an option like:

  • --rule-doc-section-include
  • --rule-doc-section-exclude

Handle configs that extend other configs

module.exports = {
  extends: [require.resolve('./other-config')],
};

This causes a crash right now:

$ eslint-doc-generator
eslint-doc-generator/dist/lib/configs.js:15
        const value = config.rules[`${pluginPrefix}/${ruleName}`];
                                  ^

TypeError: Cannot read properties of undefined (reading 'test/no-foo')
    at getConfigsForRule (eslint-doc-generator/dist/lib/configs.js:15:35)
    at getRuleNoticeLines (eslint-doc-generator/dist/lib/rule-notices.js:47:28)
    at generateRuleHeaderLines (eslint-doc-generator/dist/lib/rule-notices.js:93:12)
    at generate (eslint-doc-generator/dist/lib/generator.js:62:32)
    at async Command.<anonymous> (eslint-doc-generator/dist/lib/cli.js:21:9)
error Command failed with exit code 1.

And the extended config needs to be resolved. Maybe ESLint has an API to do this for us.

Include rule name prefix in rule doc title

Before

# Do not use `foo` (`no-foo`)

After

# Do not use `foo` (`test/no-foo`)

Where the plugin is called eslint-plugin-test.

This avoids a potential hiccup since users will need to use the prefix to refer to the rule in their own codebases.

Automatically generate configs list in README

Automatically generate a table/list of configs in the README ## Configs section.

Not sure about this yet. We have the list of configs but we don't know the config descriptions. We do know the config emojis/badges if the user has specified them.

Optional columns:

  • Number of rules enabled, warn, or disabled in each config

Related: #20.

Potential issue with importing Windows paths

Node 16 Windows CI is failing attempting to add this tool to an eslint plugin in square/eslint-plugin-square#764.

node:internal/errors:477
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
    at new NodeError (node:internal/errors:387:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1116:11)
    at defaultResolve (node:internal/modules/esm/resolve:1196:3)
    at nextResolve (node:internal/modules/esm/loader:165:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:844:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:431:18)
    at ESMLoader.import (node:internal/modules/esm/loader:528:22)
    at importModuleDynamically (node:internal/modules/esm/translators:110:35)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:[14](https://github.com/square/eslint-plugin-square/actions/runs/3170797584/jobs/5163651883#step:5:15))
    at loadPlugin (file:///D:/a/eslint-plugin-square/eslint-plugin-square/node_modules/eslint-doc-generator/dist/lib/package-json.js:[20](https://github.com/square/eslint-plugin-square/actions/runs/3170797584/jobs/5163651883#step:5:21):33) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
error Command failed with exit code 1.

https://github.com/square/eslint-plugin-square/actions/runs/3170797584/jobs/5163651883

Split tests file

All our tests our in the massive generate-test.ts test file. Sticking to acceptance tests and avoiding most unit tests has been helpful as it has allowed quicker refactoring of functions without having to update a ton of unit tests. But we should split this giant acceptance test file into multiple files based on category of test.

Auto-generate a badge for each config

So the user doesn't have to do it themselves unless they want to.

If an emoji isn't specified for a config, and we don't see a badge for it in the README, automatically add one to the bottom of the README.

Custom config emojis

Allow specifying the emoji to represent each config.

Examples of config option:

--config-emoji "recommended,โœ…" (default)
--config-emoji "stylistic,๐ŸŽจ"

Add option to create missing rule docs

--init-rule-docs to create any missing rule docs.

Fail if there are no rule docs to create so this option isn't left in place indefinitely.

This would only be useful for someone who hasn't created any docs for their rules yet. In that scenario, this would help save time in getting started with documentation.

The reason we need an explicit option for this (and we don't want to automatically create missing rule docs by default) is because the rule docs might live at a non-standard path and we just didn't detect them. If the plugin has a non-standard rule doc path, the user just needs to specify --path-rule-doc.

Follow-up to #78.

[BUG] Prettier not found

Apparently the library expects that i installed prettier in my project.

node:internal/errors:465
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'prettier' imported from ...\node_modules\.pnpm\[email protected]_ypn2ylkkyfa5i233caldtndbqa\node_modules\eslint-doc-generator\dist\lib\markdown.js
    at new NodeError (node:internal/errors:372:5)
    at packageResolve (node:internal/modules/esm/resolve:954:9)
    at moduleResolve (node:internal/modules/esm/resolve:1003:20)
    at defaultResolve (node:internal/modules/esm/resolve:1218:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
โ€‰ELIFECYCLEโ€‰ Command failed with exit code 1.

EXPECTED RESULT:
shouldn't crash if prettier isn't my project.

ACTUAL RESULT:
crash if prettier isn't my project.

ENVIROMENT:
Windows 10
Node 16

Only use prettier to format affected doc content

Not everyone wants to format their docs with prettier. It also creates a big diff when running this tool. By default, we should only use prettier to format the doc sections this tool manages. We could have an option (default off) to use it to format the entire affected docs.

Configurable rule doc title format

We currently use the following rule doc title format:

# Do not use foo (`test/no-foo`)

We should also support another format with just the rule name without description which is also a common format in plugins:

# no-foo

Not sure which should be the default yet.

  • --rule-doc-title-format desc-parens-prefix-name (default): # Do not use foo (test/no-foo)
  • --rule-doc-title-format desc-parens-name: # Do not use foo (no-foo)
  • --rule-doc-title-format prefix-name: # test/no-foo
  • --rule-doc-title-format name: # no-foo

More robust detection of README rules section

Right now, we only detect a ## Rules section when looking for where to insert the rules list into the README when the marker comments are missing. While this is the most common section name, we should detect additional variations:

  • ## ๐ŸŸ Rules (eslint-plugin-ember)
  • ## Custom rules (eslint-plugin-square)
  • ## List of supported rules (eslint-plugin-react)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.