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

[Custom Functions] when importing CommonJS modules, lint does not work if you do not add `.js` in `require`

formulahendry opened this issue · comments

Describe the bug
When importing CommonJS modules, lint does not work if you do not add .js in require

To Reproduce

  1. Git clone from https://github.com/formulahendry/test
  2. Install vscode-spectral extension
  3. Open test-spectral\openapi.yaml file

Actual behavior
Lint does not show any error.

Expected behavior
Lint should show error message for message: aaa222: https://github.com/formulahendry/test/blob/91ea37278d2e316a74f016b06dea2b08f80e6bcb/test-spectral/openapi.yaml#L5

However,

If you run from CLI with the same rule: spectral lint .\test-spectral\openapi.yaml --ruleset .\test-spectral\test_rules\my-ruleset.yaml
Lint works!

In test-spectral\test_rules\functions\abc.js, if you add a .js in require: var { getMessages } = require("../function_utils/test.js");
Lint works!

the .js file extension should be optional when importing CommonJS modules.

Screenshots
1707378815548

Environment:

  • Extension version: 1.1.2
  • VS Code version: 1.86
  • Operating System: Windows 11

Additional context
.js should be optional in require: