11import * as core from "@arethetypeswrong/core" ;
2- import { allResolutionKinds } from "@arethetypeswrong/core/utils" ;
3- import Table , { type GenericTable , type HorizontalTableRow } from "cli-table3" ;
2+ import { allResolutionKinds , groupProblemsByKind } from "@arethetypeswrong/core/utils" ;
43import chalk from "chalk" ;
4+ import Table , { type GenericTable , type HorizontalTableRow } from "cli-table3" ;
5+ import { marked } from "marked" ;
56
6- import { moduleKinds , problemEmoji , resolutionKinds , problemShortDescriptions , problemFlags } from "../problemUtils.js " ;
7+ import { filterProblems , problemAffectsEntrypoint , problemKindInfo } from "@arethetypeswrong/core/problems " ;
78import type { Opts } from "../index.js" ;
9+ import { moduleKinds , problemFlags , resolutionKinds } from "../problemUtils.js" ;
810import { tableFlipped } from "./tableFlipped.js" ;
11+ import TerminalRenderer from "marked-terminal" ;
912
1013export async function typed ( analysis : core . TypedAnalysis , opts : Opts ) {
11- const problems = core
12- . getProblems ( analysis )
13- . filter ( ( problem ) => ! opts . ignoreRules || ! opts . ignoreRules . includes ( problem . kind ) ) ;
14-
15- const subpaths = Object . keys ( analysis . entrypointResolutions ) ;
14+ const problems = analysis . problems . filter ( ( problem ) => ! opts . ignoreRules || ! opts . ignoreRules . includes ( problem . kind ) ) ;
15+ const grouped = groupProblemsByKind ( problems ) ;
16+ const subpaths = Object . keys ( analysis . entrypoints ) ;
17+ marked . setOptions ( {
18+ // @ts -expect-error the types are wrong (haha)
19+ renderer : new TerminalRenderer ( ) ,
20+ mangle : false ,
21+ headerIds : false ,
22+ } ) ;
1623
1724 if ( opts . ignoreRules && opts . ignoreRules . length ) {
1825 console . log (
@@ -25,23 +32,18 @@ export async function typed(analysis: core.TypedAnalysis, opts: Opts) {
2532 }
2633
2734 if ( opts . summary ) {
28- const summaries = core . summarizeProblems ( problems , analysis ) ;
2935 const defaultSummary = ! opts . emoji ? " No problems found" : " No problems found 🌟" ;
30- const summaryTexts = summaries . map ( ( summary ) => {
31- return summary . messages
32- . map ( ( message ) => {
33- const messageText = message . messageText . split ( ". " ) . join ( ".\n " ) ;
34- if ( ! opts . emoji ) return ` ${ messageText } ` ;
35- return ` ${ problemEmoji [ summary . kind ] } ${ messageText } ` ;
36- } )
37- . join ( "\n" ) ;
36+ const summaryTexts = Object . keys ( grouped ) . map ( ( kind ) => {
37+ const emoji = opts . emoji ? `${ problemKindInfo [ kind as core . ProblemKind ] . emoji } ` : "" ;
38+ const description = marked ( problemKindInfo [ kind as core . ProblemKind ] . description ) ;
39+ return `${ emoji } ${ description } ` ;
3840 } ) ;
3941
4042 console . log ( ( summaryTexts . join ( "\n\n" ) || defaultSummary ) + "\n" ) ;
4143 }
4244
4345 const entrypoints = subpaths . map ( ( s ) => {
44- const hasProblems = problems . some ( ( p ) => p . entrypoint === s ) ;
46+ const hasProblems = problems . some ( ( p ) => problemAffectsEntrypoint ( p , s , analysis ) ) ;
4547 const color = hasProblems ? "redBright" : "greenBright" ;
4648
4749 if ( s === "." ) return chalk . bold [ color ] ( `"${ analysis . packageName } "` ) ;
@@ -60,22 +62,21 @@ export async function typed(analysis: core.TypedAnalysis, opts: Opts) {
6062
6163 row = row . concat (
6264 allResolutionKinds . map ( ( kind ) => {
63- const problemsForCell = problems . filter (
64- ( problem ) => problem . entrypoint === subpath && problem . resolutionKind === kind
65+ const problemsForCell = groupProblemsByKind (
66+ filterProblems ( problems , analysis , { entrypoint : subpath , resolutionKind : kind } )
6567 ) ;
66-
67- const resolution = analysis . entrypointResolutions [ subpath ] [ kind ] . resolution ;
68-
69- const descriptions = problemShortDescriptions [ ! opts . emoji ? "noEmoji" : "emoji" ] ;
70-
71- if ( problemsForCell . length ) {
72- return problemsForCell . map ( ( problem ) => descriptions [ problem . kind ] ) . join ( "\n" ) ;
68+ const resolution = analysis . entrypoints [ subpath ] . resolutions [ kind ] . resolution ;
69+ const kinds = Object . keys ( problemsForCell ) as core . ProblemKind [ ] ;
70+ if ( kinds . length ) {
71+ return kinds
72+ . map (
73+ ( kind ) => ( opts . emoji ? `${ problemKindInfo [ kind ] . emoji } ` : "" ) + problemKindInfo [ kind ] . shortDescription
74+ )
75+ . join ( "\n" ) ;
7376 }
7477
7578 const jsonResult = ! opts . emoji ? "OK (JSON)" : "🟢 (JSON)" ;
76-
7779 const moduleResult = ( ! opts . emoji ? "OK " : "🟢 " ) + moduleKinds [ resolution ?. moduleKind ?. detectedKind || "" ] ;
78-
7980 return resolution ?. isJson ? jsonResult : moduleResult ;
8081 } )
8182 ) ;
@@ -96,22 +97,21 @@ export async function typed(analysis: core.TypedAnalysis, opts: Opts) {
9697
9798 row = row . concat (
9899 subpaths . map ( ( subpath ) => {
99- const problemsForCell = problems . filter (
100- ( problem ) => problem . entrypoint === subpath && problem . resolutionKind === kind
100+ const problemsForCell = groupProblemsByKind (
101+ filterProblems ( problems , analysis , { entrypoint : subpath , resolutionKind : kind } )
101102 ) ;
102-
103- const resolution = analysis . entrypointResolutions [ subpath ] [ kind ] . resolution ;
104-
105- const descriptions = problemShortDescriptions [ ! opts . emoji ? "noEmoji" : "emoji" ] ;
106-
107- if ( problemsForCell . length ) {
108- return problemsForCell . map ( ( problem ) => descriptions [ problem . kind ] ) . join ( "\n" ) ;
103+ const resolution = analysis . entrypoints [ subpath ] . resolutions [ kind ] . resolution ;
104+ const kinds = Object . keys ( problemsForCell ) as core . ProblemKind [ ] ;
105+ if ( kinds . length ) {
106+ return kinds
107+ . map (
108+ ( kind ) => ( opts . emoji ? `${ problemKindInfo [ kind ] . emoji } ` : "" ) + problemKindInfo [ kind ] . shortDescription
109+ )
110+ . join ( "\n" ) ;
109111 }
110112
111113 const jsonResult = ! opts . emoji ? "OK (JSON)" : "🟢 (JSON)" ;
112-
113114 const moduleResult = ( ! opts . emoji ? "OK " : "🟢 " ) + moduleKinds [ resolution ?. moduleKind ?. detectedKind || "" ] ;
114-
115115 return resolution ?. isJson ? jsonResult : moduleResult ;
116116 } )
117117 ) ;
0 commit comments