@mintlify/cli 4.0.1740 → 4.0.1742

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,11 @@ import { Box, Text } from 'ink';
4
4
  import type { Report } from './report.js';
5
5
  import type { Diagnostic } from './types.js';
6
6
 
7
+ const preview = (value: string) => {
8
+ const text = JSON.stringify(value);
9
+ return text.length > 60 ? `${text.slice(0, 57)}..."` : text;
10
+ };
11
+
7
12
  const location = ({ line, column }: Pick<Diagnostic, 'line' | 'column'>) =>
8
13
  line ? `${line}${column ? `:${column}` : ''}` : '';
9
14
 
@@ -27,6 +32,14 @@ const DiagnosticLine = ({ diagnostic }: { diagnostic: Diagnostic }) => {
27
32
  const plural = (count: number, word: string) => `${count} ${word}${count === 1 ? '' : 's'}`;
28
33
 
29
34
  export const logReport = (report: Report) => {
35
+ for (const change of report.fixed ?? []) {
36
+ addLog(
37
+ <SuccessLog
38
+ message={`fixed ${change.file}${change.line ? `:${change.line}` : ''} ${change.rule}: ${preview(change.before)} → ${preview(change.after)}`}
39
+ />
40
+ );
41
+ }
42
+
30
43
  const byFile = new Map<string, Diagnostic[]>();
31
44
  for (const diagnostic of report.diagnostics) {
32
45
  byFile.get(diagnostic.file)?.push(diagnostic) ?? byFile.set(diagnostic.file, [diagnostic]);
@@ -42,6 +55,11 @@ export const logReport = (report: Report) => {
42
55
  );
43
56
  }
44
57
 
58
+ const fixable = report.diagnostics.filter(({ fix }) => fix).length;
59
+ if (fixable > 0 && !report.fixed) {
60
+ addLog(<InfoLog message={`\`--fix\` would fix ${plural(fixable, 'issue')}.`} />);
61
+ }
62
+
45
63
  const { build } = report;
46
64
  if (build.ran && build.passed) addLog(<SuccessLog message="build passed" />);
47
65
  else if (build.ran && report.passed)
@@ -1,4 +1,4 @@
1
- import type { Diagnostic } from './types.js';
1
+ import type { Change, Diagnostic } from './types.js';
2
2
 
3
3
  export type BuildStatus =
4
4
  | { ran: true; passed: boolean }
@@ -9,9 +9,15 @@ export type Report = {
9
9
  summary: { errors: number; warnings: number; byRule: Record<string, number> };
10
10
  diagnostics: Diagnostic[];
11
11
  build: BuildStatus;
12
+ /** With --fix: the edits that were applied. */
13
+ fixed?: Change[];
12
14
  };
13
15
 
14
- export const toReport = (diagnostics: Diagnostic[], build: BuildStatus): Report => {
16
+ export const toReport = (
17
+ diagnostics: Diagnostic[],
18
+ build: BuildStatus,
19
+ fixed?: Change[]
20
+ ): Report => {
15
21
  const byRule: Record<string, number> = {};
16
22
  for (const { rule } of diagnostics) byRule[rule] = (byRule[rule] ?? 0) + 1;
17
23
  const errors = diagnostics.filter(({ severity }) => severity === 'error').length;
@@ -29,5 +35,6 @@ export const toReport = (diagnostics: Diagnostic[], build: BuildStatus): Report
29
35
  ...(fix && { fix }),
30
36
  })),
31
37
  build,
38
+ ...(fixed && { fixed }),
32
39
  };
33
40
  };
@@ -11,6 +11,16 @@ export type Edit = { start: number; end: number; text: string };
11
11
 
12
12
  export type FileEdit = Edit & { file: string };
13
13
 
14
+ /** A fix --fix applied: where it was and the text it replaced. */
15
+ export type Change = {
16
+ rule: string;
17
+ file: string;
18
+ line?: number;
19
+ column?: number;
20
+ before: string;
21
+ after: string;
22
+ };
23
+
14
24
  export type Diagnostic = {
15
25
  rule: string;
16
26
  group: Group;