Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ruleset-migrator): implement ruleset migrator #1698

Merged
merged 17 commits into from
Jul 1, 2021

Conversation

P0lip
Copy link
Contributor

@P0lip P0lip commented Jun 28, 2021

Closes https://github.com/stoplightio/platform-internal/issues/6763

Checklist

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
    HonestWork

  • No

Additional context

Make sure to read f90d2c8

Tests account for ~50% of the whole diff

 .../services/__tests__/__fixtures__/ruleset.json   |  17 +++
 packages/cli/src/services/__tests__/linter.test.ts |  14 ++
 .../__fixtures__/apisyouwonthate/output.cjs        | 149 +++++++++++++++++++++
 .../__fixtures__/apisyouwonthate/output.mjs        | 143 ++++++++++++++++++++
 .../__fixtures__/apisyouwonthate/ruleset.yaml      | 133 ++++++++++++++++++
 .../__fixtures__/extends-variant-1/output.cjs      |   4 +
 .../__fixtures__/extends-variant-1/output.mjs      |   4 +
 .../__fixtures__/extends-variant-1/ruleset.yaml    |   1 +
 .../__fixtures__/extends-variant-2/output.cjs      |   4 +
 .../__fixtures__/extends-variant-2/output.mjs      |   4 +
 .../__fixtures__/extends-variant-2/ruleset.yaml    |   1 +
 .../__fixtures__/extends-variant-3/output.cjs      |   4 +
 .../__fixtures__/extends-variant-3/output.mjs      |   4 +
 .../__fixtures__/extends-variant-3/ruleset.yaml    |   1 +
 .../__fixtures__/extends-variant-4/output.cjs      |   4 +
 .../__fixtures__/extends-variant-4/output.mjs      |   4 +
 .../__fixtures__/extends-variant-4/ruleset.yaml    |   1 +
 .../__fixtures__/extends-variant-5/output.cjs      |   4 +
 .../__fixtures__/extends-variant-5/output.mjs      |   4 +
 .../__fixtures__/extends-variant-5/ruleset.yaml    |   1 +
 .../__fixtures__/formats-variant-1/output.cjs      |  10 ++
 .../__fixtures__/formats-variant-1/output.mjs      |   5 +
 .../__fixtures__/formats-variant-1/ruleset.yaml    |   2 +
 .../__fixtures__/formats-variant-2/output.cjs      |  21 +++
 .../__fixtures__/formats-variant-2/output.mjs      |  14 ++
 .../__fixtures__/formats-variant-2/ruleset.yaml    |  16 +++
 .../__fixtures__/functions-variant-1/output.cjs    |  28 ++++
 .../__fixtures__/functions-variant-1/output.mjs    |  25 ++++
 .../__fixtures__/functions-variant-1/ruleset.yaml  |  22 +++
 .../__fixtures__/functions-variant-2/output.cjs    |  23 ++++
 .../__fixtures__/functions-variant-2/output.mjs    |  20 +++
 .../__fixtures__/functions-variant-2/ruleset.yaml  |  17 +++
 .../__fixtures__/rules-variant-1/output.cjs        |  19 +++
 .../__fixtures__/rules-variant-1/output.mjs        |  19 +++
 .../__fixtures__/rules-variant-1/ruleset.yaml      |  16 +++
 .../ruleset-migrator/src/__tests__/ruleset.test.ts |  63 +++++++++
 36 files changed, 821 insertions(+)

One can apply the following filter to filter out the majority of test artefacts.

image

@P0lip P0lip added the enhancement New feature or request label Jun 28, 2021
@P0lip P0lip self-assigned this Jun 28, 2021
@P0lip P0lip force-pushed the feat/migrator-project branch from 303a321 to cf87716 Compare June 28, 2021 14:58
@P0lip P0lip force-pushed the feat/migrator-project branch from d3894fa to 97e5d22 Compare June 28, 2021 15:17
@P0lip P0lip force-pushed the feat/migrator-project branch from 2953884 to 4e94c40 Compare June 28, 2021 15:33
@P0lip P0lip marked this pull request as ready for review June 29, 2021 08:20
@P0lip P0lip requested review from mnaumanali94, a team and billiegoose and removed request for a team June 29, 2021 08:21
import { migrateRuleset } from '@stoplight/spectral-ruleset-migrator';

// eslint-disable-next-line @typescript-eslint/require-await
const AsyncFunction = (async (): Promise<void> => void 0).constructor as FunctionConstructor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I even want to know?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, long story short - in rare circumstances a "top-level" await might be inserted.
This won't be a problem soon-ish once we hop on ESM, but for the time being it's a plain CommonJS.
The above is needed for us to be able to do

AsyncFunction('module.exports = await /* the rest of the code goes here */)'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Narrator: it turns out he really did not want to know :trollface:

billiegoose
billiegoose previously approved these changes Jul 1, 2021
Copy link
Contributor

@billiegoose billiegoose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@P0lip P0lip merged commit efa5c50 into develop Jul 1, 2021
@P0lip P0lip deleted the feat/migrator-project branch July 1, 2021 22:47
@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version @stoplight/spectral-cli-v1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version @stoplight/spectral-core-v1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version @stoplight/spectral-ruleset-migrator-v1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version @stoplight/spectral-runtime-v1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

stoplight-bot pushed a commit that referenced this pull request Jul 8, 2021
# @stoplight/spectral-cli-v1.0.0 (2021-07-08)

### Features

* **cli:** demand some ruleset to be present ([#1699](#1699)) ([3baba29](3baba29))
* **cli:** implement --stdin-filepath flag ([#1712](#1712)) ([45b15a2](45b15a2))
* **core:** support overrides in rulesets ([#1684](#1684)) ([153d685](153d685))
* **core:** use double quotes in errors reported by Ajv ([#1718](#1718)) ([dd2a166](dd2a166))
* **ruleset-migrator:** implement ruleset migrator  ([#1698](#1698)) ([efa5c50](efa5c50))
* **ruleset-migrator:** inline external rulesets & support exceptions  ([#1711](#1711)) ([2a1d2d3](2a1d2d3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants