Repository: stoplightio/spectral
Pull request #1470 (2021-01-12 15:08:02)

chore: split actual rulesets and ruleset core logic
Extracted from https://github.com/stoplightio/spectral/pull/1465

**Checklist**

- [x] Tests added / updated
- [x] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No



Patch:
diff --git a/src/cli/commands/lint.ts b/src/cli/commands/lint.ts
index 2a6d346a..eeb5da89 100644
--- a/src/cli/commands/lint.ts
+++ b/src/cli/commands/lint.ts
@@ -3,7 +3,7 @@ import { pick } from 'lodash';
 import { ReadStream } from 'tty';
 import { CommandModule, showHelp } from 'yargs';
 
-import { getDiagnosticSeverity } from '../../rulesets/severity';
+import { getDiagnosticSeverity } from '../../ruleset';
 import { IRuleResult } from '../../types';
 import { FailSeverity, ILintConfig, OutputFormat } from '../../types/config';
 import { lint } from '../services/linter';
diff --git a/src/cli/services/linter/utils/getRuleset.ts b/src/cli/services/linter/utils/getRuleset.ts
index ed25a0c1..224297b0 100644
--- a/src/cli/services/linter/utils/getRuleset.ts
+++ b/src/cli/services/linter/utils/getRuleset.ts
@@ -1,7 +1,7 @@
 import { isAbsolute, resolve } from '@stoplight/path';
 import { Optional } from '@stoplight/types';
-import { readRuleset } from '../../../../rulesets';
-import { getDefaultRulesetFile } from '../../../../rulesets/loader';
+import { readRuleset } from '../../../../ruleset';
+import { getDefaultRulesetFile } from '../../../../ruleset/utils';
 import { IRuleset } from '../../../../types/ruleset';
 import { KNOWN_RULESETS } from '../../../../formats';
 
diff --git a/src/rule.ts b/src/rule.ts
index d43bcaa2..d53f7073 100644
--- a/src/rule.ts
+++ b/src/rule.ts
@@ -2,7 +2,7 @@ import { Optional } from '@stoplight/types';
 import { JSONPathExpression } from 'nimma';
 
 import { IDocument } from './document';
-import { DEFAULT_SEVERITY_LEVEL, getDiagnosticSeverity } from './rulesets/severity';
+import { DEFAULT_SEVERITY_LEVEL, getDiagnosticSeverity } from './ruleset/severity';
 import { IGivenNode, IRule, IThen, SpectralDiagnosticSeverity } from './types';
 import { hasIntersectingElement } from './utils';
 
diff --git a/src/rulesets/__tests__/validation.test.ts b/src/ruleset/__tests__/validation.test.ts
similarity index 100%
rename from src/rulesets/__tests__/validation.test.ts
rename to src/ruleset/__tests__/validation.test.ts
diff --git a/src/ruleset/index.ts b/src/ruleset/index.ts
new file mode 100644
index 00000000..f99d2771
--- /dev/null
+++ b/src/ruleset/index.ts
@@ -0,0 +1,5 @@
+export * from './mergers';
+export { readRuleset, IRulesetReadOptions } from './readRuleset';
+export { assertValidRuleset, ValidationError } from './validation';
+export { compileExportedFunction, setFunctionContext } from './utils/evaluators';
+export { getDiagnosticSeverity } from './severity';
diff --git a/src/rulesets/mergers/__tests__/exceptions.test.ts b/src/ruleset/mergers/__tests__/exceptions.test.ts
similarity index 100%
rename from src/rulesets/mergers/__tests__/exceptions.test.ts
rename to src/ruleset/mergers/__tests__/exceptions.test.ts
diff --git a/src/rulesets/mergers/__tests__/formats.test.ts b/src/ruleset/mergers/__tests__/formats.test.ts
similarity index 100%
rename from src/rulesets/mergers/__tests__/formats.test.ts
rename to src/ruleset/mergers/__tests__/formats.test.ts
diff --git a/src/rulesets/mergers/__tests__/functions.jest.test.ts b/src/ruleset/mergers/__tests__/functions.jest.test.ts
similarity index 100%
rename from src/rulesets/mergers/__tests__/functions.jest.test.ts
rename to src/ruleset/mergers/__tests__/functions.jest.test.ts
diff --git a/src/rulesets/mergers/__tests__/rules.test.ts b/src/ruleset/mergers/__tests__/rules.test.ts
similarity index 100%
rename from src/rulesets/mergers/__tests__/rules.test.ts
rename to src/ruleset/mergers/__tests__/rules.test.ts
diff --git a/src/rulesets/mergers/exceptions.ts b/src/ruleset/mergers/exceptions.ts
similarity index 100%
rename from src/rulesets/mergers/exceptions.ts
rename to src/ruleset/mergers/exceptions.ts
diff --git a/src/rulesets/mergers/formats.ts b/src/ruleset/mergers/formats.ts
similarity index 100%
rename from src/rulesets/mergers/formats.ts
rename to src/ruleset/mergers/formats.ts
diff --git a/src/rulesets/mergers/functions.ts b/src/ruleset/mergers/functions.ts
similarity index 100%
rename from src/rulesets/mergers/functions.ts
rename to src/ruleset/mergers/functions.ts
diff --git a/src/rulesets/mergers/index.ts b/src/ruleset/mergers/index.ts
similarity index 100%
rename from src/rulesets/mergers/index.ts
rename to src/ruleset/mergers/index.ts
diff --git a/src/rulesets/mergers/rules.ts b/src/ruleset/mergers/rules.ts
similarity index 100%
rename from src/rulesets/mergers/rules.ts
rename to src/ruleset/mergers/rules.ts
diff --git a/src/rulesets/reader.ts b/src/ruleset/readRuleset.ts
similarity index 99%
rename from src/rulesets/reader.ts
rename to src/ruleset/readRuleset.ts
index 8b1923c3..cb12fc80 100644
--- a/src/rulesets/reader.ts
+++ b/src/ruleset/readRuleset.ts
@@ -5,7 +5,7 @@ import { Optional } from '@stoplight/types';
 import { readFile, readParsable } from '../fs/reader';
 import { createHttpAndFileResolver, IHttpAndFileResolverOptions } from '../resolvers/http-and-file';
 import { FileRulesetSeverity, IRuleset, RulesetFunctionCollection } from '../types/ruleset';
-import { findFile, isNPMSource } from './finder';
+import { findFile, isNPMSource } from './utils';
 import { mergeFormats, mergeFunctions, mergeRules } from './mergers';
 import { mergeExceptions } from './mergers/exceptions';
 import { assertValidRuleset, isValidRule } from './validation';
diff --git a/src/rulesets/evaluators.ts b/src/ruleset/utils/evaluators.ts
similarity index 97%
rename from src/rulesets/evaluators.ts
rename to src/ruleset/utils/evaluators.ts
index f8974d03..faef1ef5 100644
--- a/src/rulesets/evaluators.ts
+++ b/src/ruleset/utils/evaluators.ts
@@ -1,8 +1,8 @@
 import { join, stripRoot } from '@stoplight/path';
 import { Dictionary, Optional } from '@stoplight/types';
 import { isObject } from 'lodash';
-import { IFunction, JSONSchema } from '../types';
-import { decorateIFunctionWithSchemaValidation } from './validation';
+import { decorateIFunctionWithSchemaValidation } from '../validation';
+import { JSONSchema, IFunction } from '../../types';
 
 export type CJSExport = Partial<{
   exports: object | ESCJSCompatibleExport;
diff --git a/src/rulesets/finder.ts b/src/ruleset/utils/findFile.ts
similarity index 86%
rename from src/rulesets/finder.ts
rename to src/ruleset/utils/findFile.ts
index 2c24121b..ab34b04e 100644
--- a/src/rulesets/finder.ts
+++ b/src/ruleset/utils/findFile.ts
@@ -1,10 +1,10 @@
 import * as path from '@stoplight/path';
 import * as fs from 'fs';
-import { RESOLVE_ALIASES, STATIC_ASSETS } from '../assets';
-import { NPM_PKG_ROOT, SPECTRAL_PKG_NAME, SPECTRAL_PKG_VERSION } from '../consts';
+import { RESOLVE_ALIASES, STATIC_ASSETS } from '../../assets';
+import { NPM_PKG_ROOT, SPECTRAL_PKG_NAME, SPECTRAL_PKG_VERSION } from '../../consts';
 
 // let's point at dist directory that has all relevant files (including custom functions) transpiled
-const SPECTRAL_SRC_ROOT = path.join(__dirname, '../../dist');
+const SPECTRAL_SRC_ROOT = path.join(__dirname, '../../../dist');
 
 function resolveSpectralVersion(pkg: string): string {
   return SPECTRAL_PKG_VERSION.length === 0
@@ -20,10 +20,6 @@ function resolveFromNPM(pkg: string): string {
   }
 }
 
-export function isNPMSource(src: string): boolean {
-  return src.startsWith(NPM_PKG_ROOT) && !src.includes(`${NPM_PKG_ROOT}${SPECTRAL_PKG_NAME}`); // we ignore spectral on purpose, since they undergo a slightly different process
-}
-
 async function resolveFromFS(from: string, to: string): Promise<string> {
   let targetPath: string;
 
diff --git a/src/rulesets/loader.ts b/src/ruleset/utils/getDefaultRulesetFile.ts
similarity index 75%
rename from src/rulesets/loader.ts
rename to src/ruleset/utils/getDefaultRulesetFile.ts
index bcb0aaf5..47187983 100644
--- a/src/rulesets/loader.ts
+++ b/src/ruleset/utils/getDefaultRulesetFile.ts
@@ -1,9 +1,6 @@
 import { join } from '@stoplight/path';
 import * as fs from 'fs';
-
-const DEFAULT_RULESET_FILE = /^\.?spectral\.(?:ya?ml|json)$/;
-
-export const isDefaultRulesetFile = (uri: string) => DEFAULT_RULESET_FILE.test(uri);
+import { isDefaultRulesetFile } from './isDefaultRulesetFile';
 
 export const getDefaultRulesetFile = (directory: string): Promise<string | null> => {
   return new Promise(resolve => {
diff --git a/src/ruleset/utils/index.ts b/src/ruleset/utils/index.ts
new file mode 100644
index 00000000..50235717
--- /dev/null
+++ b/src/ruleset/utils/index.ts
@@ -0,0 +1,5 @@
+export * from './evaluators';
+export * from './findFile';
+export * from './getDefaultRulesetFile';
+export * from './isDefaultRulesetFile';
+export * from './isNPMSource';
diff --git a/src/ruleset/utils/isDefaultRulesetFile.ts b/src/ruleset/utils/isDefaultRulesetFile.ts
new file mode 100644
index 00000000..a6e77924
--- /dev/null
+++ b/src/ruleset/utils/isDefaultRulesetFile.ts
@@ -0,0 +1,3 @@
+const DEFAULT_RULESET_FILE = /^\.?spectral\.(?:ya?ml|json)$/;
+
+export const isDefaultRulesetFile = (uri: string) => DEFAULT_RULESET_FILE.test(uri);
diff --git a/src/ruleset/utils/isNPMSource.ts b/src/ruleset/utils/isNPMSource.ts
new file mode 100644
index 00000000..6c89608e
--- /dev/null
+++ b/src/ruleset/utils/isNPMSource.ts
@@ -0,0 +1,5 @@
+import { NPM_PKG_ROOT, SPECTRAL_PKG_NAME } from '../../consts';
+
+export function isNPMSource(src: string): boolean {
+  return src.startsWith(NPM_PKG_ROOT) && !src.includes(`${NPM_PKG_ROOT}${SPECTRAL_PKG_NAME}`); // we ignore spectral on purpose, since they undergo a slightly different process
+}
diff --git a/src/rulesets/index.ts b/src/rulesets/index.ts
deleted file mode 100644
index 9a5e2540..00000000
--- a/src/rulesets/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export * from './mergers';
-export { readRuleset } from './reader';
-export { assertValidRuleset } from './validation';
diff --git a/src/runner/lintNode.ts b/src/runner/lintNode.ts
index de54effe..0e312698 100644
--- a/src/runner/lintNode.ts
+++ b/src/runner/lintNode.ts
@@ -3,12 +3,11 @@ import { get } from 'lodash';
 
 import { Document } from '../document';
 import { Rule } from '../rule';
-import { IMessageVars, message } from '../rulesets/message';
-import { getDiagnosticSeverity } from '../rulesets/severity';
+import { getDiagnosticSeverity } from '../ruleset/severity';
 import { IFunctionResult, IFunctionValues, IGivenNode } from '../types';
 import { decodeSegmentFragment, getClosestJsonPath, printPath, PrintStyle } from '../utils';
 import { IRunnerInternalContext } from './types';
-import { getLintTargets, ExceptionLocation, isAKnownException } from './utils';
+import { getLintTargets, ExceptionLocation, isAKnownException, IMessageVars, message } from './utils';
 
 export const lintNode = (
   context: IRunnerInternalContext,
diff --git a/src/runner/utils/index.ts b/src/runner/utils/index.ts
index c2b28a37..6ae63df5 100644
--- a/src/runner/utils/index.ts
+++ b/src/runner/utils/index.ts
@@ -1,4 +1,5 @@
 export * from './arePathsEqual';
 export * from './getLintTargets';
 export * from './isAKnownException';
+export * from './message';
 export * from './pivotExceptions';
diff --git a/src/rulesets/message.ts b/src/runner/utils/message.ts
similarity index 95%
rename from src/rulesets/message.ts
rename to src/runner/utils/message.ts
index 4ca2718e..5e39b81b 100644
--- a/src/rulesets/message.ts
+++ b/src/runner/utils/message.ts
@@ -1,6 +1,6 @@
 import { Segment } from '@stoplight/types';
 import { isObject } from 'lodash';
-import { Replacer } from '../utils/replacer';
+import { Replacer } from '../../utils/replacer';
 
 export interface IMessageVars {
   property: Segment;
diff --git a/src/runner/utils/pivotExceptions.ts b/src/runner/utils/pivotExceptions.ts
index 66b67761..6c6d19d2 100644
--- a/src/runner/utils/pivotExceptions.ts
+++ b/src/runner/utils/pivotExceptions.ts
@@ -1,8 +1,8 @@
 import { extractPointerFromRef, extractSourceFromRef, pointerToPath } from '@stoplight/json';
 import { Dictionary, JsonPath } from '@stoplight/types';
-import { InvalidUriError } from '../../rulesets/mergers/exceptions';
 import { RunRuleCollection } from '../../types';
 import { RulesetExceptionCollection } from '../../types/ruleset';
+import { InvalidUriError } from '../../ruleset/mergers/exceptions';
 
 export type ExceptionLocation =
   | {
diff --git a/src/spectral.ts b/src/spectral.ts
index 0b21462c..a155c10b 100644
--- a/src/spectral.ts
+++ b/src/spectral.ts
@@ -13,10 +13,14 @@ import * as Parsers from './parsers';
 import request from './request';
 import { createHttpAndFileResolver } from './resolvers/http-and-file';
 import { OptimizedRule, Rule } from './rule';
-import { readRuleset } from './rulesets';
-import { compileExportedFunction, setFunctionContext } from './rulesets/evaluators';
-import { mergeExceptions } from './rulesets/mergers/exceptions';
-import { IRulesetReadOptions } from './rulesets/reader';
+import {
+  compileExportedFunction,
+  IRulesetReadOptions,
+  setFunctionContext,
+  readRuleset,
+  getDiagnosticSeverity,
+} from './ruleset';
+import { mergeExceptions } from './ruleset/mergers/exceptions';
 import { Runner, RunnerRuntime } from './runner';
 import {
   FormatLookup,
@@ -35,7 +39,6 @@ import {
 import { IParserOptions, IRuleset, RulesetExceptionCollection } from './types/ruleset';
 import { ComputeFingerprintFunc, defaultComputeResultFingerprint, empty, isNimmaEnvVariableSet } from './utils';
 import { generateDocumentWideResult } from './utils/generateDocumentWideResult';
-import { getDiagnosticSeverity } from './rulesets/severity';
 import { DEFAULT_PARSER_OPTIONS } from './consts';
 
 memoize.Cache = WeakMap;


Test patch:
diff --git a/src/__tests__/generate-assets.jest.test.ts b/src/__tests__/generate-assets.jest.test.ts
index c51bbfcd..351e4033 100644
--- a/src/__tests__/generate-assets.jest.test.ts
+++ b/src/__tests__/generate-assets.jest.test.ts
@@ -1,6 +1,6 @@
 import { existsSync, readFileSync } from 'fs';
 import { Spectral } from '../spectral';
-import { setFunctionContext } from '../rulesets/evaluators';
+import { setFunctionContext } from '../ruleset';
 import { functions } from '../functions';
 import oasDocumentSchema from '../rulesets/oas/functions/oasDocumentSchema';
 import { KNOWN_FORMATS } from '../formats';
diff --git a/src/__tests__/linter.jest.test.ts b/src/__tests__/linter.jest.test.ts
index 4148899a..2af8b4c2 100644
--- a/src/__tests__/linter.jest.test.ts
+++ b/src/__tests__/linter.jest.test.ts
@@ -6,7 +6,7 @@ import * as path from 'path';
 import * as timers from 'timers';
 
 import { httpAndFileResolver } from '../resolvers/http-and-file';
-import { readRuleset } from '../rulesets';
+import { readRuleset } from '../ruleset';
 import { IFunctionResult, Spectral } from '../spectral';
 import { IRuleset, RulesetExceptionCollection } from '../types/ruleset';
 
diff --git a/src/cli/services/__tests__/linter.test.ts b/src/cli/services/__tests__/linter.test.ts
index 85edaaf2..1ae757d5 100644
--- a/src/cli/services/__tests__/linter.test.ts
+++ b/src/cli/services/__tests__/linter.test.ts
@@ -1,7 +1,7 @@
 import { join, resolve } from '@stoplight/path';
 import * as nock from 'nock';
 import * as yargs from 'yargs';
-import { ValidationError } from '../../../rulesets/validation';
+import { ValidationError } from '../../../ruleset/validation';
 import { ILintConfig } from '../../../types/config';
 import lintCommand from '../../commands/lint';
 import { lint } from '../linter';
diff --git a/src/rulesets/__tests__/__fixtures__/bar-extends-foo-ruleset.json b/src/ruleset/__tests__/__fixtures__/bar-extends-foo-ruleset.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/bar-extends-foo-ruleset.json
rename to src/ruleset/__tests__/__fixtures__/bar-extends-foo-ruleset.json
diff --git a/src/rulesets/__tests__/__fixtures__/casing-rules.json b/src/ruleset/__tests__/__fixtures__/casing-rules.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/casing-rules.json
rename to src/ruleset/__tests__/__fixtures__/casing-rules.json
diff --git a/src/rulesets/__tests__/__fixtures__/customFunctions/bar.js b/src/ruleset/__tests__/__fixtures__/customFunctionsRuleset/customFunctions/bar.js
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/customFunctions/bar.js
rename to src/ruleset/__tests__/__fixtures__/customFunctionsRuleset/customFunctions/bar.js
diff --git a/src/rulesets/__tests__/__fixtures__/customFunctions/truthy.js b/src/ruleset/__tests__/__fixtures__/customFunctionsRuleset/customFunctions/truthy.js
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/customFunctions/truthy.js
rename to src/ruleset/__tests__/__fixtures__/customFunctionsRuleset/customFunctions/truthy.js
diff --git a/src/rulesets/__tests__/__fixtures__/customFunctionsRuleset/ruleset.json b/src/ruleset/__tests__/__fixtures__/customFunctionsRuleset/ruleset.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/customFunctionsRuleset/ruleset.json
rename to src/ruleset/__tests__/__fixtures__/customFunctionsRuleset/ruleset.json
diff --git a/src/rulesets/__tests__/__fixtures__/documentation-url-ruleset.json b/src/ruleset/__tests__/__fixtures__/documentation-url-ruleset.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/documentation-url-ruleset.json
rename to src/ruleset/__tests__/__fixtures__/documentation-url-ruleset.json
diff --git a/src/rulesets/__tests__/__fixtures__/empty.json b/src/ruleset/__tests__/__fixtures__/empty.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/empty.json
rename to src/ruleset/__tests__/__fixtures__/empty.json
diff --git a/src/rulesets/__tests__/__fixtures__/exceptions/inheriting.yaml b/src/ruleset/__tests__/__fixtures__/exceptions/inheriting.yaml
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/exceptions/inheriting.yaml
rename to src/ruleset/__tests__/__fixtures__/exceptions/inheriting.yaml
diff --git a/src/rulesets/__tests__/__fixtures__/exceptions/invalid.yaml b/src/ruleset/__tests__/__fixtures__/exceptions/invalid.yaml
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/exceptions/invalid.yaml
rename to src/ruleset/__tests__/__fixtures__/exceptions/invalid.yaml
diff --git a/src/rulesets/__tests__/__fixtures__/exceptions/simple.yaml b/src/ruleset/__tests__/__fixtures__/exceptions/simple.yaml
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/exceptions/simple.yaml
rename to src/ruleset/__tests__/__fixtures__/exceptions/simple.yaml
diff --git a/src/rulesets/__tests__/__fixtures__/exceptions/standalone.yaml b/src/ruleset/__tests__/__fixtures__/exceptions/standalone.yaml
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/exceptions/standalone.yaml
rename to src/ruleset/__tests__/__fixtures__/exceptions/standalone.yaml
diff --git a/src/rulesets/__tests__/__fixtures__/foo-extends-bar-ruleset.json b/src/ruleset/__tests__/__fixtures__/foo-extends-bar-ruleset.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/foo-extends-bar-ruleset.json
rename to src/ruleset/__tests__/__fixtures__/foo-extends-bar-ruleset.json
diff --git a/src/rulesets/__tests__/__fixtures__/foo-ruleset.json b/src/ruleset/__tests__/__fixtures__/foo-ruleset.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/foo-ruleset.json
rename to src/ruleset/__tests__/__fixtures__/foo-ruleset.json
diff --git a/src/rulesets/__tests__/__fixtures__/formats/oas2.json b/src/ruleset/__tests__/__fixtures__/formats/oas2.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/formats/oas2.json
rename to src/ruleset/__tests__/__fixtures__/formats/oas2.json
diff --git a/src/rulesets/__tests__/__fixtures__/formats/oas3.json b/src/ruleset/__tests__/__fixtures__/formats/oas3.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/formats/oas3.json
rename to src/ruleset/__tests__/__fixtures__/formats/oas3.json
diff --git a/src/rulesets/__tests__/__fixtures__/formats/ruleset.json b/src/ruleset/__tests__/__fixtures__/formats/ruleset.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/formats/ruleset.json
rename to src/ruleset/__tests__/__fixtures__/formats/ruleset.json
diff --git a/src/rulesets/__tests__/__fixtures__/functions/foo.cjs.js b/src/ruleset/__tests__/__fixtures__/functions/foo.cjs.js
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/functions/foo.cjs.js
rename to src/ruleset/__tests__/__fixtures__/functions/foo.cjs.js
diff --git a/src/rulesets/__tests__/__fixtures__/invalid-ruleset.json b/src/ruleset/__tests__/__fixtures__/invalid-ruleset.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/invalid-ruleset.json
rename to src/ruleset/__tests__/__fixtures__/invalid-ruleset.json
diff --git a/src/rulesets/__tests__/__fixtures__/npm/plain.json b/src/ruleset/__tests__/__fixtures__/npm/plain.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/npm/plain.json
rename to src/ruleset/__tests__/__fixtures__/npm/plain.json
diff --git a/src/rulesets/__tests__/__fixtures__/npm/versioned.json b/src/ruleset/__tests__/__fixtures__/npm/versioned.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/npm/versioned.json
rename to src/ruleset/__tests__/__fixtures__/npm/versioned.json
diff --git a/src/rulesets/__tests__/__fixtures__/parser-options-ruleset.json b/src/ruleset/__tests__/__fixtures__/parser-options-ruleset.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/parser-options-ruleset.json
rename to src/ruleset/__tests__/__fixtures__/parser-options-ruleset.json
diff --git a/src/rulesets/__tests__/__fixtures__/ruleset-with-merge-keys.yaml b/src/ruleset/__tests__/__fixtures__/ruleset-with-merge-keys.yaml
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/ruleset-with-merge-keys.yaml
rename to src/ruleset/__tests__/__fixtures__/ruleset-with-merge-keys.yaml
diff --git a/src/rulesets/__tests__/__fixtures__/ruleset-with-missing-functions.json b/src/ruleset/__tests__/__fixtures__/ruleset-with-missing-functions.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/ruleset-with-missing-functions.json
rename to src/ruleset/__tests__/__fixtures__/ruleset-with-missing-functions.json
diff --git a/src/rulesets/__tests__/__fixtures__/self-extending-ruleset.json b/src/ruleset/__tests__/__fixtures__/self-extending-ruleset.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/self-extending-ruleset.json
rename to src/ruleset/__tests__/__fixtures__/self-extending-ruleset.json
diff --git a/src/rulesets/__tests__/__fixtures__/severity/all.json b/src/ruleset/__tests__/__fixtures__/severity/all.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/severity/all.json
rename to src/ruleset/__tests__/__fixtures__/severity/all.json
diff --git a/src/rulesets/__tests__/__fixtures__/severity/implicit.json b/src/ruleset/__tests__/__fixtures__/severity/implicit.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/severity/implicit.json
rename to src/ruleset/__tests__/__fixtures__/severity/implicit.json
diff --git a/src/rulesets/__tests__/__fixtures__/severity/off.json b/src/ruleset/__tests__/__fixtures__/severity/off.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/severity/off.json
rename to src/ruleset/__tests__/__fixtures__/severity/off.json
diff --git a/src/rulesets/__tests__/__fixtures__/severity/recommended.json b/src/ruleset/__tests__/__fixtures__/severity/recommended.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/severity/recommended.json
rename to src/ruleset/__tests__/__fixtures__/severity/recommended.json
diff --git a/src/rulesets/__tests__/__fixtures__/severity/shared.json b/src/ruleset/__tests__/__fixtures__/severity/shared.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/severity/shared.json
rename to src/ruleset/__tests__/__fixtures__/severity/shared.json
diff --git a/src/rulesets/__tests__/__fixtures__/valid-flat-ruleset-2.json b/src/ruleset/__tests__/__fixtures__/valid-flat-ruleset-2.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/valid-flat-ruleset-2.json
rename to src/ruleset/__tests__/__fixtures__/valid-flat-ruleset-2.json
diff --git a/src/rulesets/__tests__/__fixtures__/valid-flat-ruleset.json b/src/ruleset/__tests__/__fixtures__/valid-flat-ruleset.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/valid-flat-ruleset.json
rename to src/ruleset/__tests__/__fixtures__/valid-flat-ruleset.json
diff --git a/src/rulesets/__tests__/reader.jest.test.ts b/src/ruleset/__tests__/reader.jest.test.ts
similarity index 99%
rename from src/rulesets/__tests__/reader.jest.test.ts
rename to src/ruleset/__tests__/reader.jest.test.ts
index cb41bc64..f53c8188 100644
--- a/src/rulesets/__tests__/reader.jest.test.ts
+++ b/src/ruleset/__tests__/reader.jest.test.ts
@@ -3,7 +3,7 @@ import { DiagnosticSeverity } from '@stoplight/types';
 import * as fs from 'fs';
 import * as nock from 'nock';
 import { RuleCollection, Spectral } from '../../spectral';
-import { readRuleset } from '../reader';
+import { readRuleset } from '../readRuleset';
 
 jest.mock('fs');
 jest.mock('nanoid/non-secure');
diff --git a/src/rulesets/__tests__/reader.karma.test.ts b/src/ruleset/__tests__/reader.karma.test.ts
similarity index 96%
rename from src/rulesets/__tests__/reader.karma.test.ts
rename to src/ruleset/__tests__/reader.karma.test.ts
index 01e1aae5..e87fdc45 100644
--- a/src/rulesets/__tests__/reader.karma.test.ts
+++ b/src/ruleset/__tests__/reader.karma.test.ts
@@ -1,6 +1,6 @@
 import { FetchMockSandbox } from 'fetch-mock';
 import { Spectral } from '../../spectral';
-import { readRuleset } from '../reader';
+import { readRuleset } from '../readRuleset';
 
 declare const fetch: FetchMockSandbox;
 
diff --git a/src/rulesets/__tests__/reader.test.ts b/src/ruleset/__tests__/reader.test.ts
similarity index 95%
rename from src/rulesets/__tests__/reader.test.ts
rename to src/ruleset/__tests__/reader.test.ts
index b1c23b8d..f29fe916 100644
--- a/src/rulesets/__tests__/reader.test.ts
+++ b/src/ruleset/__tests__/reader.test.ts
@@ -1,4 +1,4 @@
-import { readRuleset } from '../reader';
+import { readRuleset } from '../readRuleset';
 
 describe('Rulesets reader', () => {
   it('should resolve oas2-schema', async () => {
diff --git a/src/rulesets/__tests__/severity.test.ts b/src/ruleset/__tests__/severity.test.ts
similarity index 97%
rename from src/rulesets/__tests__/severity.test.ts
rename to src/ruleset/__tests__/severity.test.ts
index 5c5ec5f2..b88b81fc 100644
--- a/src/rulesets/__tests__/severity.test.ts
+++ b/src/ruleset/__tests__/severity.test.ts
@@ -1,4 +1,4 @@
-import { DiagnosticSeverity } from '@stoplight/types/dist';
+import { DiagnosticSeverity } from '@stoplight/types';
 import { HumanReadableDiagnosticSeverity } from '../../types';
 import { FileRulesetSeverity } from '../../types/ruleset';
 import { DEFAULT_SEVERITY_LEVEL, getDiagnosticSeverity, getSeverityLevel } from '../severity';
diff --git a/src/rulesets/severity.ts b/src/ruleset/severity.ts
similarity index 100%
rename from src/rulesets/severity.ts
rename to src/ruleset/severity.ts
diff --git a/src/rulesets/__tests__/__fixtures__/foo.js b/src/ruleset/utils/__tests__/__fixtures__/foo.js
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/foo.js
rename to src/ruleset/utils/__tests__/__fixtures__/foo.js
diff --git a/src/rulesets/__tests__/__fixtures__/spectral.json b/src/ruleset/utils/__tests__/__fixtures__/spectral.json
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/spectral.json
rename to src/ruleset/utils/__tests__/__fixtures__/spectral.json
diff --git a/src/rulesets/__tests__/__fixtures__/yaml/.spectral.yaml b/src/ruleset/utils/__tests__/__fixtures__/yaml/.spectral.yaml
similarity index 100%
rename from src/rulesets/__tests__/__fixtures__/yaml/.spectral.yaml
rename to src/ruleset/utils/__tests__/__fixtures__/yaml/.spectral.yaml
diff --git a/src/rulesets/__tests__/evaluators.jest.test.ts b/src/ruleset/utils/__tests__/evaluators.jest.test.ts
similarity index 100%
rename from src/rulesets/__tests__/evaluators.jest.test.ts
rename to src/ruleset/utils/__tests__/evaluators.jest.test.ts
diff --git a/src/rulesets/__tests__/evaluators.karma.test.ts b/src/ruleset/utils/__tests__/evaluators.karma.test.ts
similarity index 100%
rename from src/rulesets/__tests__/evaluators.karma.test.ts
rename to src/ruleset/utils/__tests__/evaluators.karma.test.ts
diff --git a/src/rulesets/__tests__/evaluators.test.ts b/src/ruleset/utils/__tests__/evaluators.test.ts
similarity index 100%
rename from src/rulesets/__tests__/evaluators.test.ts
rename to src/ruleset/utils/__tests__/evaluators.test.ts
diff --git a/src/rulesets/__tests__/finder.jest.test.ts b/src/ruleset/utils/__tests__/findFile.jest.test.ts
similarity index 90%
rename from src/rulesets/__tests__/finder.jest.test.ts
rename to src/ruleset/utils/__tests__/findFile.jest.test.ts
index 04fda25d..9a163d59 100644
--- a/src/rulesets/__tests__/finder.jest.test.ts
+++ b/src/ruleset/utils/__tests__/findFile.jest.test.ts
@@ -1,10 +1,10 @@
 import * as path from '@stoplight/path';
-import { findFile } from '../finder';
+import { findFile } from '../findFile';
 
 describe('Rulesets finder', () => {
   it('should join relative path', () => {
-    return expect(findFile(__dirname, './finder.jest.test.ts')).resolves.toEqual(
-      path.join(__dirname, './finder.jest.test.ts'),
+    return expect(findFile(__dirname, './findFile.jest.test.ts')).resolves.toEqual(
+      path.join(__dirname, './findFile.jest.test.ts'),
     );
   });
 
diff --git a/src/rulesets/__tests__/finder.karma.test.ts b/src/ruleset/utils/__tests__/findFile.karma.test.ts
similarity index 95%
rename from src/rulesets/__tests__/finder.karma.test.ts
rename to src/ruleset/utils/__tests__/findFile.karma.test.ts
index bcaecb1a..2a8136f0 100644
--- a/src/rulesets/__tests__/finder.karma.test.ts
+++ b/src/ruleset/utils/__tests__/findFile.karma.test.ts
@@ -1,4 +1,4 @@
-import { findFile } from '../finder';
+import { findFile } from '../findFile';
 
 describe('Rulesets finder', () => {
   it('should point to unpkg.com if npm module', () => {
diff --git a/src/ruleset/utils/__tests__/getDefaultRulesetFile.jest.test.ts b/src/ruleset/utils/__tests__/getDefaultRulesetFile.jest.test.ts
new file mode 100644
index 00000000..f428e910
--- /dev/null
+++ b/src/ruleset/utils/__tests__/getDefaultRulesetFile.jest.test.ts
@@ -0,0 +1,17 @@
+import * as path from '@stoplight/path';
+import { getDefaultRulesetFile } from '../getDefaultRulesetFile';
+
+const ROOT = path.join(__dirname, './__fixtures__');
+
+describe('getDefaultRulesetFile util', () => {
+  test('should resolve with null if a default ruleset does not exist', () => {
+    return expect(getDefaultRulesetFile(path.join(ROOT, './empty'))).resolves.toBeNull();
+  });
+
+  test('should resolve with a path to found ruleset if there is any matching', async () => {
+    await expect(getDefaultRulesetFile(ROOT)).resolves.toEqual(path.join(ROOT, './spectral.json'));
+    await expect(getDefaultRulesetFile(path.join(ROOT, './yaml'))).resolves.toEqual(
+      path.join(ROOT, './yaml/.spectral.yaml'),
+    );
+  });
+});
diff --git a/src/rulesets/validation.ts b/src/ruleset/validation.ts
similarity index 100%
rename from src/rulesets/validation.ts
rename to src/ruleset/validation.ts
diff --git a/src/rulesets/__tests__/__fixtures__/customFunctionsRuleset/customFunctions/bar.js b/src/rulesets/__tests__/__fixtures__/customFunctionsRuleset/customFunctions/bar.js
deleted file mode 100644
index db866313..00000000
--- a/src/rulesets/__tests__/__fixtures__/customFunctionsRuleset/customFunctions/bar.js
+++ /dev/null
@@ -1,11 +0,0 @@
-module.exports = (targetVal, _opts, paths) => {
-  if (targetVal !== 'bar') {
-    return [
-      {
-        message: `${
-          paths.target ? paths.target.join('.') : 'property'
-        } does not equals "bar".`,
-      },
-    ];
-  }
-};
diff --git a/src/rulesets/__tests__/__fixtures__/customFunctionsRuleset/customFunctions/truthy.js b/src/rulesets/__tests__/__fixtures__/customFunctionsRuleset/customFunctions/truthy.js
deleted file mode 100644
index 27fe1c8d..00000000
--- a/src/rulesets/__tests__/__fixtures__/customFunctionsRuleset/customFunctions/truthy.js
+++ /dev/null
@@ -1,11 +0,0 @@
-module.exports = (targetVal, _opts, paths) => {
-  if (!targetVal) {
-    return [
-      {
-        message: `${
-          paths.target ? paths.target.join('.') : 'property'
-        } is not truthy`,
-      },
-    ];
-  }
-};
diff --git a/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/my-ruleset-recommended.json b/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/my-ruleset-recommended.json
deleted file mode 100644
index 9c704522..00000000
--- a/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/my-ruleset-recommended.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "extends": [["./my-ruleset.json", "recommended"]]
-}
diff --git a/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/my-ruleset.json b/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/my-ruleset.json
deleted file mode 100644
index 36a45660..00000000
--- a/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/my-ruleset.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "extends": [["./ruleset-c.json", "all"]]
-}
diff --git a/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/ruleset-a.json b/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/ruleset-a.json
deleted file mode 100644
index 1f5deb95..00000000
--- a/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/ruleset-a.json
+++ /dev/null
@@ -1,43 +0,0 @@
-{
-  "rules": {
-    "description-matches-stoplight": {
-      "message": "Description must contain Stoplight",
-      "given": "$.info",
-      "type": "style",
-      "recommended": true,
-      "severity": "error",
-      "then": {
-        "field": "description",
-        "function": "pattern",
-        "functionOptions": {
-          "match": "Stoplight"
-        }
-      }
-    },
-    "title-matches-stoplight": {
-      "message": "Title must contain Stoplight",
-      "given": "$.info",
-      "type": "style",
-      "then": {
-        "field": "title",
-        "function": "pattern",
-        "functionOptions": {
-          "match": "Stoplight"
-        }
-      }
-    },
-    "contact-name-matches-stoplight": {
-      "message": "Contact name must contain Stoplight",
-      "given": "$.info.contact",
-      "type": "style",
-      "recommended": false,
-      "then": {
-        "field": "name",
-        "function": "pattern",
-        "functionOptions": {
-          "match": "Stoplight"
-        }
-      }
-    }
-  }
-}
diff --git a/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/ruleset-b.json b/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/ruleset-b.json
deleted file mode 100644
index e577d214..00000000
--- a/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/ruleset-b.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "extends": "./ruleset-a.json"
-}
diff --git a/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/ruleset-c.json b/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/ruleset-c.json
deleted file mode 100644
index 6ec51ead..00000000
--- a/src/rulesets/__tests__/__fixtures__/inheritanceRulesets/ruleset-c.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "extends": [["./ruleset-b.json", "off"]]
-}
diff --git a/src/rulesets/__tests__/loader.jest.test.ts b/src/rulesets/__tests__/loader.jest.test.ts
deleted file mode 100644
index e378ee85..00000000
--- a/src/rulesets/__tests__/loader.jest.test.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import * as path from '@stoplight/path';
-import { getDefaultRulesetFile } from '../loader';
-
-const ROOT = path.join(__dirname, './__fixtures__');
-
-describe('ruleset loading', () => {
-  describe('getDefaultRulesetFile', () => {
-    test('should resolve with null if a default ruleset does not exist', () => {
-      return expect(getDefaultRulesetFile(path.join(ROOT, './empty'))).resolves.toBeNull();
-    });
-
-    test('should resolve with a path to found ruleset if there is any matching', async () => {
-      await expect(getDefaultRulesetFile(ROOT)).resolves.toEqual(path.join(ROOT, './spectral.json'));
-      await expect(getDefaultRulesetFile(path.join(ROOT, './yaml'))).resolves.toEqual(
-        path.join(ROOT, './yaml/.spectral.yaml'),
-      );
-    });
-  });
-});
diff --git a/src/rulesets/oas/functions/__tests__/oasDocumentSchema.test.ts b/src/rulesets/oas/functions/__tests__/oasDocumentSchema.test.ts
index 1ff4ec2f..7f88447d 100644
--- a/src/rulesets/oas/functions/__tests__/oasDocumentSchema.test.ts
+++ b/src/rulesets/oas/functions/__tests__/oasDocumentSchema.test.ts
@@ -1,13 +1,13 @@
 import { DiagnosticSeverity } from '@stoplight/types';
 import { isOpenApiv2, isOpenApiv3, RuleType, Spectral } from '../../../..';
 import { functions } from '../../../../functions';
-import { setFunctionContext } from '../../../evaluators';
 import { rules } from '../../index.json';
 import oasDocumentSchema, { prepareResults } from '../oasDocumentSchema';
 
 import { ErrorObject } from 'ajv';
 import * as oas2Schema from '../../schemas/schema.oas2.json';
 import * as oas3Schema from '../../schemas/schema.oas3.json';
+import { setFunctionContext } from '../../../../ruleset';
 
 describe('oasDocumentSchema', () => {
   let s: Spectral;
diff --git a/src/rulesets/__tests__/message.test.ts b/src/runner/utils/__tests__/message.test.ts
similarity index 100%
rename from src/rulesets/__tests__/message.test.ts
rename to src/runner/utils/__tests__/message.test.ts
diff --git a/src/runner/utils/__tests__/pivotExceptions.test.ts b/src/runner/utils/__tests__/pivotExceptions.test.ts
index f42707f3..11d5d9c6 100644
--- a/src/runner/utils/__tests__/pivotExceptions.test.ts
+++ b/src/runner/utils/__tests__/pivotExceptions.test.ts
@@ -1,8 +1,8 @@
 import { DiagnosticSeverity, Dictionary } from '@stoplight/types';
-import { InvalidUriError } from '../../../rulesets/mergers/exceptions';
 import { ExceptionLocation, pivotExceptions } from '../pivotExceptions';
 
 import { Rule } from '../../../rule';
+import { InvalidUriError } from '../../../ruleset/mergers/exceptions';
 
 describe('pivotExceptions', () => {
   let dummyRule: Rule;