stoplightio / vscode-spectral

VS Code extension bringing the awesome Spectral JSON/YAML linter with OpenAPI/AsyncAPI support

Home Page:https://marketplace.visualstudio.com/items?itemName=stoplight.spectral

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VSCode extension fails when using raw github link to ruleset

mikekistler opened this issue · comments

Describe the bug

My spectral.yaml file references a ruleset in GitHub with a raw github url:

extends:
  - https://raw.githubusercontent.com/azure/azure-api-style-guide/main/spectral.yaml

The Spectral-cli works just fine with this configuration, but the Spectral VSCode extension throws an error:

[Error - 10:17:36 AM] An error occurred while validating document /Users/mikekistler/Projects/Azure/azure-rest-api-specs/specification/loadtestservice/data-plane/Microsoft.LoadTestService/stable/2022-11-01/loadtestservice.json: Unable to read ruleset at /Users/mikekistler/Projects/Azure/azure-rest-api-specs/.spectral.yaml. Error: Could not load https://raw.githubusercontent.com/azure/azure-api-style-guide/main/functions/%00commonjsHelpers.js (imported by https://raw.githubusercontent.com/azure/azure-api-style-guide/main/functions/consistent-response-body.js): Error fetching https://raw.githubusercontent.com/azure/azure-api-style-guide/main/functions/%00commonjsHelpers.js: Bad Request

Note the %00 character before commonjsHelpers.js. This is likely the source of the problem.

Also, I will note that functions/consistent-response-body.js, and in fact no other file in the repository` has any reference to "commonjsHelpers.js".

One more detail -- the extension works fine if I clone the repo and point the Spectral config to my local copy.

To Reproduce

Set your Spectral config as shown above and then open any OpenAPI document.

Expected behavior

It should not throw an error -- it should run successfully and show the resulting lint messages in the Problems pane.

Environment:

  • Extension version: v1.1.0
  • VS Code version: Version: 1.72.2
  • Operating System: MacOS version 12.6

I made a stab -- unsuccessfully -- to debug this problem. I tried some simple things, like updating the versions of the spectral packages to the latest. I discovered that updating spectral-core and spectral path built fine but did not fix the problem.

However, when I updated spectral-ruleset-bundler (to 1.4.0), the build for the vscode extension fails.

> yarn --ignore-engines --silent webpack --mode production --stats errors-warnings --config ./server/webpack.config.js
WARNING in ./node_modules/@stoplight/spectral-ruleset-migrator/dist/requireResolve.js 5:15-22
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

ERROR in /Users/Mike/Projects/stoplightio/vscode-spectral/server/src/linter.ts
./src/linter.ts 139:22-98
[tsl] ERROR in /Users/Mike/Projects/stoplightio/vscode-spectral/server/src/linter.ts(139,23)
      TS2345: Argument of type 'import("/Users/Mike/Projects/stoplightio/vscode-spectral/server/node_modules/@stoplight/spectral-ruleset-bundler/node_modules/rollup/dist/rollup").Plugin' is not assignable to parameter of type 'import("/Users/Mike/Projects/stoplightio/vscode-spectral/server/node_modules/rollup/dist/rollup").Plugin'.
  Types of property 'buildEnd' are incompatible.
    Type 'ObjectHook<(this: PluginContext, err?: Error | undefined) => void | Promise<void>, { sequential?: boolean | undefined; }> | undefined' is not assignable to type '((this: PluginContext, err?: Error | undefined) => void | Promise<void>) | undefined'.
      Type '{ handler: (this: PluginContext, err?: Error | undefined) => void | Promise<void>; order?: "pre" | "post" | null | undefined; } & { sequential?: boolean | undefined; }' is not assignable to type '((this: PluginContext, err?: Error | undefined) => void | Promise<void>) | undefined'.

This seems suspicious since there does appear to be code in the ruleset bundler to handle commonjs:

import { commonjs } from '@stoplight/spectral-ruleset-bundler/plugins/commonjs';

I toyed around a bit and found that the spectral-ruleset-bundler dependency works at version 1.3.0 but broke with 1.3.1. I looked at the diff but I could not see how the changes in 1.3.1 would lead to the error above.

But I'm posting this here in hopes that it may trigger someone with a better understanding of this code to see what is going wrong and submit a fix.

I'm having the same issue.

I made another stab at updating the packages and this time it worked. I think the trick is to make sure that the rollup packages is at the same level as is used in ruleset-bundler.