11import * as core from "@arethetypeswrong/core" ;
2- import { filterProblems , problemAffectsEntrypoint , problemKindInfo } from "@arethetypeswrong/core/problems" ;
2+ import {
3+ filterProblems ,
4+ problemAffectsEntrypoint ,
5+ problemAffectsResolutionKind ,
6+ problemKindInfo ,
7+ } from "@arethetypeswrong/core/problems" ;
38import { allResolutionKinds , getResolutionOption , groupProblemsByKind } from "@arethetypeswrong/core/utils" ;
49import chalk from "chalk" ;
510import Table , { type GenericTable , type HorizontalTableRow } from "cli-table3" ;
@@ -11,13 +16,16 @@ import type { RenderOptions } from "./index.js";
1116
1217export async function typed (
1318 analysis : core . Analysis ,
14- { emoji = true , summary = true , format = "auto" , ignoreRules = [ ] } : RenderOptions ,
19+ { emoji = true , summary = true , format = "auto" , ignoreRules = [ ] , ignoreResolutions = [ ] } : RenderOptions ,
1520) : Promise < string > {
1621 let output = "" ;
1722 const problems = analysis . problems . filter (
1823 ( problem ) => ! ignoreRules || ! ignoreRules . includes ( problemFlags [ problem . kind ] ) ,
1924 ) ;
20- const grouped = groupProblemsByKind ( problems ) ;
25+ // sort resolutions with required (impacts result) first and ignored after
26+ const requiredResolutions = allResolutionKinds . filter ( ( kind ) => ! ignoreResolutions . includes ( kind ) ) ;
27+ const ignoredResolutions = allResolutionKinds . filter ( ( kind ) => ignoreResolutions . includes ( kind ) ) ;
28+ const resolutions = requiredResolutions . concat ( ignoredResolutions ) ;
2129 const entrypoints = Object . keys ( analysis . entrypoints ) ;
2230 marked . setOptions ( {
2331 renderer : new TerminalRenderer ( ) ,
@@ -43,15 +51,26 @@ export async function typed(
4351 if ( ignoreRules && ignoreRules . length ) {
4452 out ( chalk . gray ( ` (ignoring rules: ${ ignoreRules . map ( ( rule ) => `'${ rule } '` ) . join ( ", " ) } )\n` ) ) ;
4553 }
54+ if ( ignoreResolutions && ignoreResolutions . length ) {
55+ out (
56+ chalk . gray ( ` (ignoring resolutions: ${ ignoreResolutions . map ( ( resolution ) => `'${ resolution } '` ) . join ( ", " ) } )\n` ) ,
57+ ) ;
58+ }
4659
4760 if ( summary ) {
4861 const defaultSummary = marked ( ! emoji ? " No problems found" : " No problems found 🌟" ) ;
49- const summaryTexts = Object . keys ( grouped ) . map ( ( kind ) => {
62+ const grouped = groupProblemsByKind ( problems ) ;
63+ const summaryTexts = Object . entries ( grouped ) . map ( ( [ kind , kindProblems ] ) => {
5064 const info = problemKindInfo [ kind as core . ProblemKind ] ;
65+ const affectsRequiredResolution = kindProblems . some ( ( p ) =>
66+ requiredResolutions . some ( ( r ) => problemAffectsResolutionKind ( p , r , analysis ) ) ,
67+ ) ;
5168 const description = marked (
5269 `${ info . description } ${ info . details ? ` Use \`-f json\` to see ${ info . details } .` : "" } ${ info . docsUrl } ` ,
5370 ) ;
54- return `${ emoji ? `${ info . emoji } ` : "" } ${ description } ` ;
71+ return `${ affectsRequiredResolution ? "" : "(ignored per resolution) " } ${
72+ emoji ? `${ info . emoji } ` : ""
73+ } ${ description } `;
5574 } ) ;
5675
5776 out ( summaryTexts . join ( "" ) || defaultSummary ) ;
@@ -67,6 +86,7 @@ export async function typed(
6786 } ) ;
6887
6988 const getCellContents = memo ( ( subpath : string , resolutionKind : core . ResolutionKind ) => {
89+ const ignoredPrefix = ignoreResolutions . includes ( resolutionKind ) ? "(ignored) " : "" ;
7090 const problemsForCell = groupProblemsByKind (
7191 filterProblems ( problems , analysis , { entrypoint : subpath , resolutionKind } ) ,
7292 ) ;
@@ -75,7 +95,10 @@ export async function typed(
7595 const kinds = Object . keys ( problemsForCell ) as core . ProblemKind [ ] ;
7696 if ( kinds . length ) {
7797 return kinds
78- . map ( ( kind ) => ( emoji ? `${ problemKindInfo [ kind ] . emoji } ` : "" ) + problemKindInfo [ kind ] . shortDescription )
98+ . map (
99+ ( kind ) =>
100+ ignoredPrefix + ( emoji ? `${ problemKindInfo [ kind ] . emoji } ` : "" ) + problemKindInfo [ kind ] . shortDescription ,
101+ )
79102 . join ( "\n" ) ;
80103 }
81104
@@ -87,20 +110,25 @@ export async function typed(
87110 analysis . programInfo [ getResolutionOption ( resolutionKind ) ] . moduleKinds ?. [ resolution ?. fileName ?? "" ]
88111 ?. detectedKind || ""
89112 ] ;
90- return resolution ?. isJson ? jsonResult : moduleResult ;
113+ return ignoredPrefix + ( resolution ?. isJson ? jsonResult : moduleResult ) ;
91114 } ) ;
92115
93116 const flippedTable =
94117 format === "auto" || format === "table-flipped"
95118 ? new Table ( {
96- head : [ "" , ...allResolutionKinds . map ( ( kind ) => chalk . reset ( resolutionKinds [ kind ] ) ) ] ,
119+ head : [
120+ "" ,
121+ ...resolutions . map ( ( kind ) =>
122+ chalk . reset ( resolutionKinds [ kind ] + ( ignoreResolutions . includes ( kind ) ? " (ignored)" : "" ) ) ,
123+ ) ,
124+ ] ,
97125 } )
98126 : undefined ;
99127 if ( flippedTable ) {
100128 entrypoints . forEach ( ( subpath , i ) => {
101129 flippedTable . push ( [
102130 entrypointHeaders [ i ] ,
103- ...allResolutionKinds . map ( ( resolutionKind ) => getCellContents ( subpath , resolutionKind ) ) ,
131+ ...resolutions . map ( ( resolutionKind ) => getCellContents ( subpath , resolutionKind ) ) ,
104132 ] ) ;
105133 } ) ;
106134 }
@@ -112,7 +140,7 @@ export async function typed(
112140 } ) as GenericTable < HorizontalTableRow > )
113141 : undefined ;
114142 if ( table ) {
115- allResolutionKinds . forEach ( ( kind ) => {
143+ resolutions . forEach ( ( kind ) => {
116144 table . push ( [ resolutionKinds [ kind ] , ...entrypoints . map ( ( entrypoint ) => getCellContents ( entrypoint , kind ) ) ] ) ;
117145 } ) ;
118146 }
0 commit comments