Skip to content

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

@formulahendry

Description

@formulahendry

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions