-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor rule modules and add component analyzer
- Loading branch information
Showing
112 changed files
with
1,635 additions
and
2,119 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/lit-analyzer/src/analyze/component-analyzer/component-analyzer.ts
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,26 @@ | ||
import { ComponentDefinition } from "web-component-analyzer"; | ||
import { LitAnalyzerContext } from "../lit-analyzer-context"; | ||
import { LitCodeFix } from "../types/lit-code-fix"; | ||
import { LitDiagnostic } from "../types/lit-diagnostic"; | ||
import { SourceFileRange } from "../types/range"; | ||
import { arrayDefined, arrayFlat } from "../util/array-util"; | ||
import { intersects } from "../util/range-util"; | ||
import { convertRuleDiagnosticToLitDiagnostic } from "../util/rule-diagnostic-util"; | ||
import { converRuleFixToLitCodeFix } from "../util/rule-fix-util"; | ||
|
||
export class ComponentAnalyzer { | ||
getDiagnostics(definition: ComponentDefinition, context: LitAnalyzerContext): LitDiagnostic[] { | ||
return context.rules.getDiagnosticsFromDefinition(definition, context).map(d => convertRuleDiagnosticToLitDiagnostic(d, context)); | ||
} | ||
|
||
getCodeFixesAtOffsetRange(definition: ComponentDefinition, range: SourceFileRange, context: LitAnalyzerContext): LitCodeFix[] { | ||
return arrayFlat( | ||
arrayDefined( | ||
context.rules | ||
.getDiagnosticsFromDefinition(definition, context) | ||
.filter(({ diagnostic }) => intersects(range, diagnostic.location)) | ||
.map(({ diagnostic }) => diagnostic.fix?.()) | ||
) | ||
).map(ruleFix => converRuleFixToLitCodeFix(ruleFix)); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
.../lit-analyzer/src/analyze/document-analyzer/html/code-fix/code-fixes-for-html-document.ts
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,18 @@ | ||
import { LitAnalyzerContext } from "../../../lit-analyzer-context"; | ||
import { HtmlDocument } from "../../../parse/document/text-document/html-document/html-document"; | ||
import { LitCodeFix } from "../../../types/lit-code-fix"; | ||
import { DocumentRange } from "../../../types/range"; | ||
import { arrayDefined, arrayFlat } from "../../../util/array-util"; | ||
import { documentRangeToSFRange, intersects } from "../../../util/range-util"; | ||
import { converRuleFixToLitCodeFix } from "../../../util/rule-fix-util"; | ||
|
||
export function codeFixesForHtmlDocument(htmlDocument: HtmlDocument, range: DocumentRange, context: LitAnalyzerContext): LitCodeFix[] { | ||
return arrayFlat( | ||
arrayDefined( | ||
context.rules | ||
.getDiagnosticsFromDocument(htmlDocument, context) | ||
.filter(({ diagnostic }) => intersects(documentRangeToSFRange(htmlDocument, range), diagnostic.location)) | ||
.map(({ diagnostic }) => diagnostic.fix?.()) | ||
) | ||
).map(ruleFix => converRuleFixToLitCodeFix(ruleFix)); | ||
} |
Oops, something went wrong.