-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from mizdra/print-documentation-link
Print documentation links of rule
- Loading branch information
Showing
7 changed files
with
118 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ESLint } from 'eslint'; | ||
import { unique } from './array'; | ||
import { notEmpty } from './filter'; | ||
|
||
/** `results` 内で使われているプラグインの名前のリストを洗い出して返す */ | ||
export function scanUsedPluginsFromResults(results: ESLint.LintResult[]): string[] { | ||
const plugins = results | ||
.flatMap((result) => result.messages) // messages: Linter.LintMessage[] | ||
.map((message) => message.ruleId) // ruleIds: (string | undefined)[] | ||
.filter(notEmpty) // ruleIds: string[] | ||
.map((ruleId) => { | ||
const parts = ruleId.split('/'); | ||
if (parts.length === 1) return undefined; // ex: 'rule-a' | ||
if (parts.length === 2) return parts[0]; // ex: 'plugin/rule-a' | ||
if (parts.length === 3) return `${parts[0]}/${parts[1]}`; // ex: '@scoped/plugin/rule-a' | ||
return undefined; // invalid ruleId | ||
}) // plugins: string[] | ||
.filter(notEmpty); | ||
return unique(plugins); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ESLint } from 'eslint'; | ||
import { scanUsedPluginsFromResults } from '../../src/util/eslint'; | ||
import { fakeLintMessage, fakeLintResult } from '../test-util/eslint'; | ||
|
||
test('scanUsedPluginsFromResults', () => { | ||
const results: ESLint.LintResult[] = [ | ||
fakeLintResult({ | ||
messages: [ | ||
fakeLintMessage({ ruleId: 'rule', severity: 2 }), | ||
fakeLintMessage({ ruleId: 'plugin/rule', severity: 2 }), | ||
fakeLintMessage({ ruleId: '@scoped/plugin/rule', severity: 2 }), | ||
fakeLintMessage({ ruleId: 'invalid/@scoped/plugin/rule', severity: 2 }), | ||
], | ||
}), | ||
]; | ||
expect(scanUsedPluginsFromResults(results)).toStrictEqual(['plugin', '@scoped/plugin']); | ||
}); |
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