@salesforce-ux/slds-linter 0.0.13-alpha.0 → 0.1.1
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/README.md +41 -22
- package/build/commands/emit.js +3 -5
- package/build/commands/lint-components.js +1 -1
- package/build/commands/lint-styles.js +2 -2
- package/build/commands/lint.js +4 -24
- package/build/index.js +81 -2
- package/build/services/report-generator.js +9 -11
- package/build/utils/cli-args.js +1 -0
- package/build/utils/lintResultsUtil.d.ts +8 -1
- package/build/utils/lintResultsUtil.js +7 -3
- package/package.json +12 -14
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@ SLDS Linter provides custom linting rules specifically built for Salesforce Ligh
|
|
|
9
9
|
- Component Linting:
|
|
10
10
|
The utility supports linting for two types of Salesforce Lightning components:
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
LWC and Aura components.
|
|
13
|
+
- LWC Components (.html): Linting is applied to Lightning Web Components.
|
|
14
14
|
- Aura Components (.cmp): Linting is applied to Aura Components.
|
|
15
15
|
|
|
16
16
|
* Stylelint for CSS Files:
|
|
@@ -29,6 +29,15 @@ SLDS Linter CLI tool works best with the [Active LTS](https://nodejs.org/en/abou
|
|
|
29
29
|
#### **Minimum Required Node.js Version**
|
|
30
30
|
- The minimum supported Node.js version is **v20.18.3**.
|
|
31
31
|
- We recommend using the latest **Active LTS** release for the best performance and compatibility.
|
|
32
|
+
- The tool verifies the Node.js version at the beginning of the process. If the Node.js requirements are met, the subsequent steps will proceed smoothly.
|
|
33
|
+
|
|
34
|
+
#### Extensions
|
|
35
|
+
To enhance your linting and error analysis experience, consider installing the following VSCode extensions:
|
|
36
|
+
|
|
37
|
+
- *[ESLint Extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)*: This extension is essential for JavaScript/TypeScript linting and will show squiggly lines over code that violates the ESLint rules.
|
|
38
|
+
- *[Stylelint Extension](https://marketplace.visualstudio.com/items?itemName=stylelint.vscode-stylelint)*: For linting CSS, SCSS, and other stylesheets, this extension will highlight errors with squiggly lines.
|
|
39
|
+
- *[SARIF Viewer Extension](https://marketplace.visualstudio.com/items?itemName=MS-SarifVSCode.sarif-viewer)*: For better viewing and navigating through SARIF files.
|
|
40
|
+
These extensions will significantly improve your development workflow and make it easier to navigate and address linting issues.
|
|
32
41
|
|
|
33
42
|
|
|
34
43
|
### Command-Line Interface (CLI)
|
|
@@ -37,27 +46,29 @@ To see what all options does slds-linter provide please run `npx @salesforce-ux/
|
|
|
37
46
|
For the first time, it will ask to install the package. Please reply with `y` as yes to install the package.
|
|
38
47
|
|
|
39
48
|
```
|
|
40
|
-
Usage:
|
|
49
|
+
Usage: npx @salesforce-ux/slds-linter@latest [options] [command]
|
|
41
50
|
|
|
42
|
-
|
|
51
|
+
SLDS Linter CLI tool for linting styles and components
|
|
43
52
|
|
|
44
53
|
Options:
|
|
45
|
-
-V, --version output the version number
|
|
46
|
-
-h, --help display help for command
|
|
54
|
+
-V, --version output the version number
|
|
55
|
+
-h, --help display help for command
|
|
47
56
|
|
|
48
57
|
Commands:
|
|
49
|
-
lint:styles [options] Run stylelint on all style files
|
|
50
|
-
lint:components [options] Run eslint on all markup files
|
|
51
|
-
lint [options] Run both style and component linting
|
|
52
|
-
report [options] Generate SARIF report from linting results
|
|
53
|
-
|
|
58
|
+
lint:styles [options] Run stylelint on all style files
|
|
59
|
+
lint:components [options] Run eslint on all markup files
|
|
60
|
+
lint [options] Run both style and component linting
|
|
61
|
+
report [options] Generate SARIF report from linting results
|
|
62
|
+
emit [options] Emits the configuration files used by slds-linter cli
|
|
63
|
+
help [command] display help for command
|
|
54
64
|
```
|
|
55
65
|
|
|
56
66
|
- `npx @salesforce-ux/slds-linter lint` - Runs the ESlint and Stylelint rules on your HTML/CSS/CMP files and outputs issues.
|
|
57
67
|
- `npx @salesforce-ux/slds-linter lint:styles` - Runs the Stylelint rules on your CSS files and outputs issues.
|
|
58
68
|
- `npx @salesforce-ux/slds-linter lint:components` - Runs the ESlint rules on your HTML/CMP files and outputs issues.
|
|
59
|
-
- `npx @salesforce-ux/slds-linter fix`: Attempts to automatically fix violations.
|
|
69
|
+
- `npx @salesforce-ux/slds-linter lint --fix`: Attempts to automatically fix violations.
|
|
60
70
|
- `npx @salesforce-ux/slds-linter report`: Generates a SARIF report for static analysis.
|
|
71
|
+
- `npx @salesforce-ux/slds-linter emit`: Emits the configuration files used by slds-linter cli (defaults to current directory).
|
|
61
72
|
|
|
62
73
|
#### Options available with each command
|
|
63
74
|
|
|
@@ -66,20 +77,28 @@ help [command] display help for command
|
|
|
66
77
|
| `-d, --directory <path>` | Target directory to scan (defaults to current directory) | lint, lint:styles, lint:components, report |
|
|
67
78
|
| `-o, --output <path>` | Output directory for reports (defaults to current directory) | report |
|
|
68
79
|
| `--fix` | Automatically fix problems | lint, lint:styles, lint:components |
|
|
69
|
-
| `--config <path>` | Path to eslint/stylelint config file'
|
|
70
|
-
| `--config-style <path>` |
|
|
71
|
-
| `--config-eslint <path>` | Path to eslint config file'
|
|
80
|
+
| `--config <path>` | Path to eslint/stylelint config file' | lint:styles, lint:components |
|
|
81
|
+
| `--config-style <path>` | Path to stylelint config file' | lint |
|
|
82
|
+
| `--config-eslint <path>` | Path to eslint config file' | lint |
|
|
72
83
|
| `--editor <editor>` | Editor to open files with (e.g., vscode, atom, sublime). Defaults to vscode | lint,lint:styles, lint:components |
|
|
73
84
|
|
|
74
|
-
|
|
75
|
-
These options can also be visualised by using `--help` with each command. For example: Running `slds-linter lint --help` will give the options which can be used along with `lint`.
|
|
85
|
+
These options can also be visualised by using `--help` with each command. For example: Running `npx @salesforce-ux/slds-linter lint --help` will give the options which can be used along with `lint`.
|
|
76
86
|
|
|
77
87
|
#### Detailed Steps
|
|
78
88
|
|
|
79
|
-
1. Run `npx @salesforce-ux/slds-linter lint` to see the lint output on terminal. For specific files, you can go ahead with either `npx @salesforce-ux/slds-linter lint:styles` for lint errors within css files or `npx @salesforce-ux/slds-linter lint:components` for lint errors within html/cmp files. To run the linting only on a specific folder, use the option `-d` to specify the directory to be linted.
|
|
80
|
-
2.
|
|
81
|
-
3.
|
|
82
|
-
4.
|
|
83
|
-
5.
|
|
89
|
+
1. Run `npx @salesforce-ux/slds-linter lint` to see the lint output on terminal. For specific files, you can go ahead with either `npx @salesforce-ux/slds-linter lint:styles` for lint errors within css files or `npx @salesforce-ux/slds-linter lint:components` for lint errors within html/cmp files. To run the linting only on a specific folder, use the option `-d` to specify the directory to be linted.
|
|
90
|
+
2. The linting output displayed in the console includes the row and column numbers on the left. Navigate to the specific line of concern in the source code by clicking on these numbers (Command + Click on Mac).
|
|
91
|
+
3. To run SLDS Linter, in Terminal, run `npx @salesforce-ux/slds-linter report` to generate a Sarif report in the project root directory. To run it on a different directory, use `-d` to run the report on that directory. For output, `-o` can be used to specify a different output folder for the genreated sarif. It will be named as `slds-linter-report.sarif`.
|
|
92
|
+
4. Open the generated Sarif file.
|
|
93
|
+
5. Make a note of how many components SLDS Linter has identified that you must update.
|
|
94
|
+
6. Run `npx @salesforce-ux/slds-linter lint --fix` to automatically fix validation errors in bulk.
|
|
95
|
+
7. Run `npx @salesforce-ux/slds-linter emit` to emit the configuration files used by slds-linter cli, defaults to current working directory. These configuration files will be discovered by VSCode ESLint/Stylelint extensions to display squiggly lines in css/html files when opened in editor. Please ensure ESLint and Stylelint extensions are enabled.
|
|
96
|
+
|
|
97
|
+
#### Troubleshooting SARIF Viewer Navigation
|
|
98
|
+
If the SARIF viewer is not automatically navigating you to the line of code when you click on an error/warning, follow these steps:
|
|
99
|
+
|
|
100
|
+
- Click on "Locate" in the popup that appears from the extension.
|
|
101
|
+
- Locate the file in the file explorer or editor.
|
|
102
|
+
- Once the file is located, you should be able to click on the errors in the SARIF viewer, and it will navigate you directly to the specific line of code.
|
|
84
103
|
|
|
85
104
|
For any questions or issues, feel free to reach out to the maintainers or open an issue in the repository.
|
package/build/commands/emit.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
DEFAULT_STYLELINT_CONFIG_PATH
|
|
8
8
|
} from "../services/config.resolver.js";
|
|
9
9
|
import path from "path";
|
|
10
|
-
import {
|
|
10
|
+
import { copyFile } from "fs/promises";
|
|
11
11
|
function registerEmitCommand(program) {
|
|
12
12
|
program.command("emit").description("Emits the configuration files used by slds-linter cli").option(
|
|
13
13
|
"-d, --directory <path>",
|
|
@@ -23,7 +23,7 @@ function registerEmitCommand(program) {
|
|
|
23
23
|
normalizedOptions.directory,
|
|
24
24
|
path.basename(normalizedOptions.configStyle)
|
|
25
25
|
);
|
|
26
|
-
|
|
26
|
+
await copyFile(normalizedOptions.configStyle, destStyleConfigPath);
|
|
27
27
|
Logger.success(chalk.green(`Stylelint configuration created at:
|
|
28
28
|
${destStyleConfigPath}
|
|
29
29
|
`));
|
|
@@ -31,9 +31,7 @@ ${destStyleConfigPath}
|
|
|
31
31
|
normalizedOptions.directory,
|
|
32
32
|
path.basename(normalizedOptions.configEslint)
|
|
33
33
|
);
|
|
34
|
-
|
|
35
|
-
`cp ${normalizedOptions.configEslint} ${destESLintConfigPath}`
|
|
36
|
-
);
|
|
34
|
+
await copyFile(normalizedOptions.configEslint, destESLintConfigPath);
|
|
37
35
|
Logger.success(chalk.green(`ESLint configuration created at:
|
|
38
36
|
${destESLintConfigPath}
|
|
39
37
|
`));
|
|
@@ -22,7 +22,7 @@ function registerLintComponentsCommand(program) {
|
|
|
22
22
|
});
|
|
23
23
|
const totalFiles = fileBatches.reduce((sum, batch) => sum + batch.length, 0);
|
|
24
24
|
Logger.info(chalk.blue(`Scanned ${totalFiles} file(s).`));
|
|
25
|
-
Logger.info(chalk.blue(
|
|
25
|
+
Logger.info(chalk.blue(`Running linting${normalizedOptions.fix ? " with autofix" : ""}...`));
|
|
26
26
|
const results = await LintRunner.runLinting(fileBatches, "component", {
|
|
27
27
|
fix: normalizedOptions.fix,
|
|
28
28
|
configPath: normalizedOptions.config
|
|
@@ -13,7 +13,7 @@ function registerLintStylesCommand(program) {
|
|
|
13
13
|
try {
|
|
14
14
|
Logger.info(chalk.blue("Starting linting of style files..."));
|
|
15
15
|
const normalizedOptions = normalizeCliOptions(options, {
|
|
16
|
-
|
|
16
|
+
config: DEFAULT_STYLELINT_CONFIG_PATH
|
|
17
17
|
});
|
|
18
18
|
Logger.info(chalk.blue("Scanning for style files..."));
|
|
19
19
|
const fileBatches = await FileScanner.scanFiles(normalizedOptions.directory, {
|
|
@@ -22,7 +22,7 @@ function registerLintStylesCommand(program) {
|
|
|
22
22
|
});
|
|
23
23
|
const totalFiles = fileBatches.reduce((sum, batch) => sum + batch.length, 0);
|
|
24
24
|
Logger.info(chalk.blue(`Scanned ${totalFiles} file(s).`));
|
|
25
|
-
Logger.info(chalk.blue(
|
|
25
|
+
Logger.info(chalk.blue(`Running stylelint${normalizedOptions.fix ? " with autofix" : ""}...`));
|
|
26
26
|
const results = await LintRunner.runLinting(fileBatches, "style", {
|
|
27
27
|
fix: normalizedOptions.fix,
|
|
28
28
|
configPath: normalizedOptions.config
|
package/build/commands/lint.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// src/commands/lint.ts
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { createClickableLineCol } from "../utils/editorLinkUtil.js";
|
|
5
3
|
import { printLintResults } from "../utils/lintResultsUtil.js";
|
|
6
4
|
import { normalizeCliOptions } from "../utils/cli-args.js";
|
|
7
5
|
import { Logger } from "../utils/logger.js";
|
|
@@ -13,7 +11,7 @@ function registerLintCommand(program) {
|
|
|
13
11
|
program.command("lint").description("Run both style and component linting").option("-d, --directory <path>", "Target directory to scan (defaults to current directory)").option("--fix", "Automatically fix problems").option("--config-style <path>", "Path to stylelint config file").option("--config-eslint <path>", "Path to eslint config file").option("--editor <editor>", "Editor to open files with (e.g., vscode, atom, sublime). Defaults to vscode", "vscode").action(async (options) => {
|
|
14
12
|
const startTime = Date.now();
|
|
15
13
|
try {
|
|
16
|
-
Logger.info(chalk.blue("Starting
|
|
14
|
+
Logger.info(chalk.blue("Starting lint process..."));
|
|
17
15
|
const normalizedOptions = normalizeCliOptions(options, {
|
|
18
16
|
configStyle: DEFAULT_STYLELINT_CONFIG_PATH,
|
|
19
17
|
configEslint: DEFAULT_ESLINT_CONFIG_PATH
|
|
@@ -26,31 +24,12 @@ function registerLintCommand(program) {
|
|
|
26
24
|
const totalStyleFiles = styleFileBatches.reduce((sum, batch) => sum + batch.length, 0);
|
|
27
25
|
Logger.info(chalk.blue(`Found ${totalStyleFiles} style file(s). Running stylelint...
|
|
28
26
|
`));
|
|
27
|
+
Logger.info(chalk.blue(`Running stylelint${normalizedOptions.fix ? " with autofix" : ""}...`));
|
|
29
28
|
const styleResults = await LintRunner.runLinting(styleFileBatches, "style", {
|
|
30
29
|
fix: normalizedOptions.fix,
|
|
31
30
|
configPath: normalizedOptions.configStyle
|
|
32
31
|
});
|
|
33
|
-
styleResults.
|
|
34
|
-
const hasErrors = result.errors?.length > 0;
|
|
35
|
-
const hasWarnings = result.warnings?.length > 0;
|
|
36
|
-
if (!hasErrors && !hasWarnings) return;
|
|
37
|
-
const absolutePath = result.filePath || "";
|
|
38
|
-
const relativeFile = path.relative(process.cwd(), absolutePath) || "Unknown file";
|
|
39
|
-
Logger.info(`
|
|
40
|
-
${chalk.bold(relativeFile)}`);
|
|
41
|
-
result.errors?.forEach((err) => {
|
|
42
|
-
const lineCol = `${err.line}:${err.column}`;
|
|
43
|
-
const clickable = createClickableLineCol(lineCol, absolutePath, err.line, err.column, normalizedOptions.editor);
|
|
44
|
-
const ruleId = err.ruleId ? chalk.dim(err.ruleId) : "";
|
|
45
|
-
Logger.error(` ${clickable} ${err.message} ${ruleId}`);
|
|
46
|
-
});
|
|
47
|
-
result.warnings?.forEach((warn) => {
|
|
48
|
-
const lineCol = `${warn.line}:${warn.column}`;
|
|
49
|
-
const clickable = createClickableLineCol(lineCol, absolutePath, warn.line, warn.column, normalizedOptions.editor);
|
|
50
|
-
const ruleId = warn.ruleId ? chalk.dim(warn.ruleId) : "";
|
|
51
|
-
Logger.warning(` ${clickable} ${warn.message} ${ruleId}`);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
32
|
+
printLintResults(styleResults, normalizedOptions.editor);
|
|
54
33
|
const styleErrorCount = styleResults.reduce((sum, r) => sum + r.errors.length, 0);
|
|
55
34
|
const styleWarningCount = styleResults.reduce((sum, r) => sum + r.warnings.length, 0);
|
|
56
35
|
Logger.info(chalk.blue("\nScanning component files..."));
|
|
@@ -61,6 +40,7 @@ ${chalk.bold(relativeFile)}`);
|
|
|
61
40
|
const totalComponentFiles = componentFileBatches.reduce((sum, batch) => sum + batch.length, 0);
|
|
62
41
|
Logger.info(chalk.blue(`Found ${totalComponentFiles} component file(s). Running eslint...
|
|
63
42
|
`));
|
|
43
|
+
Logger.info(chalk.blue(`Running linting${normalizedOptions.fix ? " with autofix" : ""}...`));
|
|
64
44
|
const componentResults = await LintRunner.runLinting(componentFileBatches, "component", {
|
|
65
45
|
fix: normalizedOptions.fix,
|
|
66
46
|
configPath: normalizedOptions.configEslint
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,75 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
4
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// package.json
|
|
8
|
+
var require_package = __commonJS({
|
|
9
|
+
"package.json"(exports, module) {
|
|
10
|
+
module.exports = {
|
|
11
|
+
name: "@salesforce-ux/slds-linter",
|
|
12
|
+
version: "0.1.0",
|
|
13
|
+
description: "SLDS Linter CLI tool for linting styles and components",
|
|
14
|
+
keywords: [
|
|
15
|
+
"lightning design system linter",
|
|
16
|
+
"SLDS Linter",
|
|
17
|
+
"SLDS2 Linter",
|
|
18
|
+
"SLDS Stylelint",
|
|
19
|
+
"SLDS ESLint"
|
|
20
|
+
],
|
|
21
|
+
author: "UXF Tooling Team",
|
|
22
|
+
type: "module",
|
|
23
|
+
main: "build/index.js",
|
|
24
|
+
files: [
|
|
25
|
+
"build/**",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
bin: {
|
|
29
|
+
"slds-linter": "./build/index.js"
|
|
30
|
+
},
|
|
31
|
+
scripts: {
|
|
32
|
+
prepublishOnly: "clean-pkg-json",
|
|
33
|
+
build: "gulp build",
|
|
34
|
+
dev: "gulp dev",
|
|
35
|
+
test: 'NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" npx jest',
|
|
36
|
+
lint: "eslint src/**/*.ts"
|
|
37
|
+
},
|
|
38
|
+
dependencies: {
|
|
39
|
+
"@salesforce-ux/eslint-plugin-slds": "0.1.0",
|
|
40
|
+
"@salesforce-ux/stylelint-plugin-slds": "0.1.0",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
42
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
43
|
+
chalk: "^4.1.2",
|
|
44
|
+
commander: "^13.1.0",
|
|
45
|
+
eslint: "^8.0.0",
|
|
46
|
+
glob: "^11.0.0",
|
|
47
|
+
"json-stream-stringify": "^3.1.6",
|
|
48
|
+
"node-sarif-builder": "^3.2.0",
|
|
49
|
+
ora: "^5.4.1",
|
|
50
|
+
semver: "^7.7.1",
|
|
51
|
+
stylelint: "^16.10.0"
|
|
52
|
+
},
|
|
53
|
+
devDependencies: {
|
|
54
|
+
"@types/jest": "^29.5.14",
|
|
55
|
+
jest: "^29.7.0",
|
|
56
|
+
"ts-jest": "^29.2.5"
|
|
57
|
+
},
|
|
58
|
+
license: "ISC",
|
|
59
|
+
repository: {
|
|
60
|
+
type: "git",
|
|
61
|
+
url: "git+https://github.com/salesforce-ux/slds-linter.git"
|
|
62
|
+
},
|
|
63
|
+
bugs: {
|
|
64
|
+
url: "https://github.com/salesforce-ux/slds-linter/issues"
|
|
65
|
+
},
|
|
66
|
+
homepage: "https://github.com/salesforce-ux/slds-linter/tree/main/packages/cli#slds-linter",
|
|
67
|
+
publishConfig: {
|
|
68
|
+
registry: "https://registry.npmjs.org"
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
});
|
|
2
73
|
|
|
3
74
|
// src/index.ts
|
|
4
75
|
import { Command } from "commander";
|
|
@@ -9,7 +80,6 @@ import { registerReportCommand } from "./commands/report.js";
|
|
|
9
80
|
import { registerEmitCommand } from "./commands/emit.js";
|
|
10
81
|
import { Logger } from "./utils/logger.js";
|
|
11
82
|
import { validateNodeVersion } from "./utils/nodeVersionUtil.js";
|
|
12
|
-
import pkg from "../package.json" with { type: "json" };
|
|
13
83
|
validateNodeVersion();
|
|
14
84
|
process.on("unhandledRejection", (error) => {
|
|
15
85
|
Logger.error(`Unhandled rejection: ${error}`);
|
|
@@ -20,10 +90,19 @@ process.on("uncaughtException", (error) => {
|
|
|
20
90
|
process.exit(1);
|
|
21
91
|
});
|
|
22
92
|
var program = new Command();
|
|
23
|
-
program.name("npx @salesforce-ux/slds-linter@latest").
|
|
93
|
+
program.name("npx @salesforce-ux/slds-linter@latest").showHelpAfterError();
|
|
94
|
+
function registerVersion() {
|
|
95
|
+
let pkg = { description: "", version: "" };
|
|
96
|
+
try {
|
|
97
|
+
pkg = require_package();
|
|
98
|
+
} catch (e) {
|
|
99
|
+
}
|
|
100
|
+
program.description(pkg.description).version(pkg.version);
|
|
101
|
+
}
|
|
24
102
|
registerLintStylesCommand(program);
|
|
25
103
|
registerLintComponentsCommand(program);
|
|
26
104
|
registerLintCommand(program);
|
|
27
105
|
registerReportCommand(program);
|
|
28
106
|
registerEmitCommand(program);
|
|
107
|
+
registerVersion();
|
|
29
108
|
program.parse(process.argv);
|
|
@@ -6,6 +6,7 @@ import { SarifBuilder, SarifRunBuilder, SarifResultBuilder, SarifRuleBuilder } f
|
|
|
6
6
|
import { createWriteStream } from "fs";
|
|
7
7
|
import { JsonStreamStringify } from "json-stream-stringify";
|
|
8
8
|
import { getRuleDescription } from "./config.resolver.js";
|
|
9
|
+
import { replaceNamespaceinRules } from "../utils/lintResultsUtil.js";
|
|
9
10
|
var ReportGenerator = class {
|
|
10
11
|
/**
|
|
11
12
|
* Generate SARIF report from lint results
|
|
@@ -21,9 +22,8 @@ var ReportGenerator = class {
|
|
|
21
22
|
const rules = this.extractRules(results);
|
|
22
23
|
for (const rule of rules) {
|
|
23
24
|
const ruleBuilder = new SarifRuleBuilder().initSimple({
|
|
24
|
-
ruleId: rule.id,
|
|
25
|
-
shortDescriptionText: rule.shortDescription?.text
|
|
26
|
-
helpUri: rule.helpUri
|
|
25
|
+
ruleId: replaceNamespaceinRules(rule.id),
|
|
26
|
+
shortDescriptionText: rule.shortDescription?.text
|
|
27
27
|
});
|
|
28
28
|
runBuilder.addRule(ruleBuilder);
|
|
29
29
|
}
|
|
@@ -54,11 +54,10 @@ var ReportGenerator = class {
|
|
|
54
54
|
for (const error of result.errors) {
|
|
55
55
|
if (!rules.has(error.ruleId)) {
|
|
56
56
|
rules.set(error.ruleId, {
|
|
57
|
-
id: error.ruleId,
|
|
57
|
+
id: replaceNamespaceinRules(error.ruleId),
|
|
58
58
|
shortDescription: {
|
|
59
|
-
text: getRuleDescription(error.ruleId)
|
|
59
|
+
text: getRuleDescription(replaceNamespaceinRules(error.ruleId))
|
|
60
60
|
},
|
|
61
|
-
helpUri: error.ruleId.startsWith("slds/") ? `https://github.com/salesforce/slds-linting-plugin/blob/main/docs/rules/${error.ruleId.replace("slds/", "")}.md` : `https://stylelint.io/user-guide/rules/${error.ruleId}`,
|
|
62
61
|
properties: {
|
|
63
62
|
category: "Style"
|
|
64
63
|
}
|
|
@@ -68,11 +67,10 @@ var ReportGenerator = class {
|
|
|
68
67
|
for (const warning of result.warnings) {
|
|
69
68
|
if (!rules.has(warning.ruleId)) {
|
|
70
69
|
rules.set(warning.ruleId, {
|
|
71
|
-
id: warning.ruleId,
|
|
70
|
+
id: replaceNamespaceinRules(warning.ruleId),
|
|
72
71
|
shortDescription: {
|
|
73
|
-
text: getRuleDescription(warning.ruleId)
|
|
72
|
+
text: getRuleDescription(replaceNamespaceinRules(warning.ruleId))
|
|
74
73
|
},
|
|
75
|
-
helpUri: warning.ruleId.startsWith("slds/") ? `https://github.com/salesforce/slds-linting-plugin/blob/main/docs/rules/${warning.ruleId.replace("slds/", "")}.md` : `https://stylelint.io/user-guide/rules/${warning.ruleId}`,
|
|
76
74
|
properties: {
|
|
77
75
|
category: "Style"
|
|
78
76
|
}
|
|
@@ -88,7 +86,7 @@ var ReportGenerator = class {
|
|
|
88
86
|
static addResultsToSarif(runBuilder, lintResult) {
|
|
89
87
|
for (const error of lintResult.errors) {
|
|
90
88
|
const resultBuilder = new SarifResultBuilder().initSimple({
|
|
91
|
-
ruleId: error.ruleId,
|
|
89
|
+
ruleId: replaceNamespaceinRules(error.ruleId),
|
|
92
90
|
level: "error",
|
|
93
91
|
messageText: error.message,
|
|
94
92
|
fileUri: lintResult.filePath,
|
|
@@ -101,7 +99,7 @@ var ReportGenerator = class {
|
|
|
101
99
|
}
|
|
102
100
|
for (const warning of lintResult.warnings) {
|
|
103
101
|
const resultBuilder = new SarifResultBuilder().initSimple({
|
|
104
|
-
ruleId: warning.ruleId,
|
|
102
|
+
ruleId: replaceNamespaceinRules(warning.ruleId),
|
|
105
103
|
level: "warning",
|
|
106
104
|
messageText: warning.message,
|
|
107
105
|
fileUri: lintResult.filePath,
|
package/build/utils/cli-args.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { LintResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param id - Rule id
|
|
5
|
+
* @returns updated Rule id without the namespace @salesforce-ux
|
|
6
|
+
*/
|
|
7
|
+
export declare function replaceNamespaceinRules(id: string): string;
|
|
1
8
|
/**
|
|
2
9
|
* Prints detailed lint results for each file that has issues.
|
|
3
10
|
*
|
|
4
11
|
* @param results - Array of lint results.
|
|
5
12
|
* @param editor - The chosen editor for clickable links (e.g., "vscode", "atom", "sublime").
|
|
6
13
|
*/
|
|
7
|
-
export declare function printLintResults(results:
|
|
14
|
+
export declare function printLintResults(results: LintResult[], editor: string): void;
|
|
@@ -3,6 +3,9 @@ import chalk from "chalk";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { createClickableLineCol } from "./editorLinkUtil.js";
|
|
5
5
|
import { Logger } from "../utils/logger.js";
|
|
6
|
+
function replaceNamespaceinRules(id) {
|
|
7
|
+
return id.includes("@salesforce-ux/") ? id.replace("@salesforce-ux/", "") : id;
|
|
8
|
+
}
|
|
6
9
|
function printLintResults(results, editor) {
|
|
7
10
|
results.forEach((result) => {
|
|
8
11
|
const hasErrors = result.errors && result.errors.length > 0;
|
|
@@ -17,7 +20,7 @@ ${chalk.bold(relativeFile)}`);
|
|
|
17
20
|
if (error.line && error.column && absolutePath) {
|
|
18
21
|
const lineCol = `${error.line}:${error.column}`;
|
|
19
22
|
const clickable = createClickableLineCol(lineCol, absolutePath, error.line, error.column, editor);
|
|
20
|
-
const ruleId = error.ruleId ? chalk.dim(error.ruleId) : "";
|
|
23
|
+
const ruleId = error.ruleId ? chalk.dim(replaceNamespaceinRules(error.ruleId)) : "";
|
|
21
24
|
Logger.error(` ${clickable} ${error.message} ${ruleId}`);
|
|
22
25
|
} else {
|
|
23
26
|
Logger.error(` ${chalk.red("Error:")} ${error.message}`);
|
|
@@ -29,7 +32,7 @@ ${chalk.bold(relativeFile)}`);
|
|
|
29
32
|
if (warn.line && warn.column && absolutePath) {
|
|
30
33
|
const lineCol = `${warn.line}:${warn.column}`;
|
|
31
34
|
const clickable = createClickableLineCol(lineCol, absolutePath, warn.line, warn.column, editor);
|
|
32
|
-
const ruleId = warn.ruleId ? chalk.dim(warn.ruleId) : "";
|
|
35
|
+
const ruleId = warn.ruleId ? chalk.dim(replaceNamespaceinRules(warn.ruleId)) : "";
|
|
33
36
|
Logger.warning(` ${clickable} ${warn.message} ${ruleId}`);
|
|
34
37
|
} else {
|
|
35
38
|
Logger.warning(` ${chalk.yellow("Warning:")} ${warn.message}`);
|
|
@@ -39,5 +42,6 @@ ${chalk.bold(relativeFile)}`);
|
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
44
|
export {
|
|
42
|
-
printLintResults
|
|
45
|
+
printLintResults,
|
|
46
|
+
replaceNamespaceinRules
|
|
43
47
|
};
|
package/package.json
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce-ux/slds-linter",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "SLDS CLI tool for linting styles and components",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "SLDS Linter CLI tool for linting styles and components",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"parallel",
|
|
12
|
-
"performance"
|
|
6
|
+
"lightning design system linter",
|
|
7
|
+
"SLDS Linter",
|
|
8
|
+
"SLDS2 Linter",
|
|
9
|
+
"SLDS Stylelint",
|
|
10
|
+
"SLDS ESLint"
|
|
13
11
|
],
|
|
14
12
|
"author": "UXF Tooling Team",
|
|
15
13
|
"type": "module",
|
|
@@ -22,8 +20,8 @@
|
|
|
22
20
|
"slds-linter": "./build/index.js"
|
|
23
21
|
},
|
|
24
22
|
"dependencies": {
|
|
25
|
-
"@salesforce-ux/eslint-plugin-slds": "0.
|
|
26
|
-
"@salesforce-ux/stylelint-plugin-slds": "0.
|
|
23
|
+
"@salesforce-ux/eslint-plugin-slds": "0.1.1",
|
|
24
|
+
"@salesforce-ux/stylelint-plugin-slds": "0.1.1",
|
|
27
25
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
28
26
|
"@typescript-eslint/parser": "^5.0.0",
|
|
29
27
|
"chalk": "^4.1.2",
|
|
@@ -39,12 +37,12 @@
|
|
|
39
37
|
"license": "ISC",
|
|
40
38
|
"repository": {
|
|
41
39
|
"type": "git",
|
|
42
|
-
"url": "git+https://github.com/
|
|
40
|
+
"url": "git+https://github.com/salesforce-ux/slds-linter.git"
|
|
43
41
|
},
|
|
44
42
|
"bugs": {
|
|
45
|
-
"url": "https://github.com/
|
|
43
|
+
"url": "https://github.com/salesforce-ux/slds-linter/issues"
|
|
46
44
|
},
|
|
47
|
-
"homepage": "https://github.com/
|
|
45
|
+
"homepage": "https://github.com/salesforce-ux/slds-linter/tree/main/packages/cli#slds-linter",
|
|
48
46
|
"publishConfig": {
|
|
49
47
|
"registry": "https://registry.npmjs.org"
|
|
50
48
|
}
|