-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print documentation links of rule #54
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a102de3
feat: support to print documentation link
mizdra 21a5574
deps: use patched package
mizdra 10531f5
test: add test for printing links
mizdra d305f3d
feat: print documentation links of plugin's rules
mizdra 3c5b8b7
refactor: `eslint.getRulesMetaForResults` may be undefined
mizdra 78c30f6
deps: update dependencies
mizdra 7661f29
refactor: remove type assertion
mizdra 740282b
refactor: refactor
mizdra d703a63
ci: fix cache key
mizdra File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { DisableTarget, Option } from './rules/add-disable-comment'; | |
import { ApplySuggestionOption } from './rules/apply-suggestion'; | ||
import { DisplayMode } from './types'; | ||
import { groupBy } from './util/array'; | ||
import { scanUsedPluginsFromResults } from './util/eslint'; | ||
import { notEmpty } from './util/filter'; | ||
|
||
function filterResultsByRuleId(results: ESLint.LintResult[], ruleIds: string[]): ESLint.LintResult[] { | ||
|
@@ -72,7 +73,6 @@ function createApplySuggestionESLint( | |
}); | ||
return eslint; | ||
} | ||
|
||
type CachedESLintOptions = { | ||
rulePaths?: string[]; | ||
extensions?: string[]; | ||
|
@@ -103,7 +103,18 @@ export class CachedESLint { | |
} | ||
|
||
printResults(results: ESLint.LintResult[]): void { | ||
const resultText = format(results); | ||
// get used plugins from `results` | ||
const plugins = scanUsedPluginsFromResults(results); | ||
|
||
// get `rulesMeta` from `results` | ||
const eslint = new ESLint({ | ||
...this.defaultOptions, | ||
overrideConfig: { plugins }, | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const rulesMeta: ESLint.LintResultData['rulesMeta'] | undefined = (eslint as any).getRulesMetaForResults?.(results); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
const resultText = format(results, { rulesMeta: rulesMeta ?? {} }); | ||
console.log(resultText); | ||
} | ||
|
||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref: Automattic/cli-table#149