diff --git a/.gitignore b/.gitignore index 861f3e6..ea98f23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ node_modules dist -*ignoreme* +**ignoreme* coverage # ignore non-pnpm lockfiles package-lock.json yarn.lock + +*.tgz diff --git a/README.md b/README.md index 1981941..89e2bcb 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,14 @@ Here's an example of it being used along with VSCode's eslint plugin, with auto- - [Setup](#setup) - [Usage with eslint-plugin-markdown](#usage-with-eslint-plugin-markdown) - [Presets](#presets) - - [monorepoTOC](#monorepotoc) - [barrel](#barrel) + - [custom](#custom) - [markdownFromJsdoc](#markdownfromjsdoc) + - [monorepoTOC](#monorepotoc) + - [markdownFromJsdoc](#markdownfromjsdoc-1) - [markdownTOC](#markdowntoc) - [markdownFromTests](#markdownfromtests) - [labeler](#labeler) - - [custom](#custom) - [Customisation](#customisation) @@ -140,33 +141,6 @@ module.exports = { ``` ### Presets - - -#### [monorepoTOC](./src/presets/monorepo-toc.ts#L30) - -Generate a table of contents for a monorepo. - -##### Example (basic) - -`` - -##### Example (using config options) - -`` - -##### Params - -|name |description | -|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -|repoRoot|[optional] the relative path to the root of the git repository. By default, searches parent directories for a package.json to find the "root". | -|filter |[optional] a dictionary of filter rules to whitelist packages. Filters can be applied based on package.json keys,
e.g. `filter: { package.name: someRegex, path: some/relative/path }`| -|sort |[optional] sort based on package properties (see `filter`), or readme length. Use `-` as a prefix to sort descending.
e.g. `sort: -readme.length` | - - -##### Demo - -![](./gifs/monorepoTOC.gif) - #### [barrel](./src/presets/barrel.ts#L38) @@ -197,6 +171,36 @@ export * from './some/path/module-c' ![](./gifs/barrel.gif) + +#### [custom](./src/presets/custom.ts#L32) + +Define your own codegen function, which will receive all options specified. Import the `Preset` type from this library to define a strongly-typed preset function: + +##### Example + +```typescript +import {Preset} from 'eslint-plugin-codegen' + +export const jsonPrinter: Preset<{myCustomProp: string}> = ({meta, options}) => { + const components = meta.glob('**\/*.tsx') // uses 'globSync' from glob package + return `filename: ${meta.filename}\ncustom prop: ${options.myCustomProp}\nComponent paths: ${components.join(', ')}` +} +``` + +This can be used with: + +` + #### [markdownFromJsdoc](./src/presets/markdown-from-jsdoc.ts#L17) @@ -214,6 +218,48 @@ Convert jsdoc for an es export from a javascript/typescript file to markdown. |export|{string} the name of the export | + +#### [monorepoTOC](./src/presets/monorepo-toc.ts#L30) + +Generate a table of contents for a monorepo. + +##### Example (basic) + +`` + +##### Example (using config options) + +`` + +##### Params + +|name |description | +|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +|repoRoot|[optional] the relative path to the root of the git repository. By default, searches parent directories for a package.json to find the "root". | +|filter |[optional] a dictionary of filter rules to whitelist packages. Filters can be applied based on package.json keys,
e.g. `filter: { package.name: someRegex, path: some/relative/path }`| +|sort |[optional] sort based on package properties (see `filter`), or readme length. Use `-` as a prefix to sort descending.
e.g. `sort: -readme.length` | + + +##### Demo + +![](./gifs/monorepoTOC.gif) + +#### [markdownFromJsdoc](./src/presets/markdown-from-jsdoc.ts#L17) + +Convert jsdoc for an es export from a javascript/typescript file to markdown. + +##### Example + +`` + +##### Params + +|name |description | +|------|----------------------------------------------------------------------------------------------| +|source|{string} relative file path containing the export with jsdoc that should be copied to markdown| +|export|{string} the name of the export | + + ##### Demo ![](./gifs/markdownFromJsdoc.gif) @@ -287,36 +333,6 @@ Generates a yaml config for the [GitHub Pull Request Labeler Action](https://git ![](./gifs/labeler.gif) - -#### [custom](./src/presets/custom.ts#L32) - -Define your own codegen function, which will receive all options specified. Import the `Preset` type from this library to define a strongly-typed preset function: - -##### Example - -```typescript -import {Preset} from 'eslint-plugin-codegen' - -export const jsonPrinter: Preset<{myCustomProp: string}> = ({meta, options}) => { - const components = meta.glob('**\/*.tsx') // uses 'globSync' from glob package - return `filename: ${meta.filename}\ncustom prop: ${options.myCustomProp}\nComponent paths: ${components.join(', ')}` -} -``` - -This can be used with: - -` - ##### Demo ![](./gifs/custom.gif) @@ -414,4 +430,4 @@ _Rendered_: ___ -The code in this repository was moved from https://github.com/mmkal/ts +The code in this repository was moved from https://github.com/mmkal/ts diff --git a/package.json b/package.json index bcb1d51..0467a35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-codegen", - "version": "0.19.0", + "version": "0.20.0-0", "engines": { "node": ">=12.0.0" }, @@ -41,6 +41,14 @@ "@babel/generator": "~7.12.0", "@babel/parser": "^7.11.5", "@babel/traverse": "^7.11.5", + "@types/dedent": "0.7.0", + "@types/eslint": "^8.44.7", + "@types/glob": "7.1.3", + "@types/jest": "29.0.0", + "@types/js-yaml": "3.12.5", + "@types/lodash": "^4.14.202", + "@types/node": "^14.0.0", + "dedent": "^1.5.1", "eslint-plugin-markdown": "^3.0.1", "expect": "^29.7.0", "fp-ts": "^2.1.0", @@ -57,14 +65,11 @@ "@types/babel__generator": "7.6.2", "@types/babel__traverse": "7.11.0", "@types/dedent": "0.7.0", - "@types/eslint": "^8.44.7", "@types/glob": "7.1.3", "@types/jest": "29.5.8", "@types/js-yaml": "3.12.5", - "@types/lodash": "4.14.201", "@types/minimatch": "3.0.3", "@types/node": "^20.0.0", - "dedent": "0.7.0", "eslint": "8.54.0", "eslint-plugin-mmkal": "0.2.0", "expect-type2": "npm:expect-type@0.14.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f8e7ee8..989e2ab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,30 @@ dependencies: '@babel/traverse': specifier: ^7.11.5 version: 7.19.6 + '@types/dedent': + specifier: 0.7.0 + version: 0.7.0 + '@types/eslint': + specifier: ^8.44.7 + version: 8.44.7 + '@types/glob': + specifier: 7.1.3 + version: 7.1.3 + '@types/jest': + specifier: 29.0.0 + version: 29.0.0 + '@types/js-yaml': + specifier: 3.12.5 + version: 3.12.5 + '@types/lodash': + specifier: ^4.14.202 + version: 4.14.202 + '@types/node': + specifier: ^14.0.0 + version: 14.18.63 + dedent: + specifier: ^1.5.1 + version: 1.5.1 eslint-plugin-markdown: specifier: ^3.0.1 version: 3.0.1(eslint@8.54.0) @@ -58,33 +82,9 @@ devDependencies: '@types/babel__traverse': specifier: 7.11.0 version: 7.11.0 - '@types/dedent': - specifier: 0.7.0 - version: 0.7.0 - '@types/eslint': - specifier: ^8.44.7 - version: 8.44.7 - '@types/glob': - specifier: 7.1.3 - version: 7.1.3 - '@types/jest': - specifier: 29.5.8 - version: 29.5.8 - '@types/js-yaml': - specifier: 3.12.5 - version: 3.12.5 - '@types/lodash': - specifier: 4.14.201 - version: 4.14.201 '@types/minimatch': specifier: 3.0.3 version: 3.0.3 - '@types/node': - specifier: ^20.0.0 - version: 20.9.1 - dedent: - specifier: 0.7.0 - version: 0.7.0 eslint: specifier: 8.54.0 version: 8.54.0 @@ -96,7 +96,7 @@ devDependencies: version: /expect-type@0.14.0 jest: specifier: 29.7.0 - version: 29.7.0(@types/node@20.9.1)(ts-node@9.1.1) + version: 29.7.0(@types/node@14.18.63)(ts-node@9.1.1) minimatch: specifier: 3.0.4 version: 3.0.4 @@ -587,7 +587,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 chalk: 4.1.2 jest-message-util: 29.7.0 jest-util: 29.7.0 @@ -608,14 +608,14 @@ packages: '@jest/test-result': 29.7.0 '@jest/transform': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 ansi-escapes: 4.3.2 chalk: 4.1.2 ci-info: 3.9.0 exit: 0.1.2 graceful-fs: 4.2.10 jest-changed-files: 29.7.0 - jest-config: 29.7.0(@types/node@20.9.1)(ts-node@9.1.1) + jest-config: 29.7.0(@types/node@14.18.63)(ts-node@9.1.1) jest-haste-map: 29.7.0 jest-message-util: 29.7.0 jest-regex-util: 29.6.3 @@ -643,7 +643,7 @@ packages: dependencies: '@jest/fake-timers': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 jest-mock: 29.7.0 dev: true @@ -669,7 +669,7 @@ packages: dependencies: '@jest/types': 29.6.3 '@sinonjs/fake-timers': 10.3.0 - '@types/node': 20.9.1 + '@types/node': 14.18.63 jest-message-util: 29.7.0 jest-mock: 29.7.0 jest-util: 29.7.0 @@ -702,7 +702,7 @@ packages: '@jest/transform': 29.7.0 '@jest/types': 29.6.3 '@jridgewell/trace-mapping': 0.3.20 - '@types/node': 20.9.1 + '@types/node': 14.18.63 chalk: 4.1.2 collect-v8-coverage: 1.0.2 exit: 0.1.2 @@ -788,7 +788,7 @@ packages: dependencies: '@types/istanbul-lib-coverage': 2.0.4 '@types/istanbul-reports': 3.0.1 - '@types/node': 20.9.1 + '@types/node': 14.18.63 '@types/yargs': 15.0.14 chalk: 4.1.2 dev: true @@ -800,7 +800,7 @@ packages: '@jest/schemas': 29.6.3 '@types/istanbul-lib-coverage': 2.0.4 '@types/istanbul-reports': 3.0.1 - '@types/node': 20.9.1 + '@types/node': 14.18.63 '@types/yargs': 17.0.31 chalk: 4.1.2 @@ -1090,36 +1090,34 @@ packages: dependencies: '@types/http-cache-semantics': 4.0.3 '@types/keyv': 3.1.4 - '@types/node': 20.9.1 + '@types/node': 14.18.63 '@types/responselike': 1.0.2 dev: true /@types/dedent@0.7.0: resolution: {integrity: sha512-EGlKlgMhnLt/cM4DbUSafFdrkeJoC9Mvnj0PUCU7tFmTjMjNRT957kXCx0wYm3JuEq4o4ZsS5vG+NlkM2DMd2A==} - dev: true + dev: false /@types/eslint@8.44.7: resolution: {integrity: sha512-f5ORu2hcBbKei97U73mf+l9t4zTGl74IqZ0GQk4oVea/VS8tQZYkUveSYojk+frraAVYId0V2WC9O4PTNru2FQ==} dependencies: '@types/estree': 1.0.0 '@types/json-schema': 7.0.15 - dev: true /@types/estree@1.0.0: resolution: {integrity: sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==} - dev: true /@types/glob@7.1.3: resolution: {integrity: sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==} dependencies: '@types/minimatch': 3.0.3 - '@types/node': 20.9.1 - dev: true + '@types/node': 14.18.63 + dev: false /@types/graceful-fs@4.1.9: resolution: {integrity: sha512-olP3sd1qOEe5dXTSaFvQG+02VdRXcdytWLAZsAq1PecU8uqQAhkrnbli7DagjtXKW/Bl7YJbUsa8MPcuc8LHEQ==} dependencies: - '@types/node': 20.9.1 + '@types/node': 14.18.63 dev: true /@types/http-cache-semantics@4.0.3: @@ -1139,20 +1137,19 @@ packages: dependencies: '@types/istanbul-lib-report': 3.0.0 - /@types/jest@29.5.8: - resolution: {integrity: sha512-fXEFTxMV2Co8ZF5aYFJv+YeA08RTYJfhtN5c9JSv/mFEMe+xxjufCb+PHL+bJcMs/ebPUsBu+UNTEz+ydXrR6g==} + /@types/jest@29.0.0: + resolution: {integrity: sha512-X6Zjz3WO4cT39Gkl0lZ2baFRaEMqJl5NC1OjElkwtNzAlbkr2K/WJXkBkH5VP0zx4Hgsd2TZYdOEfvp2Dxia+Q==} dependencies: expect: 29.7.0 pretty-format: 29.7.0 - dev: true + dev: false /@types/js-yaml@3.12.5: resolution: {integrity: sha512-JCcp6J0GV66Y4ZMDAQCXot4xprYB+Zfd3meK9+INSJeVZwJmHAW30BBEEkPzXswMXuiyReUGOP3GxrADc9wPww==} - dev: true + dev: false /@types/json-schema@7.0.15: resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} - dev: true /@types/json5@0.0.29: resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} @@ -1161,12 +1158,12 @@ packages: /@types/keyv@3.1.4: resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==} dependencies: - '@types/node': 20.9.1 + '@types/node': 14.18.63 dev: true - /@types/lodash@4.14.201: - resolution: {integrity: sha512-y9euML0cim1JrykNxADLfaG0FgD1g/yTHwUs/Jg9ZIU7WKj2/4IW9Lbb1WZbvck78W/lfGXFfe+u2EGfIJXdLQ==} - dev: true + /@types/lodash@4.14.202: + resolution: {integrity: sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==} + dev: false /@types/mdast@3.0.15: resolution: {integrity: sha512-LnwD+mUEfxWMa1QpDraczIn6k0Ee3SMicuYSSzS6ZYl2gKS09EClnJYGd8Du6rfc5r/GZEk5o1mRb8TaTj03sQ==} @@ -1176,12 +1173,9 @@ packages: /@types/minimatch@3.0.3: resolution: {integrity: sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==} - dev: true - /@types/node@20.9.1: - resolution: {integrity: sha512-HhmzZh5LSJNS5O8jQKpJ/3ZcrrlG6L70hpGqMIAoM9YVD0YBRNWYsfwcXq8VnSjlNpCpgLzMXdiPo+dxcvSmiA==} - dependencies: - undici-types: 5.26.5 + /@types/node@14.18.63: + resolution: {integrity: sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==} /@types/normalize-package-data@2.4.1: resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==} @@ -1189,7 +1183,7 @@ packages: /@types/responselike@1.0.2: resolution: {integrity: sha512-/4YQT5Kp6HxUDb4yhRkm0bJ7TbjvTddqX7PZ5hz6qV3pxSo72f/6YPRo+Mu2DU307tm9IioO69l7uAwn5XNcFA==} dependencies: - '@types/node': 20.9.1 + '@types/node': 14.18.63 dev: true /@types/semver@7.3.12: @@ -2333,7 +2327,7 @@ packages: typescript: 5.2.2 dev: true - /create-jest@29.7.0(@types/node@20.9.1)(ts-node@9.1.1): + /create-jest@29.7.0(@types/node@14.18.63)(ts-node@9.1.1): resolution: {integrity: sha512-Adz2bdH0Vq3F53KEMJOoftQFutWCukm6J24wbPWRO4k1kMY7gS7ds/uoJkNuV8wDCtWWnuwGcJwpWcih+zEW1Q==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -2342,7 +2336,7 @@ packages: chalk: 4.1.2 exit: 0.1.2 graceful-fs: 4.2.10 - jest-config: 29.7.0(@types/node@20.9.1)(ts-node@9.1.1) + jest-config: 29.7.0(@types/node@14.18.63)(ts-node@9.1.1) jest-util: 29.7.0 prompts: 2.4.2 transitivePeerDependencies: @@ -2408,10 +2402,6 @@ packages: mimic-response: 3.1.0 dev: true - /dedent@0.7.0: - resolution: {integrity: sha512-Q6fKUPqnAHAyhiUgFU7BUzLiv0kd8saH9al7tnu5Q/okj6dnupxyTgFIBjVzJATdfIAm9NAsvXNzjaKa+bxVyA==} - dev: true - /dedent@1.5.1: resolution: {integrity: sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg==} peerDependencies: @@ -2419,7 +2409,6 @@ packages: peerDependenciesMeta: babel-plugin-macros: optional: true - dev: true /deep-extend@0.6.0: resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==} @@ -2916,7 +2905,7 @@ packages: '@typescript-eslint/eslint-plugin': 6.11.0(@typescript-eslint/parser@6.11.0)(eslint@8.54.0)(typescript@5.2.2) '@typescript-eslint/utils': 5.40.1(eslint@8.54.0)(typescript@5.2.2) eslint: 8.54.0 - jest: 29.7.0(@types/node@20.9.1)(ts-node@9.1.1) + jest: 29.7.0(@types/node@14.18.63)(ts-node@9.1.1) transitivePeerDependencies: - supports-color - typescript @@ -4429,7 +4418,7 @@ packages: '@jest/expect': 29.7.0 '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 chalk: 4.1.2 co: 4.6.0 dedent: 1.5.1 @@ -4450,7 +4439,7 @@ packages: - supports-color dev: true - /jest-cli@29.7.0(@types/node@20.9.1)(ts-node@9.1.1): + /jest-cli@29.7.0(@types/node@14.18.63)(ts-node@9.1.1): resolution: {integrity: sha512-OVVobw2IubN/GSYsxETi+gOe7Ka59EFMR/twOU3Jb2GnKKeMGJB5SGUUrEz3SFVmJASUdZUzy83sLNNQ2gZslg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -4464,10 +4453,10 @@ packages: '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 chalk: 4.1.2 - create-jest: 29.7.0(@types/node@20.9.1)(ts-node@9.1.1) + create-jest: 29.7.0(@types/node@14.18.63)(ts-node@9.1.1) exit: 0.1.2 import-local: 3.1.0 - jest-config: 29.7.0(@types/node@20.9.1)(ts-node@9.1.1) + jest-config: 29.7.0(@types/node@14.18.63)(ts-node@9.1.1) jest-util: 29.7.0 jest-validate: 29.7.0 yargs: 17.7.2 @@ -4478,7 +4467,7 @@ packages: - ts-node dev: true - /jest-config@29.7.0(@types/node@20.9.1)(ts-node@9.1.1): + /jest-config@29.7.0(@types/node@14.18.63)(ts-node@9.1.1): resolution: {integrity: sha512-uXbpfeQ7R6TZBqI3/TxCU4q4ttk3u0PJeC+E0zbfSoSjq6bJ7buBPxzQPL0ifrkY4DNu4JUdk0ImlBUYi840eQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} peerDependencies: @@ -4493,7 +4482,7 @@ packages: '@babel/core': 7.19.6 '@jest/test-sequencer': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 babel-jest: 29.7.0(@babel/core@7.19.6) chalk: 4.1.2 ci-info: 3.9.0 @@ -4563,7 +4552,7 @@ packages: '@jest/environment': 29.7.0 '@jest/fake-timers': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 jest-mock: 29.7.0 jest-util: 29.7.0 dev: true @@ -4583,7 +4572,7 @@ packages: dependencies: '@jest/types': 29.6.3 '@types/graceful-fs': 4.1.9 - '@types/node': 20.9.1 + '@types/node': 14.18.63 anymatch: 3.1.3 fb-watchman: 2.0.2 graceful-fs: 4.2.10 @@ -4657,7 +4646,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 jest-util: 29.7.0 dev: true @@ -4717,7 +4706,7 @@ packages: '@jest/test-result': 29.7.0 '@jest/transform': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 chalk: 4.1.2 emittery: 0.13.1 graceful-fs: 4.2.10 @@ -4748,7 +4737,7 @@ packages: '@jest/test-result': 29.7.0 '@jest/transform': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 chalk: 4.1.2 cjs-module-lexer: 1.2.3 collect-v8-coverage: 1.0.2 @@ -4800,7 +4789,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 chalk: 4.1.2 ci-info: 3.5.0 graceful-fs: 4.2.10 @@ -4824,7 +4813,7 @@ packages: dependencies: '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.9.1 + '@types/node': 14.18.63 ansi-escapes: 4.3.2 chalk: 4.1.2 emittery: 0.13.1 @@ -4836,13 +4825,13 @@ packages: resolution: {integrity: sha512-eIz2msL/EzL9UFTFFx7jBTkeZfku0yUAyZZZmJ93H2TYEiroIx2PQjEXcwYtYl8zXCxb+PAmA2hLIt/6ZEkPHw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: - '@types/node': 20.9.1 + '@types/node': 14.18.63 jest-util: 29.7.0 merge-stream: 2.0.0 supports-color: 8.1.1 dev: true - /jest@29.7.0(@types/node@20.9.1)(ts-node@9.1.1): + /jest@29.7.0(@types/node@14.18.63)(ts-node@9.1.1): resolution: {integrity: sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -4855,7 +4844,7 @@ packages: '@jest/core': 29.7.0(ts-node@9.1.1) '@jest/types': 29.6.3 import-local: 3.1.0 - jest-cli: 29.7.0(@types/node@20.9.1)(ts-node@9.1.1) + jest-cli: 29.7.0(@types/node@14.18.63)(ts-node@9.1.1) transitivePeerDependencies: - '@types/node' - babel-plugin-macros @@ -6700,7 +6689,7 @@ packages: '@babel/core': 7.19.6 bs-logger: 0.2.6 fast-json-stable-stringify: 2.1.0 - jest: 29.7.0(@types/node@20.9.1)(ts-node@9.1.1) + jest: 29.7.0(@types/node@14.18.63)(ts-node@9.1.1) jest-util: 29.7.0 json5: 2.2.3 lodash.memoize: 4.1.2 @@ -6878,9 +6867,6 @@ packages: has-symbols: 1.0.3 which-boxed-primitive: 1.0.2 - /undici-types@5.26.5: - resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} - /unique-string@3.0.0: resolution: {integrity: sha512-VGXBUVwxKMBUznyffQweQABPRRW1vHZAbadFZud4pLFAqRGvv/96vafgjWFqzourzr8YonlQiPgH0YCJfawoGQ==} engines: {node: '>=12'} diff --git a/src/index.ts b/src/index.ts index 24adca9..73ebfaf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,22 @@ /* eslint-disable mmkal/@typescript-eslint/restrict-template-expressions */ +import * as dedent from 'dedent' import type * as eslint from 'eslint' import expect from 'expect' import {tryCatch} from 'fp-ts/lib/Either' import * as fs from 'fs' import {globSync} from 'glob' +import * as glob from 'glob' import * as jsYaml from 'js-yaml' +import lodash from 'lodash' import * as os from 'os' import * as path from 'path' +import * as readPkgUp from 'read-pkg-up' import * as presetsModule from './presets' import {createProcessor} from './processor' +export const dependencies: presetsModule.PresetDependencies = {dedent, fs, glob, jsYaml, lodash, path, readPkgUp} + // idea: codegen/fs rule. type fs.anything and it generates an import for fs. same for path and os. type MatchAll = (text: string, pattern: string | RegExp) => Iterable>> @@ -117,7 +123,7 @@ const codegen: eslint.Rule.RuleModule = { } const opts = maybeOptions.right || {} - const presets: Record | undefined> = { + const presets: Record = { ...presetsModule, ...context.options[0]?.presets, } @@ -142,7 +148,7 @@ const codegen: eslint.Rule.RuleModule = { fs, path, } - return preset({meta, options: opts}) + return preset({meta, options: opts, context, dependencies}) }, err => `${err}`, ) diff --git a/src/presets/custom.ts b/src/presets/custom.ts index 4e4957d..07b64c1 100644 --- a/src/presets/custom.ts +++ b/src/presets/custom.ts @@ -36,7 +36,7 @@ export const custom: Preset< require?: string dev?: boolean } & Record -> = ({meta, options}) => { +> = ({meta, options, ...rest}) => { const sourcePath = options.source ? path.join(path.dirname(meta.filename), options.source) : meta.filename if (!fs.existsSync(sourcePath) || !fs.statSync(sourcePath).isFile()) { throw new Error(`Source path is not a file: ${sourcePath}`) @@ -55,10 +55,10 @@ export const custom: Preset< // eslint-disable-next-line mmkal/@typescript-eslint/no-var-requires, mmkal/@typescript-eslint/no-require-imports const sourceModule = require(sourcePath) - const func = options.export ? sourceModule[options.export] : sourceModule + const func: Preset = options.export ? sourceModule[options.export] : sourceModule if (typeof func !== 'function') { throw new TypeError(`Couldn't find export ${options.export || 'function'} from ${sourcePath} - got ${typeof func}`) } - return func({meta, options}) + return func({meta, options, ...rest}) } diff --git a/src/presets/index.ts b/src/presets/index.ts index 2ac052b..0a8f0cc 100644 --- a/src/presets/index.ts +++ b/src/presets/index.ts @@ -1,12 +1,33 @@ export type PresetMeta = { - filename: string existingContent: string + /** @deprecated instead of `meta.filename` use `context.physicalFilename` */ + filename: string + /** @deprecated instead of `meta.glob` use `dependencies.glob.globSync` */ glob: (pattern: string, opts: any) => string[] + /** @deprecated instead of `meta.fs` use `dependencies.fs` */ + fs: typeof import('fs') + /** @deprecated instead of `meta.path` use `dependencies.path` */ + path: typeof import('path') +} + +export interface PresetDependencies { fs: typeof import('fs') path: typeof import('path') + lodash: typeof import('lodash') + jsYaml: typeof import('js-yaml') + dedent: typeof import('dedent') + glob: Pick + readPkgUp: Pick +} + +export type PresetParams = { + options: Options + meta: PresetMeta + context: import('eslint').Rule.RuleContext + dependencies: PresetDependencies } -export type Preset = (params: {meta: PresetMeta; options: Options}) => string +export type Preset = (params: PresetParams) => string // codegen:start {preset: barrel} export * from './barrel' diff --git a/src/presets/monorepo-toc.ts b/src/presets/monorepo-toc.ts index d5d45d8..ca0f26f 100644 --- a/src/presets/monorepo-toc.ts +++ b/src/presets/monorepo-toc.ts @@ -31,8 +31,8 @@ export const monorepoTOC: Preset<{ repoRoot?: string filter?: string | Record sort?: string -}> = ({meta, options}) => { - const packages = getLeafPackages(options.repoRoot, meta.filename) +}> = ({options, context}) => { + const packages = getLeafPackages(options.repoRoot, context.physicalFilename) const leafPackages = packages .map(({path: leafPath, packageJson: leafPkg}) => { @@ -71,7 +71,7 @@ export const monorepoTOC: Preset<{ })() const {name} = leafPkg const homepage = - leafPkg.homepage || relative(path.dirname(meta.filename), leafPath).replace(/\/package.json$/, '') + leafPkg.homepage || relative(path.dirname(context.physicalFilename), leafPath).replace(/\/package.json$/, '') return [`- [${name}](${homepage})`, description].filter(Boolean).join(' - ').trim() }) diff --git a/test/presets/barrel.test.ts b/test/presets/barrel.test.ts index 9ba520f..5f5295b 100644 --- a/test/presets/barrel.test.ts +++ b/test/presets/barrel.test.ts @@ -1,9 +1,9 @@ import * as glob from 'glob' import minimatch from 'minimatch' import * as preset from '../../src/presets/barrel' -import {getMeta} from './meta' +import {buildPresetParams} from './meta' -const meta = getMeta(__filename) +const params = buildPresetParams(__filename) const mockFs: any = {} @@ -33,7 +33,7 @@ test('generates typescript', () => { expect( preset.barrel({ - meta, + ...params, options: {}, }), ).toMatchInlineSnapshot(` @@ -48,7 +48,7 @@ test('generates typescript', () => { expect( preset.barrel({ - meta, + ...params, options: {include: '{a,b}*'}, }), ).toMatchInlineSnapshot(` @@ -60,14 +60,14 @@ test('generates typescript', () => { expect( preset.barrel({ - meta, + ...params, options: {exclude: '*'}, }), ).toMatchInlineSnapshot(`""`) expect( preset.barrel({ - meta, + ...params, options: {include: '{a,b}*', exclude: ['*util*']}, }), ).toMatchInlineSnapshot(` @@ -77,7 +77,7 @@ test('generates typescript', () => { expect( preset.barrel({ - meta, + ...params, options: {include: '{a,b}.ts', import: 'star'}, }), ).toMatchInlineSnapshot(` @@ -93,7 +93,7 @@ test('generates typescript', () => { expect( preset.barrel({ - meta, + ...params, options: {include: '{a,b}.ts', import: 'default'}, }), ).toMatchInlineSnapshot(` @@ -109,7 +109,7 @@ test('generates typescript', () => { expect( preset.barrel({ - meta, + ...params, options: {include: '{a,b}.ts', import: 'star', export: 'default'}, }), ).toMatchInlineSnapshot(` @@ -125,7 +125,7 @@ test('generates typescript', () => { expect( preset.barrel({ - meta, + ...params, options: {include: '{a,b}.ts', import: 'star', export: 'foo'}, }), ).toMatchInlineSnapshot(` @@ -141,7 +141,7 @@ test('generates typescript', () => { expect( preset.barrel({ - meta, + ...params, options: {include: '{a,b}.ts', import: 'star', export: {name: 'foo', keys: 'path'}}, }), ).toMatchInlineSnapshot(` @@ -157,7 +157,7 @@ test('generates typescript', () => { expect( preset.barrel({ - meta, + ...params, options: {include: '{a,b}.ts', import: 'star', export: {name: 'foo', keys: 'camelCase'}}, }), ).toMatchInlineSnapshot(` @@ -173,7 +173,7 @@ test('generates typescript', () => { expect( preset.barrel({ - meta, + ...params, options: {include: '{a,b}.ts', import: 'star', export: {name: 'default', keys: 'path'}}, }), ).toMatchInlineSnapshot(` @@ -203,8 +203,9 @@ test('is unopinionated about formatting', () => { expect( preset.barrel({ + ...params, meta: { - ...meta, + ...params.meta, existingContent: oldContent, }, options: {}, @@ -221,7 +222,7 @@ test(`generates valid identifiers for filenames that don't start with letters`, expect( preset.barrel({ - meta, + ...params, options: { import: 'star', }, @@ -248,7 +249,7 @@ test(`ambiguously named files get unique, valid identifiers`, () => { expect( preset.barrel({ - meta, + ...params, options: { import: 'star', }, @@ -273,7 +274,7 @@ test(`index files are sensibly-named`, () => { expect( preset.barrel({ - meta, + ...params, options: { include: '*/*', import: 'star', @@ -299,7 +300,7 @@ test(`supports asset imports`, () => { expect( preset.barrel({ - meta, + ...params, options: {include: '*.{jpg,png}', import: 'default'}, }), ).toMatchInlineSnapshot(` @@ -322,7 +323,7 @@ test(`respects pascale case imports`, () => { expect( preset.barrel({ - meta, + ...params, options: {import: 'star'}, }), ).toMatchInlineSnapshot(` @@ -345,7 +346,7 @@ test(`it support the extensions in the output`, () => { expect( preset.barrel({ - meta, + ...params, options: {import: 'star', extension: true}, }), ).toMatchInlineSnapshot(` @@ -367,7 +368,7 @@ test(`it can change the extension in the output`, () => { expect( preset.barrel({ - meta, + ...params, options: {import: 'star', extension: {ts: 'js'}}, }), ).toMatchInlineSnapshot(` diff --git a/test/presets/custom.test.ts b/test/presets/custom.test.ts index df81bcc..a63e39c 100644 --- a/test/presets/custom.test.ts +++ b/test/presets/custom.test.ts @@ -1,8 +1,8 @@ import * as path from 'path' import * as preset from '../../src/presets/custom' -import {getMeta} from './meta' +import {buildPresetParams} from './meta' -const meta = getMeta(__filename) +const params = buildPresetParams(__filename) jest.mock('ts-node/register/transpile-only') @@ -18,7 +18,7 @@ test('custom preset validation', () => { test('named export', () => { expect( preset.custom({ - meta, + ...params, options: {source: './custom-preset.cjs', export: 'getText', input: 'abc'}, }), ).toMatchInlineSnapshot(`"Named export with input: abc"`) @@ -27,7 +27,7 @@ test('named export', () => { test('whole module export', () => { expect( preset.custom({ - meta, + ...params, options: {source: './custom-preset.cjs', input: 'def'}, }), ).toMatchInlineSnapshot(`"Whole module export with input: def"`) @@ -36,7 +36,7 @@ test('whole module export', () => { test('load typescript with ts-node', () => { expect( preset.custom({ - meta, + ...params, options: {source: './custom-preset.ts', export: 'getText'}, }), ).toMatchInlineSnapshot(`"typescript text"`) @@ -45,7 +45,7 @@ test('load typescript with ts-node', () => { test('dev mode, deletes require cache', () => { expect( preset.custom({ - meta, + ...params, options: {source: './custom-preset.cjs', input: 'ghi', dev: true}, }), ).toMatchInlineSnapshot(`"Whole module export with input: ghi"`) @@ -54,7 +54,8 @@ test('dev mode, deletes require cache', () => { test(`when source isn't specified, uses filename`, () => { expect( preset.custom({ - meta: {...meta, filename: path.join(__dirname, 'custom-preset.cjs')}, + ...params, + meta: {...params.meta, filename: path.join(__dirname, 'custom-preset.cjs')}, options: {input: 'abc'}, }), ).toEqual('Whole module export with input: abc') @@ -63,7 +64,7 @@ test(`when source isn't specified, uses filename`, () => { test('errors for non-existent source file', () => { expect(() => preset.custom({ - meta, + ...params, options: {source: './does-not-exist.ts'}, }), ).toThrow(/Source path is not a file: .*does-not-exist.ts/) @@ -72,7 +73,7 @@ test('errors for non-existent source file', () => { test('errors if directory passed as source', () => { expect(() => preset.custom({ - meta, + ...params, options: {source: '__tests__'}, }), ).toThrow(/Source path is not a file: .*__tests__/) @@ -81,7 +82,7 @@ test('errors if directory passed as source', () => { test('errors for non-existent export', () => { expect(() => preset.custom({ - meta, + ...params, options: {source: './custom-preset.cjs', export: 'doesNotExist', input: 'abc'}, }), ).toThrow(/Couldn't find export doesNotExist from .*custom-preset.cjs - got undefined/) @@ -90,7 +91,7 @@ test('errors for non-existent export', () => { test('errors for export with wrong type', () => { expect(() => preset.custom({ - meta, + ...params, options: {source: './invalid-custom-preset.cjs', input: 'abc'}, }), ).toThrow(/Couldn't find export function from .*invalid-custom-preset.cjs - got object/) @@ -99,7 +100,7 @@ test('errors for export with wrong type', () => { test('can require module first', () => { expect(() => preset.custom({ - meta, + ...params, options: {source: './custom-preset.cjs', require: 'thismoduledoesnotexist'}, }), ).toThrow(/Cannot find module 'thismoduledoesnotexist' from 'src\/presets\/custom.ts'/) diff --git a/test/presets/empty.test.ts b/test/presets/empty.test.ts index 643b94b..ba479f5 100644 --- a/test/presets/empty.test.ts +++ b/test/presets/empty.test.ts @@ -1,14 +1,15 @@ import * as preset from '../../src/presets/empty' -import {getMeta} from './meta' +import {buildPresetParams} from './meta' -const meta = getMeta(__filename) +const params = buildPresetParams(__filename) const emptyReadme = {filename: 'readme.md', existingContent: ''} test('generates nothing', () => { expect( preset.empty({ - meta: {...meta, ...emptyReadme}, + ...params, + meta: {...params.meta, ...emptyReadme}, options: {}, }), ).toEqual('') diff --git a/test/presets/labeler.test.ts b/test/presets/labeler.test.ts index bfc37d4..7dc9cc0 100644 --- a/test/presets/labeler.test.ts +++ b/test/presets/labeler.test.ts @@ -2,9 +2,7 @@ import * as glob from 'glob' import minimatch from 'minimatch' import readPkgUp from 'read-pkg-up' import * as preset from '../../src/presets/labeler' -import {getMeta} from './meta' - -const meta = getMeta(__filename) +import {buildPresetParams} from './meta' const mockFs: any = {} @@ -55,8 +53,6 @@ jest.spyOn(readPkgUp, 'sync').mockImplementation(options => .find(p => options.cwd?.includes(p.path.replace('package.json', ''))), ) -const labelerDotYml = {...meta, filename: '.github/labeler.yml', existingContent: ''} - beforeEach(() => { Object.assign(mockFs, { 'package.json': '{ "workspaces": ["packages/*"] }', @@ -70,7 +66,7 @@ beforeEach(() => { test('generate labels', () => { expect( preset.labeler({ - meta: labelerDotYml, + ...buildPresetParams('.github/labeler.yml'), options: {}, }), ).toMatchInlineSnapshot(` diff --git a/test/presets/markdown-from-jsdoc.test.ts b/test/presets/markdown-from-jsdoc.test.ts index 9fabb42..204f745 100644 --- a/test/presets/markdown-from-jsdoc.test.ts +++ b/test/presets/markdown-from-jsdoc.test.ts @@ -1,8 +1,8 @@ import dedent from 'dedent' import * as preset from '../../src/presets/markdown-from-jsdoc' -import {getMeta} from './meta' +import {buildPresetParams} from './meta' -const meta = getMeta(__filename) +const params = buildPresetParams(__dirname + '/index.ts') const mockFs: any = {} @@ -22,7 +22,17 @@ jest.mock('fs', () => { return mockFs[path] } - return actual[orig](...args) + try { + return actual[orig](...args) + } catch (e) { + throw new Error( + `Failed calling ${orig} with args ${JSON.stringify(args)}: ${e}. Mock fs: ${JSON.stringify( + mockFs, + null, + 2, + )}}`, + ) + } } return { @@ -34,10 +44,9 @@ jest.mock('fs', () => { } }) -const emptyReadme = {...meta, filename: 'readme.md', existingContent: ''} test('generate markdown', () => { Object.assign(mockFs, { - 'index.ts': dedent` + [params.context.physicalFilename]: dedent` /** * Adds two numbers * @@ -80,7 +89,7 @@ test('generate markdown', () => { expect( preset.markdownFromJsdoc({ - meta: emptyReadme, + ...params, options: {source: 'index.ts', export: 'add'}, }), ).toMatchInlineSnapshot(` @@ -116,7 +125,7 @@ test('generate markdown', () => { expect( preset.markdownFromJsdoc({ - meta: emptyReadme, + ...params, options: {source: 'index.ts', export: 'multiply'}, }), ).toMatchInlineSnapshot(` @@ -133,7 +142,7 @@ test('generate markdown', () => { test('not found export', () => { Object.assign(mockFs, { - 'index.ts': dedent` + [params.context.physicalFilename]: dedent` /** docs */ export const add = (a: number, b: number) => a + b `, @@ -141,7 +150,7 @@ test('not found export', () => { expect(() => preset.markdownFromJsdoc({ - meta: emptyReadme, + ...params, options: {source: 'index.ts', export: 'subtract'}, }), ).toThrow(/Couldn't find export in .*index.ts with jsdoc called subtract/) diff --git a/test/presets/markdown-from-tests.test.ts b/test/presets/markdown-from-tests.test.ts index 7858fc4..0a815e1 100644 --- a/test/presets/markdown-from-tests.test.ts +++ b/test/presets/markdown-from-tests.test.ts @@ -1,8 +1,8 @@ import dedent from 'dedent' import * as preset from '../../src/presets/markdown-from-tests' -import {getMeta} from './meta' +import {buildPresetParams} from './meta' -const meta = getMeta(__filename) +const params = buildPresetParams(__dirname + '/test.ts') const mockFs: any = {} @@ -34,11 +34,9 @@ jest.mock('fs', () => { } }) -const emptyReadme = {...meta, filename: 'readme.md', existingContent: ''} - test('generate markdown', () => { Object.assign(mockFs, { - 'test.ts': dedent` + [params.context.physicalFilename]: dedent` import {calculator} from '..' beforeEach(() => { @@ -69,7 +67,7 @@ test('generate markdown', () => { }) const withHeaders = preset.markdownFromTests({ - meta: emptyReadme, + ...params, options: {source: 'test.ts', headerLevel: 4}, }) expect(withHeaders).toMatchInlineSnapshot(` @@ -92,7 +90,7 @@ test('generate markdown', () => { \`\`\`" `) const withoutHeaders = preset.markdownFromTests({ - meta: emptyReadme, + ...params, options: {source: 'test.ts'}, }) diff --git a/test/presets/markdown-toc.test.ts b/test/presets/markdown-toc.test.ts index b6f09d0..e1bf780 100644 --- a/test/presets/markdown-toc.test.ts +++ b/test/presets/markdown-toc.test.ts @@ -1,8 +1,6 @@ import dedent from 'dedent' import * as preset from '../../src/presets/markdown-toc' -import {getMeta} from './meta' - -const meta = getMeta(__filename) +import {buildPresetParams} from './meta' const mockFs: any = {} @@ -34,7 +32,7 @@ jest.mock('fs', () => { } }) -const emptyReadme = {...meta, filename: 'readme.md', existingContent: ''} +const params = buildPresetParams('readme.md') test('generate markdown', () => { Object.assign(mockFs, { @@ -58,7 +56,7 @@ test('generate markdown', () => { expect( preset.markdownTOC({ - meta: emptyReadme, + ...params, options: {}, }), ).toMatchInlineSnapshot(` @@ -75,7 +73,7 @@ test('generate markdown', () => { expect( preset.markdownTOC({ - meta: emptyReadme, + ...params, options: { minDepth: 2, maxDepth: 3, @@ -100,7 +98,7 @@ test('calculates min hashes', () => { expect( preset.markdownTOC({ - meta: emptyReadme, + ...params, options: {}, }), ).toMatchInlineSnapshot(` @@ -113,7 +111,7 @@ test('calculates min hashes', () => { expect( preset.markdownTOC({ - meta: emptyReadme, + ...params, options: { minDepth: 2, maxDepth: 3, diff --git a/test/presets/meta.ts b/test/presets/meta.ts index 630f7de..7e3392b 100644 --- a/test/presets/meta.ts +++ b/test/presets/meta.ts @@ -1,7 +1,8 @@ import * as glob from 'glob' import * as fs from 'node:fs' // 'node:fs' rather than 'fs' to avoid test mock trying to shim this import * as path from 'path' -import {PresetMeta} from '../../src/presets' +import {dependencies} from '../../src' +import {PresetMeta, PresetParams} from '../../src/presets' export const getMeta = (filename: string): PresetMeta => ({ filename, @@ -10,3 +11,9 @@ export const getMeta = (filename: string): PresetMeta => ({ fs, path, }) + +export const buildPresetParams = (filename: string): Omit => ({ + meta: getMeta(filename), + context: {filename, physicalFilename: filename} as any, + dependencies: dependencies, +}) diff --git a/test/presets/monorepo-toc.test.ts b/test/presets/monorepo-toc.test.ts index 247c062..e347ce4 100644 --- a/test/presets/monorepo-toc.test.ts +++ b/test/presets/monorepo-toc.test.ts @@ -2,9 +2,7 @@ import dedent from 'dedent' import * as glob from 'glob' import minimatch from 'minimatch' import * as preset from '../../src/presets/monorepo-toc' -import {getMeta} from './meta' - -const meta = getMeta(__filename) +import {buildPresetParams} from './meta' const mockFs: any = {} @@ -47,7 +45,7 @@ jest.spyOn(glob, 'globSync').mockImplementation((pattern, opts) => { return found.filter(f => (ignores as string[]).every(i => !minimatch(f, i))) }) -const emptyReadme = {...meta, filename: 'readme.md', existingContent: ''} +const params = buildPresetParams('readme.md') beforeEach(() => { Object.assign(mockFs, { @@ -90,7 +88,7 @@ beforeEach(() => { test('generate markdown', () => { expect( preset.monorepoTOC({ - meta: emptyReadme, + ...params, options: {}, }), ).toMatchInlineSnapshot(` @@ -104,7 +102,7 @@ test('generate markdown', () => { test('generate markdown with filter', () => { expect( preset.monorepoTOC({ - meta: emptyReadme, + ...params, options: {filter: {'package.name': 'package1|package3'}}, }), ).toMatchInlineSnapshot(` @@ -116,7 +114,7 @@ test('generate markdown with filter', () => { test('generate markdown with sorting', () => { expect( preset.monorepoTOC({ - meta: emptyReadme, + ...params, options: {sort: '-readme.length'}, }), ).toMatchInlineSnapshot(` @@ -131,7 +129,7 @@ test('generate markdown default to lerna to find packages', () => { mockFs['package.json'] = '{}' expect( preset.monorepoTOC({ - meta: emptyReadme, + ...params, options: {}, }), ).toMatchInlineSnapshot(` @@ -143,7 +141,7 @@ test('generate markdown default to lerna to find packages', () => { test('generate markdown fails when no package.json exists', () => { expect(() => preset.monorepoTOC({ - meta: {...meta, filename: 'subdir/test.md', existingContent: ''}, + ...buildPresetParams('subdir/test.md'), options: {}, }), ).toThrow(/ENOENT: no such file or directory, open '.*subdir.*package.json'/) @@ -152,7 +150,7 @@ test('generate markdown fails when no package.json exists', () => { test('generate markdown with separate rootDir', () => { expect( preset.monorepoTOC({ - meta: {...meta, filename: 'subdir/test.md', existingContent: ''}, + ...buildPresetParams('subdir/test.md'), options: {repoRoot: '..'}, }), ).toMatchInlineSnapshot(` @@ -171,7 +169,7 @@ test('invalid workspaces', () => { expect(() => preset.monorepoTOC({ - meta: emptyReadme, + ...params, options: {}, }), ).toThrow(/Expected to find workspaces array, got 'package.json - not an array'/) diff --git a/tsconfig.json b/tsconfig.json index 2f281fd..69c0ab9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,8 @@ "strict": true, "noEmit": true, "noErrorTruncation": true, + "noUnusedLocals": false, + "noUnusedParameters": false, "esModuleInterop": true }, "include": ["src", "test", "*.js", ".*.*js", "*.md"]