diff --git a/spec/worker-helpers-spec.js b/spec/worker-helpers-spec.js index 049c18c1..fb40d493 100644 --- a/spec/worker-helpers-spec.js +++ b/spec/worker-helpers-spec.js @@ -213,6 +213,13 @@ describe('Worker Helpers', () => { }) describe('getRules', () => { + it('works with the getRules function introduced in ESLint v4.15.0', () => { + const cliEngine = { + getRules: () => 'foo' + } + expect(Helpers.getRules(cliEngine)).toBe('foo') + }) + it('works with the hidden linter in ESLint v4 before v4.15.0', () => { const cliEngine = { linter: { diff --git a/src/worker-helpers.js b/src/worker-helpers.js index 9c139d21..8d21fd21 100644 --- a/src/worker-helpers.js +++ b/src/worker-helpers.js @@ -192,6 +192,12 @@ export function getCLIEngineOptions(type, config, rules, filePath, fileDir, give * properties as the contents. */ export function getRules(cliEngine) { + // Pull the list of rules used directly from the CLIEngine + // Added in https://github.com/eslint/eslint/pull/9782 + if (Object.prototype.hasOwnProperty.call(cliEngine, 'getRules')) { + return cliEngine.getRules() + } + // Attempt to use the internal (undocumented) `linter` instance attached to // the CLIEngine to get the loaded rules (including plugin rules). // Added in ESLint v4