redocly-vs-code icon indicating copy to clipboard operation
redocly-vs-code copied to clipboard

Lint plugins not supported?

Open duncanbeevers opened this issue 1 year ago • 11 comments

What happened?

First, the preconditions:

  • I created a sample OpenAPI document with a single operation, no operationId defined
  • Using a redocly.yaml configured with no plugins / custom lint rules, and no extends; I enforced a single rule operation-operationId: error
  • I linted the file using redocly-cli; redocly lint and verified the single error was reported
  • I opened the file in VS Code and verified the single error was reported & highlighted

Second, the error:

  • I modified the redocly.yaml to load a single custom plugin, and to use a single rule defined by the plugin
  • I linted the file using redocly-cli, and verified the operationId error and the custom rule's error were reported
  • I opened the file in VS Code and verified neither the original operationId error nor the custom rule's error were reported

I checked the Extension Host logs and didn't see any output for redocly-vs-code.

What should have happened instead?

Custom rules should be honored.

Minimal reproducible OpenAPI snippet

# api.yaml
openapi: 3.0.2
info:
  title: Example Schema
  version: '1.0'
paths:
  /user:
    get:
      responses:
        '200':
          description: OK
# redocly.yaml
apis:
  example:
    root: ./api.yaml
plugins:
  - .redocly/rules.js
rules:
  operation-operationId: error
  custom/operation-eov-operation-handler: error
// .redocly/rules.js
const operationEovHandler = () => {
  return {
    Operation: {
      enter: (operation, context) => {
        if (!operation['x-eov-operation-handler']) {
          context.report({
            message: 'Operation must have x-eov-operation-handler',
          });
        }
      }
    }
  };
};

module.exports = function () {
  return {
    id: 'custom',
    rules: {
      oas3: {
        'operation-eov-operation-handler': operationEovHandler
      }
    }
  };
};

Screenshots

No plugin With plugin
No plugin With plugin
Image

Using @redocly/cli @ 1.25.11 Using redocly-vs-code @ 0.5.1

duncanbeevers avatar Nov 07 '24 21:11 duncanbeevers

This is a regression bug. Thanks for reporting it! Meanwhile you can use a version prior to v0.5.

tatomyr avatar Nov 12 '24 14:11 tatomyr

here's my contribution of the error log from vsc.

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Error: Failed to load plugin "./linting/plugins/index.js": Cannot find module './linting/plugins/index.js'
Require stack:
- c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js

Error: Cannot find module './linting/plugins/index.js'
Require stack:
- c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1232:15)
    at Function.resolve (node:internal/modules/helpers:190:19)
    at r (c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:129:922)
    at c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:132:274
    at Array.map (<anonymous>)
    at SM (c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:132:97)
    at PM (c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:132:3410)
    at R7 (c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:132:4245)
    at Fye (c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:129:582)
    at r (c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:130:78)
    at c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:132:274
    at Array.map (<anonymous>)
    at SM (c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:132:97)
    at PM (c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:132:3410)
    at R7 (c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:132:4245)
    at Fye (c:\Users\fieljere\.vscode\extensions\redocly.openapi-vs-code-0.5.2\out\server\src\server.js:129:582)
|   .redocly.lint-ignore.yaml
|   redocly.yaml
|
+---linting
|   \---plugins
|       |   index.js
|       |
|       \---rules
|               ...
# redocly.yaml
plugins:
  - './linting/plugins/index.js'

jeremyfiel avatar Nov 15 '24 21:11 jeremyfiel

@duncanbeevers @jeremyfiel could you confirm it is fixed in v0.5.3?

tatomyr avatar Nov 20 '24 15:11 tatomyr

@tatomyr I verified this is fixed for me in 0.5.3.

Image

duncanbeevers avatar Nov 20 '24 15:11 duncanbeevers

@duncanbeevers which extension provides the inline errors?

jeremyfiel avatar Nov 20 '24 15:11 jeremyfiel

not fixed for me

I'm on windows 11

Image

jeremyfiel avatar Nov 20 '24 16:11 jeremyfiel

Hmm, that's strange. What version did it start failing on Windows?

tatomyr avatar Nov 20 '24 19:11 tatomyr

not sure. i can try loading prior versions to narrow it down.. will let you know

jeremyfiel avatar Nov 20 '24 20:11 jeremyfiel

seems to start with 0.5.0

Release 0.5.0 (2024-10-23) Features Reused the @redocly/openapi-language-server package. Updated the openapi-core package to 1.25.8.

jeremyfiel avatar Nov 20 '24 20:11 jeremyfiel

Thanks. Will look into that.

tatomyr avatar Nov 21 '24 09:11 tatomyr

Still need help for windows users.

jeremyfiel avatar Mar 20 '25 18:03 jeremyfiel

gentle reminder for Windows users.

  • should be tested for both plugins and extends keywords.

jeremyfiel avatar Apr 03 '25 19:04 jeremyfiel

which extension provides the inline errors?

@jeremyfiel That comes from the errorlens extension.

duncanbeevers avatar Apr 03 '25 20:04 duncanbeevers

Cool. will check it out

jeremyfiel avatar Apr 03 '25 20:04 jeremyfiel

Should be fixed in v0.6.2.

tatomyr avatar May 12 '25 14:05 tatomyr