@salesforce-ux/slds-linter 1.0.7 → 1.0.8-internal

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.
@@ -1,6 +1,6 @@
1
1
  // src/commands/emit.ts
2
- import chalk from "chalk";
3
2
  import { Logger } from "../utils/logger.js";
3
+ import { Colors } from "../utils/colors.js";
4
4
  import { normalizeCliOptions } from "../utils/config-utils.js";
5
5
  import {
6
6
  DEFAULT_ESLINT_CONFIG_PATH
@@ -47,20 +47,20 @@ function registerEmitCommand(program) {
47
47
  "Target directory to emit (defaults to current directory). Support glob patterns"
48
48
  ).action(async (options) => {
49
49
  try {
50
- Logger.info(chalk.blue("Emitting configuration files..."));
50
+ Logger.info("Emitting configuration files...");
51
51
  const normalizedOptions = normalizeCliOptions(options, {
52
52
  configEslint: DEFAULT_ESLINT_CONFIG_PATH
53
53
  });
54
54
  const enhancedConfig = await generateEnhancedESLintConfig(normalizedOptions.configEslint);
55
55
  const destESLintConfigPath = path.join(normalizedOptions.directory, path.basename(normalizedOptions.configEslint));
56
56
  await writeFile(destESLintConfigPath, enhancedConfig, "utf8");
57
- Logger.success(chalk.green(`ESLint configuration created at:
57
+ Logger.success(Colors.success(`ESLint configuration created at:
58
58
  ${destESLintConfigPath}
59
59
  `));
60
- Logger.info(chalk.cyan("Rules are dynamically loaded based on extends configuration."));
60
+ Logger.info("Rules are dynamically loaded based on extends configuration.");
61
61
  } catch (error) {
62
62
  Logger.error(
63
- chalk.red(`Failed to emit configuration: ${error.message}`)
63
+ Colors.error(`Failed to emit configuration: ${error.message}`)
64
64
  );
65
65
  process.exit(1);
66
66
  }
@@ -1,9 +1,9 @@
1
1
  // src/commands/lint.ts
2
2
  import { Option } from "commander";
3
- import chalk from "chalk";
4
3
  import { printLintResults } from "../utils/lintResultsUtil.js";
5
4
  import { normalizeCliOptions, normalizeDirectoryPath } from "../utils/config-utils.js";
6
5
  import { Logger } from "../utils/logger.js";
6
+ import { Colors } from "../utils/colors.js";
7
7
  import { DEFAULT_ESLINT_CONFIG_PATH } from "../services/config.resolver.js";
8
8
  import { lint } from "../executor/index.js";
9
9
  function registerLintCommand(program) {
@@ -14,32 +14,25 @@ function registerLintCommand(program) {
14
14
  }).description("Run both style and component linting").argument("[directory]", "Target directory to scan (defaults to current directory). Support glob patterns").addOption(new Option("-d, --directory <path>", "Target directory to scan (defaults to current directory). Support glob patterns").hideHelp()).option("--fix", "Automatically fix problems").option("--config-eslint <path>", "Path to eslint config file").option("--editor <editor>", "Editor to open files with (e.g., vscode, atom, sublime). Auto-detects if not specified").action(async (directory, options) => {
15
15
  const startTime = Date.now();
16
16
  try {
17
- Logger.info(chalk.blue("Starting lint process..."));
17
+ Logger.info("Starting lint process...");
18
18
  const normalizedOptions = normalizeCliOptions(options, {
19
19
  configEslint: DEFAULT_ESLINT_CONFIG_PATH
20
20
  });
21
21
  if (directory) {
22
22
  normalizedOptions.directory = normalizeDirectoryPath(directory);
23
23
  } else if (options.directory) {
24
- Logger.newLine().warning(chalk.yellow(
24
+ Logger.newLine().warning(Colors.warning(
25
25
  `WARNING: --directory, -d option is deprecated. Supply as argument instead.
26
26
  Example: npx @salesforce-ux/slds-linter lint ${options.directory}`
27
27
  ));
28
28
  }
29
29
  const lintResults = await lint(normalizedOptions);
30
- printLintResults(lintResults, normalizedOptions.editor);
31
- const errorCount = lintResults.reduce((sum, r) => sum + r.errors.length, 0);
32
- const warningCount = lintResults.reduce((sum, r) => sum + r.warnings.length, 0);
33
- Logger.info(
34
- `
35
- ${chalk.red(`${errorCount} error${errorCount !== 1 ? "s" : ""}`)} ${chalk.yellow(`${warningCount} warning${warningCount !== 1 ? "s" : ""}`)}`
36
- );
30
+ const { totalErrors } = printLintResults(lintResults, normalizedOptions.editor);
37
31
  const elapsedTime = ((Date.now() - startTime) / 1e3).toFixed(2);
38
- Logger.success(chalk.green(`
39
- Linting completed in ${elapsedTime} seconds.`));
40
- process.exit(errorCount > 0 ? 1 : 0);
32
+ Logger.newLine().success(`Linting completed in ${elapsedTime} seconds.`);
33
+ process.exit(totalErrors > 0 ? 1 : 0);
41
34
  } catch (error) {
42
- Logger.error(chalk.red(`Failed to complete linting: ${error.message}`));
35
+ Logger.error(Colors.error(`Failed to complete linting: ${error.message}`));
43
36
  process.exit(1);
44
37
  }
45
38
  });
@@ -2,10 +2,10 @@
2
2
  import { Option } from "commander";
3
3
  import path from "path";
4
4
  import ora from "ora";
5
- import chalk from "chalk";
6
5
  import fs from "fs";
7
6
  import { normalizeAndValidatePath, normalizeCliOptions, normalizeDirectoryPath } from "../utils/config-utils.js";
8
7
  import { Logger } from "../utils/logger.js";
8
+ import { Colors } from "../utils/colors.js";
9
9
  import { DEFAULT_ESLINT_CONFIG_PATH } from "../services/config.resolver.js";
10
10
  import { report, lint } from "../executor/index.js";
11
11
  function registerReportCommand(program) {
@@ -19,7 +19,7 @@ function registerReportCommand(program) {
19
19
  if (directory) {
20
20
  normalizedOptions.directory = normalizeDirectoryPath(directory);
21
21
  } else if (options.directory) {
22
- Logger.newLine().warning(chalk.yellow(
22
+ Logger.newLine().warning(Colors.warning(
23
23
  `WARNING: --directory, -d option is deprecated. Supply as argument instead.
24
24
  Example: npx @salesforce-ux/slds-linter report ${options.directory}`
25
25
  ));
@@ -13,20 +13,25 @@ async function lint(config) {
13
13
  const normalizedConfig = normalizeCliOptions(config, {
14
14
  configEslint: DEFAULT_ESLINT_CONFIG_PATH
15
15
  });
16
- const styleFiles = await FileScanner.scanFiles(normalizedConfig.directory, {
16
+ const { filesCount: styleFilesCount, batches: styleFiles } = await FileScanner.scanFiles(normalizedConfig.directory, {
17
17
  patterns: StyleFilePatterns,
18
18
  batchSize: 100
19
19
  });
20
- const componentFiles = await FileScanner.scanFiles(normalizedConfig.directory, {
20
+ const { filesCount: componentFilesCount, batches: componentFiles } = await FileScanner.scanFiles(normalizedConfig.directory, {
21
21
  patterns: ComponentFilePatterns,
22
22
  batchSize: 100
23
23
  });
24
+ if (styleFilesCount > 0) {
25
+ Logger.info(`Total style files: ${styleFilesCount}`);
26
+ }
27
+ if (componentFilesCount > 0) {
28
+ Logger.info(`Total component files: ${componentFilesCount}`);
29
+ }
24
30
  const { fix, configEslint } = normalizedConfig;
25
- const lintResults = await LintRunner.runLinting([...styleFiles, ...componentFiles], "component", {
31
+ return await LintRunner.runLinting([...styleFiles, ...componentFiles], {
26
32
  fix,
27
33
  configPath: configEslint
28
34
  });
29
- return standardizeLintMessages(lintResults);
30
35
  } catch (error) {
31
36
  const errorMessage = `Linting failed: ${error.message}`;
32
37
  Logger.error(errorMessage);
@@ -64,33 +69,6 @@ async function report(config, results) {
64
69
  throw new Error(errorMessage);
65
70
  }
66
71
  }
67
- function standardizeLintMessages(results) {
68
- return results.map((result) => ({
69
- ...result,
70
- errors: result.errors.map((entry) => {
71
- let msgObj;
72
- try {
73
- msgObj = JSON.parse(entry.message);
74
- if (typeof msgObj === "object" && "message" in msgObj) {
75
- return { ...entry, ...msgObj };
76
- }
77
- } catch {
78
- }
79
- return { ...entry, message: entry.message };
80
- }),
81
- warnings: result.warnings.map((entry) => {
82
- let msgObj;
83
- try {
84
- msgObj = JSON.parse(entry.message);
85
- if (typeof msgObj === "object" && "message" in msgObj) {
86
- return { ...entry, ...msgObj };
87
- }
88
- } catch {
89
- }
90
- return { ...entry, message: entry.message };
91
- })
92
- }));
93
- }
94
72
  export {
95
73
  lint,
96
74
  report
package/build/index.js CHANGED
@@ -19,7 +19,7 @@ process.on("uncaughtException", (error) => {
19
19
  var program = new Command();
20
20
  program.name("npx @salesforce-ux/slds-linter@latest").showHelpAfterError();
21
21
  function registerVersion() {
22
- program.description("SLDS Linter CLI tool for linting styles and components").version("1.0.7");
22
+ program.description("SLDS Linter CLI tool for linting styles and components").version("1.0.8-internal");
23
23
  }
24
24
  registerLintCommand(program);
25
25
  registerReportCommand(program);
@@ -157,7 +157,7 @@ var rule_messages_default = {
157
157
  // src/services/config.resolver.ts
158
158
  var DEFAULT_ESLINT_CONFIG_PATH = resolvePath("@salesforce-ux/eslint-plugin-slds/config", import.meta);
159
159
  var ESLINT_VERSION = "9.36.0";
160
- var LINTER_CLI_VERSION = "1.0.7";
160
+ var LINTER_CLI_VERSION = "1.0.8-internal";
161
161
  var getRuleDescription = (ruleId) => {
162
162
  const ruleIdWithoutNameSpace = `${ruleId}`.replace(/\@salesforce-ux\//, "").replace(/^slds\//, "");
163
163
  return rule_messages_default[ruleIdWithoutNameSpace]?.description || "--";
@@ -1,3 +1,3 @@
1
- import { FilePattern } from './file-scanner';
1
+ import { FilePattern } from '../types';
2
2
  export declare const StyleFilePatterns: FilePattern;
3
3
  export declare const ComponentFilePatterns: FilePattern;
@@ -1,12 +1,4 @@
1
- export interface FilePattern {
2
- extensions: string[];
3
- exclude?: string[];
4
- }
5
- export interface ScanOptions {
6
- patterns: FilePattern;
7
- batchSize?: number;
8
- gitignore?: boolean;
9
- }
1
+ import { ScanOptions, ScanResult } from "../types";
10
2
  export declare class FileScanner {
11
3
  private static DEFAULT_BATCH_SIZE;
12
4
  /**
@@ -15,7 +7,7 @@ export declare class FileScanner {
15
7
  * @param options Scanning options including patterns and batch size
16
8
  * @returns Array of file paths in batches
17
9
  */
18
- static scanFiles(directory: string, options: ScanOptions): Promise<string[][]>;
10
+ static scanFiles(directory: string, options: ScanOptions): Promise<ScanResult>;
19
11
  /**
20
12
  * Validates that files exist and are readable
21
13
  */
@@ -1,9 +1,8 @@
1
1
  // src/services/file-scanner.ts
2
+ import path from "path";
2
3
  import { promises as fs } from "fs";
3
- import { Logger } from "../utils/logger.js";
4
4
  import { globby, isDynamicPattern } from "globby";
5
- import { extname } from "path";
6
- import path from "path";
5
+ import { Logger } from "../utils/logger.js";
7
6
  var FileScanner = class {
8
7
  static DEFAULT_BATCH_SIZE = 100;
9
8
  /**
@@ -53,7 +52,7 @@ var FileScanner = class {
53
52
  absolute: true,
54
53
  gitignore: options.gitignore !== false
55
54
  }).then((matches) => matches.filter((match) => {
56
- const fileExt = extname(match).substring(1);
55
+ const fileExt = path.extname(match).substring(1);
57
56
  return options.patterns.extensions.includes(fileExt);
58
57
  }));
59
58
  const validFiles = await this.validateFiles(allFiles);
@@ -62,7 +61,10 @@ var FileScanner = class {
62
61
  Logger.debug(
63
62
  `Found ${validFiles.length} files, split into ${batches.length} batches`
64
63
  );
65
- return batches;
64
+ return {
65
+ filesCount: validFiles.length,
66
+ batches
67
+ };
66
68
  } catch (error) {
67
69
  Logger.error(`Failed to scan files: ${error.message}`);
68
70
  throw error;
@@ -3,7 +3,7 @@ export declare class LintRunner {
3
3
  /**
4
4
  * Run linting on batches of files
5
5
  */
6
- static runLinting(fileBatches: string[][], workerType: 'component', options?: LintRunnerOptions): Promise<LintResult[]>;
6
+ static runLinting(fileBatches: string[][], options?: LintRunnerOptions): Promise<LintResult[]>;
7
7
  /**
8
8
  * Process and normalize worker results
9
9
  */
@@ -8,7 +8,7 @@ var LintRunner = class {
8
8
  /**
9
9
  * Run linting on batches of files
10
10
  */
11
- static async runLinting(fileBatches, workerType, options = {}) {
11
+ static async runLinting(fileBatches, options = {}) {
12
12
  try {
13
13
  const workerScript = path.resolve(
14
14
  resolveDirName(import.meta),
@@ -46,21 +46,11 @@ var LintRunner = class {
46
46
  continue;
47
47
  }
48
48
  for (const result of batch.results) {
49
- if (result.error) {
50
- Logger.warning(`File processing failed: ${result.file} - ${result.error}`);
49
+ if (result.error || !result.lintResult) {
50
+ Logger.warning(`File processing failed: ${result.filePath} - ${result.error}`);
51
51
  continue;
52
52
  }
53
- results.push({
54
- filePath: result.file,
55
- errors: result.errors?.map((e) => ({
56
- ...e,
57
- severity: 2
58
- })) || [],
59
- warnings: result.warnings?.map((w) => ({
60
- ...w,
61
- severity: 1
62
- })) || []
63
- });
53
+ results.push(result.lintResult);
64
54
  }
65
55
  }
66
56
  return results;
@@ -31,11 +31,11 @@ export declare class CsvReportGenerator {
31
31
  /**
32
32
  * Generate CSV report and write to file
33
33
  */
34
- static generate(results: any[]): Promise<string>;
34
+ static generate(results: LintResult[]): Promise<string>;
35
35
  /**
36
36
  * Generate CSV string from lint results
37
37
  */
38
- static generateCsvString(results: any[]): string;
38
+ static generateCsvString(results: LintResult[]): string;
39
39
  /**
40
40
  * Convert lint results to CSV-compatible data format
41
41
  */
@@ -75,46 +75,29 @@ var ReportGenerator = class {
75
75
  */
76
76
  static extractRules(results) {
77
77
  const rules = /* @__PURE__ */ new Map();
78
- for (const result of results) {
79
- for (const error of result.errors) {
80
- if (!rules.has(error.ruleId)) {
81
- rules.set(error.ruleId, {
82
- id: replaceNamespaceinRules(error.ruleId),
78
+ results.forEach((result) => {
79
+ result.messages.forEach((message) => {
80
+ if (!rules.has(message.ruleId)) {
81
+ rules.set(message.ruleId, {
82
+ id: replaceNamespaceinRules(message.ruleId),
83
83
  shortDescription: {
84
- text: getRuleDescription(replaceNamespaceinRules(error.ruleId))
84
+ text: getRuleDescription(replaceNamespaceinRules(message.ruleId))
85
85
  },
86
86
  properties: {
87
87
  category: "Style"
88
88
  }
89
89
  });
90
90
  }
91
- }
92
- for (const warning of result.warnings) {
93
- if (!rules.has(warning.ruleId)) {
94
- rules.set(warning.ruleId, {
95
- id: replaceNamespaceinRules(warning.ruleId),
96
- shortDescription: {
97
- text: getRuleDescription(replaceNamespaceinRules(warning.ruleId))
98
- },
99
- properties: {
100
- category: "Style"
101
- }
102
- });
103
- }
104
- }
105
- }
91
+ });
92
+ });
106
93
  return Array.from(rules.values());
107
94
  }
108
95
  /**
109
96
  * Add lint results to SARIF report
110
97
  */
111
98
  static addResultsToSarif(runBuilder, lintResult) {
112
- lintResult.errors.forEach((error) => {
113
- const resultBuilder = new SarifResultBuilder().initSimple(transformedResults(lintResult, error, "error"));
114
- runBuilder.addResult(resultBuilder);
115
- });
116
- lintResult.warnings.forEach((warning) => {
117
- const resultBuilder = new SarifResultBuilder().initSimple(transformedResults(lintResult, warning, "warning"));
99
+ lintResult.messages.forEach((message) => {
100
+ const resultBuilder = new SarifResultBuilder().initSimple(transformedResults(lintResult, message, "error"));
118
101
  runBuilder.addResult(resultBuilder);
119
102
  });
120
103
  }
@@ -149,34 +132,23 @@ var CsvReportGenerator = class {
149
132
  useBom: true,
150
133
  useKeysAsHeaders: true
151
134
  });
152
- const transformedResults2 = results.flatMap(
153
- (result) => [
154
- ...result.errors.map((error) => ({
135
+ const transformedResults2 = [];
136
+ results.forEach((result) => {
137
+ result.messages.forEach((message) => {
138
+ transformedResults2.push({
155
139
  "File Path": path.relative(cwd, result.filePath),
156
- "Message": parseText(error.message),
140
+ "Message": parseText(message.message),
157
141
  "Severity": "error",
158
- "Rule ID": replaceNamespaceinRules(error.ruleId || "N/A"),
159
- "Start Line": error.line,
160
- "Start Column": error.column,
161
- "End Line": error.endLine || error.line,
142
+ "Rule ID": replaceNamespaceinRules(message.ruleId || "N/A"),
143
+ "Start Line": message.line,
144
+ "Start Column": message.column,
145
+ "End Line": message.endLine || message.line,
162
146
  // Default to start line if missing
163
- "End Column": error.endColumn || error.column
147
+ "End Column": message.endColumn || message.column
164
148
  // Default to start column if missing
165
- })),
166
- ...result.warnings.map((warning) => ({
167
- "File Path": path.relative(cwd, result.filePath),
168
- "Message": parseText(warning.message),
169
- "Severity": "warning",
170
- "Rule ID": replaceNamespaceinRules(warning.ruleId || "N/A"),
171
- "Start Line": warning.line,
172
- "Start Column": warning.column,
173
- "End Line": warning.endLine || warning.line,
174
- // Default to start line if missing
175
- "End Column": warning.endColumn || warning.column
176
- // Default to start column if missing
177
- }))
178
- ]
179
- );
149
+ });
150
+ });
151
+ });
180
152
  return generateCsv(csvConfig)(transformedResults2);
181
153
  }
182
154
  };
@@ -1,3 +1,4 @@
1
+ import type { ESLint, Linter } from 'eslint';
1
2
  export interface BaseConfig {
2
3
  directory?: string;
3
4
  files?: string[];
@@ -32,41 +33,17 @@ export interface LintRunnerOptions {
32
33
  maxWorkers?: number;
33
34
  timeoutMs?: number;
34
35
  }
35
- export interface LintResultEntry {
36
- line: number;
37
- column: number;
38
- endColumn: number;
39
- message: string;
40
- ruleId: string;
41
- severity: number;
42
- }
43
- export interface LintResult {
44
- filePath: string;
45
- errors: Array<LintResultEntry>;
46
- warnings: Array<LintResultEntry>;
47
- }
36
+ export type LintResultEntry = Linter.LintMessage;
37
+ export type LintResult = ESLint.LintResult;
48
38
  export type ExitCode = 0 | 1 | 2;
49
39
  export interface WorkerConfig {
50
40
  configPath?: string;
51
41
  fix?: boolean;
52
42
  }
53
43
  export interface WorkerResult {
54
- file: string;
44
+ filePath: string;
45
+ lintResult?: LintResult;
55
46
  error?: string;
56
- warnings?: Array<{
57
- line: number;
58
- column: number;
59
- endColumn: number;
60
- message: string;
61
- ruleId: string;
62
- }>;
63
- errors?: Array<{
64
- line: number;
65
- column: number;
66
- endColumn: number;
67
- message: string;
68
- ruleId: string;
69
- }>;
70
47
  }
71
48
  export interface SarifResultEntry {
72
49
  level: any;
@@ -78,3 +55,22 @@ export interface SarifResultEntry {
78
55
  endLine?: number;
79
56
  endColumn?: number;
80
57
  }
58
+ export interface LintResultSummary {
59
+ totalErrors: number;
60
+ totalWarnings: number;
61
+ fixableErrors: number;
62
+ fixableWarnings: number;
63
+ }
64
+ export interface FilePattern {
65
+ extensions: string[];
66
+ exclude?: string[];
67
+ }
68
+ export interface ScanOptions {
69
+ patterns: FilePattern;
70
+ batchSize?: number;
71
+ gitignore?: boolean;
72
+ }
73
+ export interface ScanResult {
74
+ filesCount: number;
75
+ batches: string[][];
76
+ }
@@ -0,0 +1,16 @@
1
+ import chalk from 'chalk';
2
+ /**
3
+ * Color constants matching the UX design system syntax colors for dark mode
4
+ * Based on the mock design specifications
5
+ */
6
+ export declare const Colors: {
7
+ readonly error: chalk.Chalk;
8
+ readonly warning: chalk.Chalk;
9
+ readonly success: chalk.Chalk;
10
+ readonly info: chalk.Chalk;
11
+ readonly hyperlink: chalk.Chalk;
12
+ readonly lowEmphasis: chalk.Chalk;
13
+ readonly standard: chalk.Chalk;
14
+ readonly errorBold: chalk.Chalk;
15
+ readonly warningBold: chalk.Chalk;
16
+ };
@@ -0,0 +1,24 @@
1
+ // src/utils/colors.ts
2
+ import chalk from "chalk";
3
+ var Colors = {
4
+ // Error: light red/salmon
5
+ error: chalk.hex("#FF8080"),
6
+ // Warning: vibrant yellow
7
+ warning: chalk.hex("#FFFF80"),
8
+ // Success: bright light green
9
+ success: chalk.hex("#66BB6A"),
10
+ // Informational: light cyan/aqua blue
11
+ info: chalk.hex("#80FFFF"),
12
+ // Hyperlink: light blue/lavender
13
+ hyperlink: chalk.hex("#8080FF"),
14
+ // Low-emphasis text: light gray
15
+ lowEmphasis: chalk.hex("#A9A9A9"),
16
+ // Standard text: white (default)
17
+ standard: chalk.white,
18
+ // Bold variants for emphasis
19
+ errorBold: chalk.hex("#FF8080").bold,
20
+ warningBold: chalk.hex("#FFFF80").bold
21
+ };
22
+ export {
23
+ Colors
24
+ };
@@ -1,5 +1,5 @@
1
1
  // src/utils/editorLinkUtil.ts
2
- import chalk from "chalk";
2
+ import { Colors } from "./colors.js";
3
3
  function detectCurrentEditor() {
4
4
  const editor = process.env.EDITOR || process.env.VISUAL;
5
5
  if (editor) {
@@ -43,7 +43,7 @@ function getEditorLink(editor, absolutePath, line, column) {
43
43
  function createClickableLineCol(lineCol, absolutePath, line, column, editor) {
44
44
  const detectedEditor = editor || detectCurrentEditor();
45
45
  const link = getEditorLink(detectedEditor, absolutePath, line, column);
46
- return `\x1B]8;;${link}\x07${chalk.blueBright(lineCol)}\x1B]8;;\x07`;
46
+ return `\x1B]8;;${link}\x07${Colors.info(lineCol)}\x1B]8;;\x07`;
47
47
  }
48
48
  export {
49
49
  createClickableLineCol,
@@ -1,4 +1,4 @@
1
- import { LintResult, LintResultEntry, SarifResultEntry } from '../types';
1
+ import { LintResult, LintResultEntry, SarifResultEntry, LintResultSummary } from '../types';
2
2
  /**
3
3
  *
4
4
  * @param id - Rule id
@@ -17,5 +17,5 @@ export declare function parseText(text: string): string;
17
17
  * @param results - Array of lint results.
18
18
  * @param editor - The chosen editor for clickable links (e.g., "vscode", "atom", "sublime"). If not provided, will auto-detect.
19
19
  */
20
- export declare function printLintResults(results: LintResult[], editor?: string): void;
20
+ export declare function printLintResults(results: LintResult[], editor?: string): LintResultSummary;
21
21
  export declare function transformedResults(lintResult: LintResult, entry: LintResultEntry, level: 'error' | 'warning'): SarifResultEntry;
@@ -1,8 +1,8 @@
1
1
  // src/utils/lintResultsUtil.ts
2
- import chalk from "chalk";
3
2
  import path from "path";
4
3
  import { createClickableLineCol } from "./editorLinkUtil.js";
5
4
  import { Logger } from "../utils/logger.js";
5
+ import { Colors } from "./colors.js";
6
6
  function replaceNamespaceinRules(id) {
7
7
  return id.includes("@salesforce-ux/") ? id.replace("@salesforce-ux/", "") : id;
8
8
  }
@@ -17,38 +17,57 @@ function parseText(text) {
17
17
  return safeText.endsWith(".") ? safeText : `${safeText}.`;
18
18
  }
19
19
  function printLintResults(results, editor) {
20
+ let totalErrors = 0;
21
+ let totalWarnings = 0;
22
+ let fixableErrors = 0;
23
+ let fixableWarnings = 0;
20
24
  results.forEach((result) => {
21
- const hasErrors = result.errors && result.errors.length > 0;
22
- const hasWarnings = result.warnings && result.warnings.length > 0;
23
- if (!hasErrors && !hasWarnings) return;
25
+ if (!result.messages || result.messages.length === 0) return;
24
26
  const absolutePath = result.filePath || "";
25
27
  const relativeFile = path.relative(process.cwd(), absolutePath) || "Unknown file";
26
- Logger.newLine().info(`${chalk.bold(relativeFile)}`);
27
- if (hasErrors) {
28
- result.errors.forEach((error) => {
29
- if (error.line && error.column && absolutePath) {
30
- const lineCol = `${error.line}:${error.column}`;
31
- const clickable = createClickableLineCol(lineCol, absolutePath, error.line, error.column, editor);
32
- const ruleId = error.ruleId ? chalk.dim(replaceNamespaceinRules(error.ruleId)) : "";
33
- Logger.error(` ${clickable} ${parseText(error.message)} ${ruleId}`);
34
- } else {
35
- Logger.error(` ${chalk.red("Error:")} ${parseText(error.message)}`);
36
- }
37
- });
38
- }
39
- if (hasWarnings) {
40
- result.warnings.forEach((warn) => {
41
- if (warn.line && warn.column && absolutePath) {
42
- const lineCol = `${warn.line}:${warn.column}`;
43
- const clickable = createClickableLineCol(lineCol, absolutePath, warn.line, warn.column, editor);
44
- const ruleId = warn.ruleId ? chalk.dim(replaceNamespaceinRules(warn.ruleId)) : "";
45
- Logger.warning(` ${clickable} ${parseText(warn.message)} ${ruleId}`);
46
- } else {
47
- Logger.warning(` ${chalk.yellow("Warning:")} ${parseText(warn.message)}`);
48
- }
28
+ console.log(`
29
+ ${Colors.info.underline(relativeFile)}
30
+ `);
31
+ const tableData = [];
32
+ result.messages.forEach((msg) => {
33
+ const isError = msg.severity === 2;
34
+ const isWarning = msg.severity === 1;
35
+ if (isError) {
36
+ totalErrors++;
37
+ if (msg.fix) fixableErrors++;
38
+ } else if (isWarning) {
39
+ totalWarnings++;
40
+ if (msg.fix) fixableWarnings++;
41
+ }
42
+ const lineCol = msg.line && msg.column ? `${msg.line}:${msg.column}` : "-";
43
+ const clickableLineCol = msg.line && msg.column ? createClickableLineCol(lineCol, absolutePath, msg.line, msg.column, editor) : lineCol;
44
+ const severityText = isError ? Colors.error("error") : Colors.warning("warning");
45
+ const message = parseText(msg.message);
46
+ const ruleId = msg.ruleId ? Colors.lowEmphasis(replaceNamespaceinRules(msg.ruleId)) : "";
47
+ tableData.push([clickableLineCol, severityText, message, ruleId]);
48
+ });
49
+ if (tableData.length > 0) {
50
+ tableData.forEach(([lineCol, severity, message, ruleId], index) => {
51
+ if (index > 0) console.log();
52
+ console.log(` ${lineCol} ${severity} ${message} ${ruleId}`);
49
53
  });
50
54
  }
51
55
  });
56
+ const totalProblems = totalErrors + totalWarnings;
57
+ if (totalProblems > 0) {
58
+ const chalkColorFn = totalErrors > 0 ? Colors.errorBold : Colors.warningBold;
59
+ console.log("");
60
+ const problemsText = `\u2716 ${totalProblems} SLDS Violation${totalProblems !== 1 ? "s" : ""} (${totalErrors} error${totalErrors !== 1 ? "s" : ""}, ${totalWarnings} warning${totalWarnings !== 1 ? "s" : ""})`;
61
+ console.log(chalkColorFn(problemsText));
62
+ const fixableTotal = fixableErrors + fixableWarnings;
63
+ if (fixableTotal > 0) {
64
+ const fixableText = ` ${fixableErrors} error${fixableErrors !== 1 ? "s" : ""} and ${fixableWarnings} warning${fixableWarnings !== 1 ? "s" : ""} potentially fixable with the \`--fix\` option.`;
65
+ console.log(chalkColorFn(fixableText));
66
+ }
67
+ } else {
68
+ Logger.newLine().success("No SLDS Violations found.");
69
+ }
70
+ return { totalErrors, totalWarnings, fixableErrors, fixableWarnings };
52
71
  }
53
72
  function transformedResults(lintResult, entry, level) {
54
73
  return {
@@ -1,25 +1,25 @@
1
1
  // src/utils/logger.ts
2
- import chalk from "chalk";
2
+ import { Colors } from "./colors.js";
3
3
  var Logger = class {
4
4
  static newLine() {
5
- console.log("\n");
5
+ console.log("");
6
6
  return this;
7
7
  }
8
8
  static info(message) {
9
- console.log(chalk.blue("\u2139"), message);
9
+ console.log(Colors.info(`\u2139 ${message}`));
10
10
  }
11
11
  static success(message) {
12
- console.log(chalk.green("\u2713"), message);
12
+ console.log(Colors.success("\u2713"), message);
13
13
  }
14
14
  static warning(message) {
15
- console.warn(chalk.yellow("\u26A0"), message);
15
+ console.warn(Colors.warning("\u26A0"), message);
16
16
  }
17
17
  static error(message) {
18
- console.error(chalk.red("\u2716"), message);
18
+ console.error(Colors.error("\u2716"), message);
19
19
  }
20
20
  static debug(message) {
21
21
  if (process.env.DEBUG) {
22
- console.debug(chalk.gray("\u{1F50D}"), message);
22
+ console.debug(Colors.lowEmphasis("\u{1F50D}"), message);
23
23
  }
24
24
  }
25
25
  };
@@ -18,25 +18,12 @@ var ESLintWorker = class extends BaseWorker {
18
18
  await ESLint.outputFixes(results);
19
19
  }
20
20
  return {
21
- file: filePath,
22
- warnings: fileResult.messages.filter((msg) => msg.severity === 1).map((warning) => ({
23
- line: warning.line,
24
- column: warning.column,
25
- endColumn: warning.endColumn,
26
- message: warning.message,
27
- ruleId: warning.ruleId || "unknown"
28
- })),
29
- errors: fileResult.messages.filter((msg) => msg.severity === 2).map((error) => ({
30
- line: error.line,
31
- column: error.column,
32
- endColumn: error.endColumn,
33
- message: error.message,
34
- ruleId: error.ruleId || "unknown"
35
- }))
21
+ filePath,
22
+ lintResult: fileResult
36
23
  };
37
24
  } catch (error) {
38
25
  return {
39
- file: filePath,
26
+ filePath,
40
27
  error: error.message
41
28
  };
42
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce-ux/slds-linter",
3
- "version": "1.0.7",
3
+ "version": "1.0.8-internal",
4
4
  "description": "SLDS Linter CLI tool for linting styles and components",
5
5
  "keywords": [
6
6
  "lightning design system linter",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "bin": "build/index.js",
31
31
  "dependencies": {
32
- "@salesforce-ux/eslint-plugin-slds": "1.0.7",
32
+ "@salesforce-ux/eslint-plugin-slds": "1.0.8-internal",
33
33
  "@typescript-eslint/eslint-plugin": "^8.36.0",
34
34
  "@typescript-eslint/parser": "^8.36.0",
35
35
  "chalk": "^4.1.2",