{"_id":"@conformyze/lynta-ruleset-migrator","name":"@conformyze/lynta-ruleset-migrator","dist-tags":{"latest":"0.0.0"},"versions":{"0.0.0":{"name":"@conformyze/lynta-ruleset-migrator","version":"0.0.0","homepage":"https://github.com/conformyze/lynta","bugs":{"url":"https://github.com/conformyze/lynta/issues"},"author":{"name":"Conformyze","email":"support@conformyze.com"},"engines":{"node":"^18.20 || ^20.13 || >=22"},"license":"Apache-2.0","main":"dist/index.js","types":"dist/index.d.ts","browser":{"./dist/requireResolve.js":false},"repository":{"type":"git","url":"git+https://github.com/conformyze/lynta.git"},"dependencies":{"@conformyze/lynta-functions":"0.0.0","@conformyze/lynta-json-schema":"0.0.0","@conformyze/lynta-parsers":"0.0.0","@conformyze/lynta-runtime":"0.0.0","@conformyze/lynta-types":"0.0.0","@conformyze/path":"^2.0.1","@types/node":"*","ast-types":"0.14.2","astring":"^1.7.5","reserved":"0.1.2","tslib":"^2.3.1","validate-npm-package-name":"3.0.0"},"devDependencies":{"@conformyze/lynta-rulesets":"*","fetch-mock":"^9.11.0","json-schema-to-typescript":"^10.1.5","lynta":"*","memfs":"^3.3.0","prettier":"^2.4.1"},"scripts":{"pretest":"ts-node -T ./scripts/generate-test-fixtures.ts && yarn prebuild","prebuild":"ts-node -T ./scripts/compile-schemas.ts"},"_id":"@conformyze/lynta-ruleset-migrator@0.0.0","gitHead":"8d534d88e052af798ae7162d23b473ab8f666c6c","description":"This project serves as a converter between the legacy ruleset format and a new one. It's used internally, albeit it can be used externally too, also in browsers.","_nodeVersion":"20.16.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-M5EX0/uLOw+UyZignwOxDDrC0P6KoXjH9ppEncFLNemryU43iiqcTyG+jmSM602ajqnAyO+T/jIgEV7kN4smSg==","shasum":"8b79a7053bb8739b152c8d0ce88ad787657da98c","tarball":"https://registry.npmjs.org/@conformyze/lynta-ruleset-migrator/-/lynta-ruleset-migrator-0.0.0.tgz","fileCount":63,"unpackedSize":78104,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDdUn/tkAB6NocTGo2sR7NJy6rEnTpKxtEQTV+plnS+LwIhAM7qmAOYNOZzjNmMwONiPpyoMTCckqbv8bFZ4EmaY5wy"}]},"_npmUser":{"name":"p0lip","email":"jakub@rozek.tech"},"directories":{},"maintainers":[{"name":"naumanali__","email":"mnaumanali94@gmail.com"},{"name":"p0lip","email":"jakub@rozek.tech"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/lynta-ruleset-migrator_0.0.0_1723628531435_0.06764873314162578"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-14T09:42:11.434Z","0.0.0":"2024-08-14T09:42:11.600Z","modified":"2024-08-14T09:42:11.982Z"},"maintainers":[{"name":"naumanali__","email":"mnaumanali94@gmail.com"},{"name":"p0lip","email":"jakub@rozek.tech"}],"description":"This project serves as a converter between the legacy ruleset format and a new one. It's used internally, albeit it can be used externally too, also in browsers.","homepage":"https://github.com/conformyze/lynta","repository":{"type":"git","url":"git+https://github.com/conformyze/lynta.git"},"author":{"name":"Conformyze","email":"support@conformyze.com"},"bugs":{"url":"https://github.com/conformyze/lynta/issues"},"license":"Apache-2.0","readme":"# @conformyze/lynta-ruleset-migrator\n\nThis project serves as a converter between the legacy ruleset format and a new one.\nIt's used internally, albeit it can be used externally too, also in browsers.\n\nFor the time being there are two output formats supported: commonjs & esm.\nThe migrator loads the ruleset, apply a number of conversions and return a valid JS code that can be executed later on.\n\n## Examples\n\n```yaml\n# .spectral.yaml\nextends: spectral:oas\nformats: [oas2, json-schema-loose]\nrules:\n  oas3-schema: warning\n  valid-type:\n    message: Type must be valid\n    given: $..type\n    then:\n      function: pattern\n      functionOptions:\n        mustMatch: ^(string|number)$\n```\n\n```js\n// .spectral.js (CommonJS)\nconst { oas: oas } = require(\"@conformyze/lynta-rulesets\");\nconst { oas2: oas2, jsonSchemaLoose: jsonSchemaLoose } = require(\"@conformyze/lynta-formats\");\nconst { pattern: pattern } = require(\"@conformyze/lynta-functions\");\nmodule.exports = {\n  extends: oas,\n  formats: [oas2, jsonSchemaLoose],\n  rules: {\n    \"oas3-schema\": \"warning\",\n    \"valid-type\": {\n      message: \"Type must be valid\",\n      given: \"$..type\",\n      then: {\n        function: pattern,\n        functionOptions: {\n          mustMatch: \"^(string|number)$\",\n        },\n      },\n    },\n  },\n};\n```\n\n```js\n// .spectral.js (ES Module)\nimport { oas } from \"@conformyze/lynta-rulesets\";\nimport { oas2, jsonSchemaLoose } from \"@conformyze/lynta-formats\";\nimport { pattern } from \"@conformyze/lynta-functions\";\nexport default {\n  extends: oas,\n  formats: [oas2, jsonSchemaLoose],\n  rules: {\n    \"oas3-schema\": \"warning\",\n    \"valid-type\": {\n      message: \"Type must be valid\",\n      given: \"$..type\",\n      then: {\n        function: pattern,\n        functionOptions: {\n          mustMatch: \"^(string|number)$\",\n        },\n      },\n    },\n  },\n};\n```\n\n## Usage\n\n### With lynta-ruleset-bundler\n\nIf you need to transform the YAML/JSON ruleset and load it in a single step, we've got you covered.\nPlease refer to [@conformyze/lynta-ruleset-bundler](https://www.npmjs.com/package/@conformyze/lynta-ruleset-bundler).\n\n### Programmatically\n\n```ts\nconst { migrateRuleset } = require(\"@conformyze/lynta-ruleset-migrator\");\nconst fs = require(\"node:fs/promises\");\nconst path = require(\"node:path\");\n\nmigrateRuleset(path.join(__dirname, \"spectral.json\"), {\n  fs,\n  fetch,\n  format: \"commonjs\", // esm available too, but not recommended for now\n}).then(fs.promises.writeFile.bind(fs.promises, path.join(__dirname, \".spectral.js\")));\n```\n\n### Caveats\n\n#### YAML/JSON extending JS rulesets\n\nIt's not disallowed for a YAML/JSON ruleset to extend another ruleset expressed in JS,\nalbeit one has to notice that the formats have to be matched.\nIn other words if you select \"commonjs\" as your target format, your extended rulesets have to follow,\notherwise Node.js or any other tool you use in between may refuse to load the resulting code.\nIf that happens to be the limitation for you, try your luck with [esm](https://www.npmjs.com/package/esm), [Babel](https://babeljs.io/) or a bundler such as [rollup.js](https://rollupjs.org/).\n","readmeFilename":"README.md"}