Having trouble with "extends" and finding functions when using JS API for Spectral

Howdy, I have got a JSON style set of rules that have worked for me when using the spectral CLI but I can’t get them to work when using the JS API directly. The docs are pretty light around how the JS API works so I was hoping someone here could steer me in the right direction.

Here is my ruleset: https://gist.github.com/Jaredk3nt/6cf890fd26a77fced3dd602f11607c0e

I have tried using setRuleset with my json ruleset

const { Spectral } = require('@stoplight/spectral');
const {
  getLocationForJsonPath,
  parseWithPointers
} = require("@stoplight/yaml");
const ruleset = require("./my-rules.json");

const spectral = new Spectral();
spectral.setRuleset(ruleset);

function validate(spec) {
    return spectral
      .run({
        getLocationForJsonPath,
        parsed: parseWithPointers(spec)
      })
      .then(console.log);
}

This led me to errors around my custom defined functions as well as functions used in the oas2 rules I have turned on:

Encountered error when running rule 'oas2-schema' on node at path '$':
TypeError: Cannot read property 'function' of undefined
Encountered error when running rule 'info-description' on node at path '$':
TypeError: Cannot read property 'function' of undefined
Encountered error when running rule 'operation-description' on node at path '$':
TypeError: Cannot read property 'function' of undefined
Function parameterNamesCamelCase not found. Called by rule parameter-names-camel-case.
Function definitionsCamelCase not found. Called by rule definitions-camel-case.
Function responseCodeValidation not found. Called by rule response-code-validation.
Function requestIdHeaderValidation not found. Called by rule request-id-header-validation.

(I have tried this with my functions defined in a folder called /functions that works for the CLI)

I also tried loading the spectral:oas2 ruleset along with mine which runs without any errors, but this blasts my ruleset entirely and just uses the generic oas2 ruleset:

const { Spectral, isOpenApiv2 } = require("@stoplight/spectral");
const {
  getLocationForJsonPath,
  parseWithPointers
} = require("@stoplight/yaml");

const ruleset = require("./my-rules.json");

const spectral = new Spectral();
spectral.setRuleset(ruleset);
spectral.registerFormat("oas2", isOpenApiv2);

function validate(spec) {
  return spectral.loadRuleset("spectral:oas2").then(() => {
    return spectral
      .run({
        getLocationForJsonPath,
        parsed: parseWithPointers(spec)
      })
      .then(console.log);
  });
}

I am sure there is something that I am missing or that is not in the docs that will support this since the CLI works just fine with the same ruleset and functions. Thanks for any help!

@jkjones.dev I’d recommend taking this to the Spectral Github repository. The Spectral developers should have a much better idea of what’s going on here.