This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use getRules and rule URL metadata where available
Refactor the worker to send the full metadata instead of just the fixable rules, allowing additional functionality to be implemented in the main package code. Rule gathering from the ESLint instance has been expanded to take advantage of the new `CLIEngine#getRules` method if it is available. The rule URL is now pulled directly from the metadata if it is available, falling back to the current method of using `eslint-rule-documentation` if the rule doesn't specify this for itself.
- Loading branch information
1 parent
c5a9d82
commit 757e82f
Showing
5 changed files
with
223 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use babel' | ||
|
||
import * as Helpers from '../src/helpers' | ||
|
||
fdescribe('The helper module', () => { | ||
describe('updateRules', () => { | ||
const ruleArray = [ | ||
['foo', { meta: { fixable: true } }], | ||
['bar', { meta: {} }] | ||
] | ||
|
||
it('adds new rules', () => { | ||
expect(Helpers.getRules()).toEqual(new Map()) | ||
Helpers.updateRules(ruleArray) | ||
expect(Helpers.getRules()).toEqual(new Map(ruleArray)) | ||
}) | ||
|
||
it('removes old rules', () => { | ||
Helpers.updateRules(ruleArray) | ||
expect(Helpers.getRules()).toEqual(new Map(ruleArray)) | ||
Helpers.updateRules([]) | ||
expect(Helpers.getRules()).toEqual(new Map()) | ||
}) | ||
|
||
it('updates the fixableRules list', () => { | ||
expect(Helpers.getFixableRules()).toEqual([]) | ||
Helpers.updateRules(ruleArray) | ||
expect(Helpers.getFixableRules()).toEqual(['foo']) | ||
}) | ||
}) | ||
|
||
describe('getRuleUrl', () => { | ||
it('works with rules that define their own URL', () => { | ||
Helpers.updateRules([['foo', { meta: { docs: { url: 'bar' } } }]]) | ||
expect(Helpers.getRuleUrl('foo')).toBe('bar') | ||
}) | ||
|
||
it('works with rules defined in eslint-rule-documentation', () => { | ||
const url = 'https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md' | ||
expect(Helpers.getRuleUrl('import/no-duplicates')).toBe(url) | ||
}) | ||
|
||
it('gives a fallback URL on how to add a rule URL', () => { | ||
const url = 'https://github.com/jfmengels/eslint-rule-documentation/blob/master/contributing.md' | ||
expect(Helpers.getRuleUrl('foo/bar')).toBe(url) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters