@salesforce-ux/slds-linter 0.1.4-alpha.1 → 0.1.4-alpha.2
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.
- package/build/commands/report.js +23 -14
- package/build/index.js +1 -1
- package/build/services/config.resolver.js +1 -1
- package/build/services/report-generator.d.ts +3 -0
- package/build/services/report-generator.js +53 -3
- package/build/types/index.d.ts +1 -0
- package/build/utils/cli-args.js +1 -0
- package/package.json +4 -3
package/build/commands/report.js
CHANGED
|
@@ -8,10 +8,10 @@ import { Logger } from "../utils/logger.js";
|
|
|
8
8
|
import { FileScanner } from "../services/file-scanner.js";
|
|
9
9
|
import { StyleFilePatterns, ComponentFilePatterns } from "../services/file-patterns.js";
|
|
10
10
|
import { LintRunner } from "../services/lint-runner.js";
|
|
11
|
-
import { ReportGenerator } from "../services/report-generator.js";
|
|
11
|
+
import { ReportGenerator, CsvReportGenerator } from "../services/report-generator.js";
|
|
12
12
|
import { DEFAULT_ESLINT_CONFIG_PATH, DEFAULT_STYLELINT_CONFIG_PATH, LINTER_CLI_VERSION } from "../services/config.resolver.js";
|
|
13
13
|
function registerReportCommand(program) {
|
|
14
|
-
program.command("report").description("Generate
|
|
14
|
+
program.command("report").description("Generate report from linting results").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("-o, --output <path>", "Output directory for reports (defaults to current directory)").option("--config-stylelint <path>", "Path to stylelint config file").option("--config-eslint <path>", "Path to eslint config file").addOption(new Option("--format <type>", "Output format").choices(["sarif", "csv"]).default("sarif")).action(async (directory, options) => {
|
|
15
15
|
const spinner = ora("Starting report generation...");
|
|
16
16
|
try {
|
|
17
17
|
const normalizedOptions = normalizeCliOptions(options, {
|
|
@@ -23,8 +23,7 @@ function registerReportCommand(program) {
|
|
|
23
23
|
} else if (options.directory) {
|
|
24
24
|
Logger.newLine().warning(chalk.yellow(
|
|
25
25
|
`WARNING: --directory, -d option is deprecated. Supply as argument instead.
|
|
26
|
-
Example: npx @salesforce-ux/slds-linter report ${options.directory}
|
|
27
|
-
`
|
|
26
|
+
Example: npx @salesforce-ux/slds-linter report ${options.directory}`
|
|
28
27
|
));
|
|
29
28
|
}
|
|
30
29
|
spinner.start();
|
|
@@ -44,20 +43,30 @@ Example: npx @salesforce-ux/slds-linter report ${options.directory}
|
|
|
44
43
|
const componentResults = await LintRunner.runLinting(componentFileBatches, "component", {
|
|
45
44
|
configPath: normalizedOptions.configEslint
|
|
46
45
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
const reportFormat = options.format.toLowerCase();
|
|
47
|
+
if (reportFormat === "sarif") {
|
|
48
|
+
spinner.text = "Generating SARIF report...";
|
|
49
|
+
const combinedReportPath = path.join(normalizedOptions.output, "slds-linter-report.sarif");
|
|
50
|
+
await ReportGenerator.generateSarifReport([...styleResults, ...componentResults], {
|
|
51
|
+
outputPath: combinedReportPath,
|
|
52
|
+
toolName: "slds-linter",
|
|
53
|
+
toolVersion: LINTER_CLI_VERSION
|
|
54
|
+
});
|
|
55
|
+
Logger.success(`SARIF report generated: ${combinedReportPath}
|
|
56
|
+
`);
|
|
57
|
+
} else if (reportFormat === "csv") {
|
|
58
|
+
spinner.text = "Generating CSV report...";
|
|
59
|
+
const csvReportPath = await CsvReportGenerator.generate([...styleResults, ...componentResults]);
|
|
60
|
+
Logger.success(`CSV report generated: ${csvReportPath}
|
|
56
61
|
`);
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error(`Invalid format: ${reportFormat}. Supported formats: sarif, csv`);
|
|
64
|
+
}
|
|
65
|
+
spinner.succeed("Report generation completed");
|
|
57
66
|
process.exit(0);
|
|
58
67
|
} catch (error) {
|
|
59
68
|
spinner?.fail("Report generation failed");
|
|
60
|
-
Logger.error(`Failed to generate
|
|
69
|
+
Logger.error(`Failed to generate report: ${error.message}`);
|
|
61
70
|
process.exit(1);
|
|
62
71
|
}
|
|
63
72
|
});
|
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("0.1.4-alpha.
|
|
22
|
+
program.description("SLDS Linter CLI tool for linting styles and components").version("0.1.4-alpha.2");
|
|
23
23
|
}
|
|
24
24
|
registerLintCommand(program);
|
|
25
25
|
registerReportCommand(program);
|
|
@@ -5,7 +5,7 @@ var DEFAULT_ESLINT_CONFIG_PATH = resolvePath("@salesforce-ux/eslint-plugin-slds/
|
|
|
5
5
|
var DEFAULT_STYLELINT_CONFIG_PATH = resolvePath("@salesforce-ux/stylelint-plugin-slds/.stylelintrc.yml", import.meta);
|
|
6
6
|
var STYLELINT_VERSION = "16.14.1";
|
|
7
7
|
var ESLINT_VERSION = "8.57.1";
|
|
8
|
-
var LINTER_CLI_VERSION = "0.1.4-alpha.
|
|
8
|
+
var LINTER_CLI_VERSION = "0.1.4-alpha.2";
|
|
9
9
|
var getRuleDescription = (ruleId) => {
|
|
10
10
|
const ruleIdWithoutNameSpace = `${ruleId}`.replace(/\@salesforce-ux\//, "");
|
|
11
11
|
return ruleMetadata(ruleIdWithoutNameSpace)?.ruleDesc || "--";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/services/report-generator.ts
|
|
2
2
|
import path from "path";
|
|
3
|
-
import fs from "fs/promises";
|
|
3
|
+
import fs, { writeFile } from "fs/promises";
|
|
4
|
+
import { mkConfig, generateCsv, asString } from "export-to-csv";
|
|
4
5
|
import { SarifBuilder, SarifRunBuilder, SarifResultBuilder, SarifRuleBuilder } from "node-sarif-builder";
|
|
5
6
|
import { createWriteStream } from "fs";
|
|
6
7
|
import { JsonStreamStringify } from "json-stream-stringify";
|
|
@@ -82,7 +83,7 @@ var ReportGenerator = class {
|
|
|
82
83
|
ruleId: replaceNamespaceinRules(error.ruleId),
|
|
83
84
|
level: "error",
|
|
84
85
|
messageText: error.message,
|
|
85
|
-
fileUri: lintResult.filePath,
|
|
86
|
+
fileUri: path.relative(process.cwd(), lintResult.filePath),
|
|
86
87
|
startLine: error.line,
|
|
87
88
|
startColumn: error.column,
|
|
88
89
|
endLine: error.line,
|
|
@@ -95,7 +96,7 @@ var ReportGenerator = class {
|
|
|
95
96
|
ruleId: replaceNamespaceinRules(warning.ruleId),
|
|
96
97
|
level: "warning",
|
|
97
98
|
messageText: warning.message,
|
|
98
|
-
fileUri: lintResult.filePath,
|
|
99
|
+
fileUri: path.relative(process.cwd(), lintResult.filePath),
|
|
99
100
|
startLine: warning.line,
|
|
100
101
|
startColumn: warning.column,
|
|
101
102
|
endLine: warning.line,
|
|
@@ -105,6 +106,55 @@ var ReportGenerator = class {
|
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
};
|
|
109
|
+
var CsvReportGenerator = class {
|
|
110
|
+
static async generate(results) {
|
|
111
|
+
const csvConfig = mkConfig({
|
|
112
|
+
filename: "slds-linter-report",
|
|
113
|
+
fieldSeparator: ",",
|
|
114
|
+
quoteStrings: true,
|
|
115
|
+
decimalSeparator: ".",
|
|
116
|
+
useTextFile: false,
|
|
117
|
+
useBom: true,
|
|
118
|
+
useKeysAsHeaders: true
|
|
119
|
+
});
|
|
120
|
+
const cwd = process.cwd();
|
|
121
|
+
const transformedResults = results.flatMap(
|
|
122
|
+
(result) => [
|
|
123
|
+
...result.errors.map((error) => ({
|
|
124
|
+
"File Path": path.relative(cwd, result.filePath),
|
|
125
|
+
"Message": error.message,
|
|
126
|
+
"Severity": "error",
|
|
127
|
+
"Rule ID": replaceNamespaceinRules(error.ruleId || "N/A"),
|
|
128
|
+
"Start Line": error.line,
|
|
129
|
+
"Start Column": error.column,
|
|
130
|
+
"End Line": error.endLine || error.line,
|
|
131
|
+
// Default to start line if missing
|
|
132
|
+
"End Column": error.endColumn || error.column
|
|
133
|
+
// Default to start column if missing
|
|
134
|
+
})),
|
|
135
|
+
...result.warnings.map((warning) => ({
|
|
136
|
+
"File Path": path.relative(cwd, result.filePath),
|
|
137
|
+
"Message": warning.message,
|
|
138
|
+
"Severity": "warning",
|
|
139
|
+
"Rule ID": replaceNamespaceinRules(warning.ruleId || "N/A"),
|
|
140
|
+
"Start Line": warning.line,
|
|
141
|
+
"Start Column": warning.column,
|
|
142
|
+
"End Line": warning.endLine || warning.line,
|
|
143
|
+
// Default to start line if missing
|
|
144
|
+
"End Column": warning.endColumn || warning.column
|
|
145
|
+
// Default to start column if missing
|
|
146
|
+
}))
|
|
147
|
+
]
|
|
148
|
+
);
|
|
149
|
+
const csvData = generateCsv(csvConfig)(transformedResults);
|
|
150
|
+
const csvString = asString(csvData);
|
|
151
|
+
const csvReportPath = path.join(cwd, `${csvConfig.filename}.csv`);
|
|
152
|
+
return writeFile(csvReportPath, csvString).then(() => {
|
|
153
|
+
return csvReportPath;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
108
157
|
export {
|
|
158
|
+
CsvReportGenerator,
|
|
109
159
|
ReportGenerator
|
|
110
160
|
};
|
package/build/types/index.d.ts
CHANGED
package/build/utils/cli-args.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce-ux/slds-linter",
|
|
3
|
-
"version": "0.1.4-alpha.
|
|
3
|
+
"version": "0.1.4-alpha.2",
|
|
4
4
|
"description": "SLDS Linter CLI tool for linting styles and components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lightning design system linter",
|
|
@@ -20,13 +20,14 @@
|
|
|
20
20
|
"slds-linter": "./build/index.js"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@salesforce-ux/eslint-plugin-slds": "0.1.4-alpha.
|
|
24
|
-
"@salesforce-ux/stylelint-plugin-slds": "0.1.4-alpha.
|
|
23
|
+
"@salesforce-ux/eslint-plugin-slds": "0.1.4-alpha.2",
|
|
24
|
+
"@salesforce-ux/stylelint-plugin-slds": "0.1.4-alpha.2",
|
|
25
25
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
26
26
|
"@typescript-eslint/parser": "^5.0.0",
|
|
27
27
|
"chalk": "^4.1.2",
|
|
28
28
|
"commander": "^13.1.0",
|
|
29
29
|
"eslint": "^8.0.0",
|
|
30
|
+
"export-to-csv": "^1.4.0",
|
|
30
31
|
"globby": "^14.1.0",
|
|
31
32
|
"import-meta-resolve": "^4.1.0",
|
|
32
33
|
"json-stream-stringify": "^3.1.6",
|