@salesforce-ux/slds-linter 1.0.10-internal → 1.1.0-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.
@@ -27,7 +27,7 @@ function registerLintCommand(program) {
27
27
  ));
28
28
  }
29
29
  const lintResults = await lint(normalizedOptions);
30
- const { totalErrors } = printLintResults(lintResults, normalizedOptions.editor);
30
+ const { totalErrors } = printLintResults(lintResults, { editor: normalizedOptions.editor });
31
31
  const elapsedTime = ((Date.now() - startTime) / 1e3).toFixed(2);
32
32
  Logger.newLine().success(`Linting completed in ${elapsedTime} seconds.`);
33
33
  process.exit(totalErrors > 0 ? 1 : 0);
@@ -17,4 +17,13 @@ export declare function lint(config: LintConfig): Promise<LintResult[]>;
17
17
  * @throws Error if report generation fails
18
18
  */
19
19
  export declare function report(config: ReportConfig, results?: LintResult[]): Promise<Readable>;
20
+ /**
21
+ * This function supports user to supply array of files to be linted
22
+ *
23
+ * @param files Array of file paths to be linted
24
+ * @param config Linting configuration options
25
+ * @returns Promise resolving to an array of lint results
26
+ * @throws Error if linting fails or if any file is not found
27
+ */
28
+ export declare function lintFiles(files: string[], config: LintConfig): Promise<LintResult[]>;
20
29
  export type { LintResult, LintResultEntry, LintConfig, ReportConfig, ExitCode, WorkerResult, SarifResultEntry } from '../types';
@@ -69,7 +69,31 @@ async function report(config, results) {
69
69
  throw new Error(errorMessage);
70
70
  }
71
71
  }
72
+ async function lintFiles(files, config) {
73
+ try {
74
+ Logger.debug("Starting linting with Node API");
75
+ const normalizedConfig = normalizeCliOptions(config, {
76
+ configEslint: DEFAULT_ESLINT_CONFIG_PATH
77
+ });
78
+ const batches = FileScanner.createBatches(files, FileScanner.DEFAULT_BATCH_SIZE);
79
+ Logger.debug(
80
+ `Found ${files.length} files, split into ${batches.length} batches`
81
+ );
82
+ const results = await LintRunner.runLinting(batches, {
83
+ fix: normalizedConfig.fix,
84
+ configPath: normalizedConfig.configEslint,
85
+ // when linting files, use the directory of the files as the working directory
86
+ cwd: normalizedConfig.directory
87
+ });
88
+ return results;
89
+ } catch (error) {
90
+ const errorMessage = `Linting failed: ${error.message}`;
91
+ Logger.error(errorMessage);
92
+ throw new Error(errorMessage);
93
+ }
94
+ }
72
95
  export {
73
96
  lint,
97
+ lintFiles,
74
98
  report
75
99
  };
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.10-internal");
22
+ program.description("SLDS Linter CLI tool for linting styles and components").version("1.1.0-internal");
23
23
  }
24
24
  registerLintCommand(program);
25
25
  registerReportCommand(program);
@@ -3,7 +3,7 @@ import { resolvePath } from "../utils/nodeVersionUtil.js";
3
3
  import ruleMessages from "@salesforce-ux/eslint-plugin-slds/rule-messages";
4
4
  var DEFAULT_ESLINT_CONFIG_PATH = resolvePath("@salesforce-ux/eslint-plugin-slds/config", import.meta);
5
5
  var ESLINT_VERSION = "9.36.0";
6
- var LINTER_CLI_VERSION = "1.0.10-internal";
6
+ var LINTER_CLI_VERSION = "1.1.0-internal";
7
7
  var getRuleDescription = (ruleId) => {
8
8
  const ruleIdWithoutNameSpace = `${ruleId}`.replace(/\@salesforce-ux\//, "").replace(/^slds\//, "");
9
9
  return ruleMessages[ruleIdWithoutNameSpace]?.description || "--";
@@ -1,6 +1,6 @@
1
1
  import { ScanOptions, ScanResult } from "../types";
2
2
  export declare class FileScanner {
3
- private static DEFAULT_BATCH_SIZE;
3
+ static DEFAULT_BATCH_SIZE: number;
4
4
  /**
5
5
  * Scans directory for files matching the given patterns
6
6
  * @param directory Base directory to scan
@@ -15,5 +15,5 @@ export declare class FileScanner {
15
15
  /**
16
16
  * Splits array of files into batches
17
17
  */
18
- private static createBatches;
18
+ static createBatches(files: string[], batchSize: number): string[][];
19
19
  }
@@ -18,7 +18,8 @@ var LintRunner = class {
18
18
  const configPath = await ConfigLoader.processConfig(options.configPath);
19
19
  const workerConfig = {
20
20
  configPath,
21
- fix: options.fix
21
+ fix: options.fix,
22
+ cwd: options.cwd
22
23
  };
23
24
  const results = await BatchProcessor.processBatches(
24
25
  fileBatches,
@@ -27,18 +27,17 @@ export interface LintConfig extends BaseConfig {
27
27
  export interface ReportConfig extends BaseConfig {
28
28
  format?: 'sarif' | 'csv';
29
29
  }
30
- export interface LintRunnerOptions {
31
- fix?: boolean;
32
- configPath?: string;
33
- maxWorkers?: number;
34
- timeoutMs?: number;
35
- }
36
30
  export type LintResultEntry = Linter.LintMessage;
37
31
  export type LintResult = ESLint.LintResult;
38
32
  export type ExitCode = 0 | 1 | 2;
39
33
  export interface WorkerConfig {
40
34
  configPath?: string;
41
35
  fix?: boolean;
36
+ cwd?: string;
37
+ }
38
+ export interface LintRunnerOptions extends WorkerConfig {
39
+ maxWorkers?: number;
40
+ timeoutMs?: number;
42
41
  }
43
42
  export interface WorkerResult {
44
43
  filePath: string;
@@ -74,3 +73,7 @@ export interface ScanResult {
74
73
  filesCount: number;
75
74
  batches: string[][];
76
75
  }
76
+ export interface PrintOptions {
77
+ editor?: string;
78
+ cwd?: string;
79
+ }
@@ -1,4 +1,4 @@
1
- import { LintResult, LintResultEntry, SarifResultEntry, LintResultSummary } from '../types';
1
+ import { LintResult, LintResultEntry, SarifResultEntry, LintResultSummary, PrintOptions } 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): LintResultSummary;
20
+ export declare function printLintResults(results: LintResult[], options?: PrintOptions): LintResultSummary;
21
21
  export declare function transformedResults(lintResult: LintResult, entry: LintResultEntry, level: 'error' | 'warning'): SarifResultEntry;
@@ -44,7 +44,7 @@ function printFixableViolationsSummary(fixableErrors, fixableWarnings) {
44
44
  }
45
45
  console.log(` ${fixableBreakdown.join(" and ")} potentially fixable with the \`--fix\` option.`);
46
46
  }
47
- function printLintResults(results, editor) {
47
+ function printLintResults(results, options) {
48
48
  let totalErrors = 0;
49
49
  let totalWarnings = 0;
50
50
  let fixableErrors = 0;
@@ -52,7 +52,7 @@ function printLintResults(results, editor) {
52
52
  results.forEach((result) => {
53
53
  if (!result.messages || result.messages.length === 0) return;
54
54
  const absolutePath = result.filePath || "";
55
- const relativeFile = path.relative(process.cwd(), absolutePath) || "Unknown file";
55
+ const relativeFile = path.relative(options?.cwd || process.cwd(), absolutePath) || "Unknown file";
56
56
  console.log(`
57
57
  ${Colors.info.underline(relativeFile)}
58
58
  `);
@@ -68,7 +68,7 @@ ${Colors.info.underline(relativeFile)}
68
68
  if (msg.fix) fixableWarnings++;
69
69
  }
70
70
  const lineCol = msg.line && msg.column ? `${msg.line}:${msg.column}` : "-";
71
- const clickableLineCol = msg.line && msg.column ? createClickableLineCol(lineCol, absolutePath, msg.line, msg.column, editor) : lineCol;
71
+ const clickableLineCol = msg.line && msg.column ? createClickableLineCol(lineCol, absolutePath, msg.line, msg.column, options?.editor) : lineCol;
72
72
  const severityText = isError ? Colors.error("error") : Colors.warning("warning");
73
73
  const message = parseText(msg.message);
74
74
  const ruleId = msg.ruleId ? Colors.lowEmphasis(replaceNamespaceinRules(msg.ruleId)) : "";
@@ -6,10 +6,14 @@ var ESLintWorker = class extends BaseWorker {
6
6
  eslint;
7
7
  constructor() {
8
8
  super();
9
- this.eslint = new ESLint({
9
+ const linterOptions = {
10
10
  overrideConfigFile: this.task.config.configPath,
11
11
  fix: this.task.config.fix
12
- });
12
+ };
13
+ if ("cwd" in this.task.config) {
14
+ linterOptions.cwd = this.task.config.cwd;
15
+ }
16
+ this.eslint = new ESLint(linterOptions);
13
17
  }
14
18
  async processFile(filePath) {
15
19
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce-ux/slds-linter",
3
- "version": "1.0.10-internal",
3
+ "version": "1.1.0-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.10-internal",
32
+ "@salesforce-ux/eslint-plugin-slds": "1.1.0-internal",
33
33
  "@typescript-eslint/eslint-plugin": "^8.36.0",
34
34
  "@typescript-eslint/parser": "^8.36.0",
35
35
  "chalk": "^4.1.2",