Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Use CLIEngine#getRules when available
Browse files Browse the repository at this point in the history
Rule gathering from the ESLint instance has been expanded to take
advantage of the new `CLIEngine#getRules` method if it is available.
  • Loading branch information
Arcanemagus committed Jan 15, 2018
1 parent 2968c44 commit 69661f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spec/worker-helpers-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 6 additions & 0 deletions src/worker-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 69661f7

Please sign in to comment.