diff --git a/lib/generator.ts b/lib/generator.ts index 633daaf7..66a6176e 100644 --- a/lib/generator.ts +++ b/lib/generator.ts @@ -173,8 +173,10 @@ export async function generate(path: string, options?: GenerateOptions) { ? { // Deprecated function-style rule don't support most of the properties that object-style rules support, so we'll just use the bare minimum. meta: { - schema: [], // TODO: figure out how to access `schema` property that can be exported from function-style rules: https://github.com/bmish/eslint-doc-generator/issues/71 - deprecated: false, // TODO: figure out how to access `deprecated` property that can be exported from function-style rules: https://github.com/bmish/eslint-doc-generator/issues/71 + // @ts-expect-error -- type is missing for this property + schema: ruleModule.schema, // eslint-disable-line @typescript-eslint/no-unsafe-assignment -- type is missing for this property + // @ts-expect-error -- type is missing for this property + deprecated: ruleModule.deprecated, // eslint-disable-line @typescript-eslint/no-unsafe-assignment -- type is missing for this property }, create: ruleModule, } diff --git a/test/lib/generate/__snapshots__/rule-metadata-test.ts.snap b/test/lib/generate/__snapshots__/rule-metadata-test.ts.snap index 852799b4..3b9e4d9a 100644 --- a/test/lib/generate/__snapshots__/rule-metadata-test.ts.snap +++ b/test/lib/generate/__snapshots__/rule-metadata-test.ts.snap @@ -22,6 +22,29 @@ exports[`generate (rule metadata) deprecated function-style rule generates the d " `; +exports[`generate (rule metadata) deprecated function-style rule with deprecated/schema properties generates the documentation 1`] = ` +"## Rules + + +❌ Deprecated.\\ +⚙️ Has configuration options. + +| Name | ❌ | ⚙️ | +| :----------------------------- | :- | :- | +| [no-foo](docs/rules/no-foo.md) | ❌ | ⚙️ | + + +" +`; + +exports[`generate (rule metadata) deprecated function-style rule with deprecated/schema properties generates the documentation 2`] = ` +"# test/no-foo + + +## Options +optionToDoSomething" +`; + exports[`generate (rule metadata) rule with no meta object generates the documentation 1`] = ` "## Rules diff --git a/test/lib/generate/rule-metadata-test.ts b/test/lib/generate/rule-metadata-test.ts index c306b14c..484c8501 100644 --- a/test/lib/generate/rule-metadata-test.ts +++ b/test/lib/generate/rule-metadata-test.ts @@ -54,6 +54,60 @@ describe('generate (rule metadata)', function () { }); }); + describe('deprecated function-style rule with deprecated/schema properties', function () { + beforeEach(function () { + mockFs({ + 'package.json': JSON.stringify({ + name: 'eslint-plugin-test', + exports: 'index.js', + type: 'module', + }), + + 'index.js': ` + const noFoo = function create () {}; + noFoo.deprecated = true; + noFoo.schema = [ + { + type: 'object', + properties: { + optionToDoSomething: { + type: 'boolean', + default: false, + }, + }, + additionalProperties: false, + }, + ]; + export default { + rules: { + 'no-foo': noFoo + }, + };`, + + 'README.md': '## Rules\n', + + 'docs/rules/no-foo.md': '## Options\noptionToDoSomething', + + // Needed for some of the test infrastructure to work. + node_modules: mockFs.load(PATH_NODE_MODULES), + }); + }); + + afterEach(function () { + mockFs.restore(); + jest.resetModules(); + }); + + it('generates the documentation', async function () { + await generate('.', { + // Ensure the relevant properties are shown for the test. + ruleListColumns: ['name', 'deprecated', 'options'], + }); + expect(readFileSync('README.md', 'utf8')).toMatchSnapshot(); + expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot(); + }); + }); + describe('rule with no meta object', function () { beforeEach(function () { mockFs({