stoplightio / vscode-spectral

VS Code extension bringing the awesome Spectral JSON/YAML linter with OpenAPI/AsyncAPI support
https://marketplace.visualstudio.com/items?itemName=stoplight.spectral
Apache License 2.0
72 stars 23 forks source link

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

Open formulahendry opened 9 months ago

formulahendry commented 9 months ago

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:

Additional context .js should be optional in require:

dtolb commented 4 months ago

Same issue here for macos ...

It's not possible for me to update all the references to include the .js as the original ruleset is written in typescript and transpiled to JS.