@salesforce-ux/slds-linter 0.0.12-alpha.0 → 0.0.12-alpha.6

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 ADDED
@@ -0,0 +1,85 @@
1
+ # SLDS Linter
2
+
3
+ ## Overview
4
+
5
+ SLDS Linter provides custom linting rules specifically built for Salesforce Lightning Design System 2 (SLDS 2 beta). SLDS Linter is designed to uplift your Cascading Style Sheet (CSS), Lightning Web Component (LWC), and Aura component files to SLDS 2 and to conform to SLDS best practices. SLDS Linter rules allow you to maintain consistent styling and identify common issues when working with Lightning components.
6
+
7
+ ## Features
8
+
9
+ - Component Linting:
10
+ The utility supports linting for two types of Salesforce Lightning components:
11
+
12
+ - LWC and Aura components.
13
+ LWC Components (.html): Linting is applied to Lightning Web Components.
14
+ - Aura Components (.cmp): Linting is applied to Aura Components.
15
+
16
+ * Stylelint for CSS Files:
17
+ Stylelint rules are applied to .css files associated with the components. This ensures consistent styling practices are followed throughout the project.
18
+
19
+ Follow the below instructions to integrate SLDS Linter into your project.
20
+
21
+ ---
22
+
23
+ ## Set Up SLDS Linter in Your Component Repository
24
+
25
+ ### Pre-requisites
26
+
27
+ SLDS Linter CLI tool works best with the [Active LTS](https://nodejs.org/en/about/previous-releases) version of Node.js.
28
+
29
+ #### **Minimum Required Node.js Version**
30
+ - The minimum supported Node.js version is **v20.18.3**.
31
+ - We recommend using the latest **Active LTS** release for the best performance and compatibility.
32
+
33
+
34
+ ### Command-Line Interface (CLI)
35
+
36
+ To see what all options does slds-linter provide please run `npx @salesforce-ux/slds-linter@latest --help` which gives the below output.
37
+ For the first time, it will ask to install the package. Please reply with `y` as yes to install the package.
38
+
39
+ ```
40
+ Usage: npx @salesforce-ux/slds-linter@latest [options] [command]
41
+
42
+ A CLI tool for linting styles and components
43
+
44
+ Options:
45
+ -V, --version output the version number
46
+ -h, --help display help for command
47
+
48
+ 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
+ help [command] display help for command
54
+ ```
55
+
56
+ - `npx @salesforce-ux/slds-linter lint` - Runs the ESlint and Stylelint rules on your HTML/CSS/CMP files and outputs issues.
57
+ - `npx @salesforce-ux/slds-linter lint:styles` - Runs the Stylelint rules on your CSS files and outputs issues.
58
+ - `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.
60
+ - `npx @salesforce-ux/slds-linter report`: Generates a SARIF report for static analysis.
61
+
62
+ #### Options available with each command
63
+
64
+ | **Options** | **Description** | **Availability** |
65
+ | ------------------------ | ---------------------------------------------------------------------------- | ------------------------------------------ |
66
+ | `-d, --directory <path>` | Target directory to scan (defaults to current directory) | lint, lint:styles, lint:components, report |
67
+ | `-o, --output <path>` | Output directory for reports (defaults to current directory) | report |
68
+ | `--fix` | Automatically fix problems | lint, lint:styles, lint:components |
69
+ | `--config <path>` | Path to eslint/stylelint config file', DEFAULT_ESLINT_CONFIG_PATH | lint:styles, lint:components |
70
+ | `--config-style <path>` | PPath to stylelint config file', DEFAULT_STYLELINT_CONFIG_PATH | lint |
71
+ | `--config-eslint <path>` | Path to eslint config file', DEFAULT_ESLINT_CONFIG_PATH | lint |
72
+ | `--editor <editor>` | Editor to open files with (e.g., vscode, atom, sublime). Defaults to vscode | lint,lint:styles, lint:components |
73
+
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`.
76
+
77
+ #### Detailed Steps
78
+
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. 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`.
81
+ 3. Open the generated Sarif file.
82
+ 4. Make a note of how many components SLDS Linter has identified that you must update.
83
+ 5. Run `npx @salesforce-ux/slds-linter fix` to automatically fix validation errors in bulk.
84
+
85
+ For any questions or issues, feel free to reach out to the maintainers or open an issue in the repository.
@@ -8,11 +8,13 @@ import { ComponentFilePatterns } from "../services/file-patterns.js";
8
8
  import { LintRunner } from "../services/lint-runner.js";
9
9
  import { DEFAULT_ESLINT_CONFIG_PATH } from "../services/config.resolver.js";
10
10
  function registerLintComponentsCommand(program) {
11
- program.command("lint:components").description("Run eslint on all markup files").option("-d, --directory <path>", "Target directory to scan (defaults to current directory)").option("--fix", "Automatically fix problems").option("--config <path>", "Path to eslint config file", DEFAULT_ESLINT_CONFIG_PATH).option("--editor <editor>", "Editor to open files with (vscode, atom, sublime). Defaults to vscode", "vscode").action(async (options) => {
11
+ program.command("lint:components").description("Run eslint on all markup files").option("-d, --directory <path>", "Target directory to scan (defaults to current directory)").option("--fix", "Automatically fix problems").option("--config <path>", "Path to eslint config file").option("--editor <editor>", "Editor to open files with (vscode, atom, sublime). Defaults to vscode", "vscode").action(async (options) => {
12
12
  const startTime = Date.now();
13
13
  try {
14
14
  Logger.info(chalk.blue("Starting linting of component files..."));
15
- const normalizedOptions = normalizeCliOptions(options);
15
+ const normalizedOptions = normalizeCliOptions(options, {
16
+ config: DEFAULT_ESLINT_CONFIG_PATH
17
+ });
16
18
  Logger.info(chalk.blue("Scanning for files..."));
17
19
  const fileBatches = await FileScanner.scanFiles(normalizedOptions.directory, {
18
20
  patterns: ComponentFilePatterns,
@@ -8,11 +8,13 @@ import { StyleFilePatterns } from "../services/file-patterns.js";
8
8
  import { LintRunner } from "../services/lint-runner.js";
9
9
  import { DEFAULT_STYLELINT_CONFIG_PATH } from "../services/config.resolver.js";
10
10
  function registerLintStylesCommand(program) {
11
- program.command("lint:styles").description("Run stylelint on all style files").option("-d, --directory <path>", "Target directory to scan (defaults to current directory)").option("--fix", "Automatically fix problems").option("--config <path>", "Path to stylelint config file", DEFAULT_STYLELINT_CONFIG_PATH).option("--editor <editor>", "Editor to open files with (vscode, atom, sublime). Defaults to vscode", "vscode").action(async (options) => {
11
+ program.command("lint:styles").description("Run stylelint on all style files").option("-d, --directory <path>", "Target directory to scan (defaults to current directory)").option("--fix", "Automatically fix problems").option("--config <path>", "Path to stylelint config file").option("--editor <editor>", "Editor to open files with (vscode, atom, sublime). Defaults to vscode", "vscode").action(async (options) => {
12
12
  const startTime = Date.now();
13
13
  try {
14
14
  Logger.info(chalk.blue("Starting linting of style files..."));
15
- const normalizedOptions = normalizeCliOptions(options);
15
+ const normalizedOptions = normalizeCliOptions(options, {
16
+ configStyle: DEFAULT_STYLELINT_CONFIG_PATH
17
+ });
16
18
  Logger.info(chalk.blue("Scanning for style files..."));
17
19
  const fileBatches = await FileScanner.scanFiles(normalizedOptions.directory, {
18
20
  patterns: StyleFilePatterns,
@@ -10,11 +10,14 @@ import { StyleFilePatterns, ComponentFilePatterns } from "../services/file-patte
10
10
  import { LintRunner } from "../services/lint-runner.js";
11
11
  import { DEFAULT_ESLINT_CONFIG_PATH, DEFAULT_STYLELINT_CONFIG_PATH } from "../services/config.resolver.js";
12
12
  function registerLintCommand(program) {
13
- 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", DEFAULT_STYLELINT_CONFIG_PATH).option("--config-eslint <path>", "Path to eslint config file", DEFAULT_ESLINT_CONFIG_PATH).option("--editor <editor>", "Editor to open files with (e.g., vscode, atom, sublime). Defaults to vscode", "vscode").action(async (options) => {
13
+ 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
14
  const startTime = Date.now();
15
15
  try {
16
16
  Logger.info(chalk.blue("Starting full linting process..."));
17
- const normalizedOptions = normalizeCliOptions(options);
17
+ const normalizedOptions = normalizeCliOptions(options, {
18
+ configStyle: DEFAULT_STYLELINT_CONFIG_PATH,
19
+ configEslint: DEFAULT_ESLINT_CONFIG_PATH
20
+ });
18
21
  Logger.info(chalk.blue("\nScanning style files..."));
19
22
  const styleFileBatches = await FileScanner.scanFiles(normalizedOptions.directory, {
20
23
  patterns: StyleFilePatterns,
@@ -9,10 +9,13 @@ import { LintRunner } from "../services/lint-runner.js";
9
9
  import { ReportGenerator } from "../services/report-generator.js";
10
10
  import { DEFAULT_ESLINT_CONFIG_PATH, DEFAULT_STYLELINT_CONFIG_PATH, LINTER_CLI_VERSION } from "../services/config.resolver.js";
11
11
  function registerReportCommand(program) {
12
- program.command("report").description("Generate SARIF report from linting results").option("-d, --directory <path>", "Target directory to scan (defaults to current directory)").option("-o, --output <path>", "Output directory for reports (defaults to current directory)").option("--config-style <path>", "Path to stylelint config file", DEFAULT_STYLELINT_CONFIG_PATH).option("--config-eslint <path>", "Path to eslint config file", DEFAULT_ESLINT_CONFIG_PATH).action(async (options) => {
12
+ program.command("report").description("Generate SARIF report from linting results").option("-d, --directory <path>", "Target directory to scan (defaults to current directory)").option("-o, --output <path>", "Output directory for reports (defaults to current directory)").option("--config-style <path>", "Path to stylelint config file").option("--config-eslint <path>", "Path to eslint config file").action(async (options) => {
13
13
  const spinner = ora("Starting report generation...").start();
14
14
  try {
15
- const normalizedOptions = normalizeCliOptions(options);
15
+ const normalizedOptions = normalizeCliOptions(options, {
16
+ configStyle: DEFAULT_STYLELINT_CONFIG_PATH,
17
+ configEslint: DEFAULT_ESLINT_CONFIG_PATH
18
+ });
16
19
  spinner.text = "Running styles linting...";
17
20
  const styleFileBatches = await FileScanner.scanFiles(normalizedOptions.directory, {
18
21
  patterns: StyleFilePatterns,
package/build/index.js CHANGED
@@ -7,6 +7,7 @@ import { registerLintComponentsCommand } from "./commands/lint-components.js";
7
7
  import { registerLintCommand } from "./commands/lint.js";
8
8
  import { registerReportCommand } from "./commands/report.js";
9
9
  import { Logger } from "./utils/logger.js";
10
+ import pkg from "../package.json" with { type: "json" };
10
11
  process.on("unhandledRejection", (error) => {
11
12
  Logger.error(`Unhandled rejection: ${error}`);
12
13
  process.exit(1);
@@ -16,7 +17,7 @@ process.on("uncaughtException", (error) => {
16
17
  process.exit(1);
17
18
  });
18
19
  var program = new Command();
19
- program.name("linting-cli").description("A CLI tool for linting styles and components").version("1.0.0");
20
+ program.name("npx @salesforce-ux/slds-linter@latest").description(pkg.description).version(pkg.version).showHelpAfterError();
20
21
  registerLintStylesCommand(program);
21
22
  registerLintComponentsCommand(program);
22
23
  registerLintCommand(program);
@@ -3,8 +3,11 @@ import path from "path";
3
3
  import { FileScanner } from "../file-scanner.js";
4
4
  import { StyleFilePatterns } from "../file-patterns.js";
5
5
  import { mkdir, writeFile, rm } from "fs/promises";
6
+ import { fileURLToPath } from "url";
7
+ var __filename = fileURLToPath(import.meta.url);
8
+ var __dirname = path.dirname(__filename);
6
9
  describe("FileScanner", () => {
7
- const testDir = path.join(import.meta.dirname, "fixtures");
10
+ const testDir = path.join(__dirname, "fixtures");
8
11
  beforeAll(async () => {
9
12
  await mkdir(testDir, { recursive: true });
10
13
  await writeFile(
@@ -95,7 +95,7 @@ var ReportGenerator = class {
95
95
  startLine: error.line,
96
96
  startColumn: error.column,
97
97
  endLine: error.line,
98
- endColumn: error.column + 1
98
+ endColumn: error.endColumn
99
99
  });
100
100
  runBuilder.addResult(resultBuilder);
101
101
  }
@@ -108,7 +108,7 @@ var ReportGenerator = class {
108
108
  startLine: warning.line,
109
109
  startColumn: warning.column,
110
110
  endLine: warning.line,
111
- endColumn: warning.column + 1
111
+ endColumn: warning.endColumn
112
112
  });
113
113
  runBuilder.addResult(resultBuilder);
114
114
  }
@@ -12,6 +12,7 @@ export interface LintResult {
12
12
  errors: Array<{
13
13
  line: number;
14
14
  column: number;
15
+ endColumn: number;
15
16
  message: string;
16
17
  ruleId: string;
17
18
  severity: number;
@@ -19,6 +20,7 @@ export interface LintResult {
19
20
  warnings: Array<{
20
21
  line: number;
21
22
  column: number;
23
+ endColumn: number;
22
24
  message: string;
23
25
  ruleId: string;
24
26
  severity: number;
@@ -35,12 +37,14 @@ export interface WorkerResult {
35
37
  warnings?: Array<{
36
38
  line: number;
37
39
  column: number;
40
+ endColumn: number;
38
41
  message: string;
39
42
  ruleId: string;
40
43
  }>;
41
44
  errors?: Array<{
42
45
  line: number;
43
46
  column: number;
47
+ endColumn: number;
44
48
  message: string;
45
49
  ruleId: string;
46
50
  }>;
@@ -1,3 +1,3 @@
1
1
  import { CliOptions } from '../types';
2
2
  export declare function validateAndNormalizePath(inputPath?: string): string;
3
- export declare function normalizeCliOptions(options: CliOptions): Required<CliOptions>;
3
+ export declare function normalizeCliOptions(options: CliOptions, defultOptions?: Partial<CliOptions>): Required<CliOptions>;
@@ -13,15 +13,16 @@ function validateAndNormalizePath(inputPath) {
13
13
  throw new Error(`Invalid path: ${inputPath}`);
14
14
  }
15
15
  }
16
- function normalizeCliOptions(options) {
16
+ function normalizeCliOptions(options, defultOptions = {}) {
17
17
  return {
18
+ fix: false,
19
+ editor: "vscode",
20
+ config: "",
21
+ configStyle: "",
22
+ configEslint: "",
23
+ ...defultOptions,
18
24
  directory: validateAndNormalizePath(options.directory),
19
- output: validateAndNormalizePath(options.output),
20
- fix: options.fix || false,
21
- config: options.config || "",
22
- configStyle: options.configStyle || "",
23
- configEslint: options.configEslint || "",
24
- editor: options.editor || "vscode"
25
+ output: validateAndNormalizePath(options.output)
25
26
  };
26
27
  }
27
28
  export {
@@ -23,12 +23,14 @@ var ESLintWorker = class extends BaseWorker {
23
23
  warnings: fileResult.messages.filter((msg) => msg.severity === 1).map((warning) => ({
24
24
  line: warning.line,
25
25
  column: warning.column,
26
+ endColumn: warning.endColumn,
26
27
  message: warning.message,
27
28
  ruleId: warning.ruleId || "unknown"
28
29
  })),
29
30
  errors: fileResult.messages.filter((msg) => msg.severity === 2).map((error) => ({
30
31
  line: error.line,
31
32
  column: error.column,
33
+ endColumn: error.endColumn,
32
34
  message: error.message,
33
35
  ruleId: error.ruleId || "unknown"
34
36
  }))
@@ -18,6 +18,7 @@ var StylelintWorker = class extends BaseWorker {
18
18
  warnings: fileResult.warnings.map((warning) => ({
19
19
  line: warning.line,
20
20
  column: warning.column,
21
+ endColumn: warning.endColumn,
21
22
  message: warning.text,
22
23
  ruleId: warning.rule
23
24
  })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce-ux/slds-linter",
3
- "version": "0.0.12-alpha.0",
3
+ "version": "0.0.12-alpha.6",
4
4
  "description": "SLDS CLI tool for linting styles and components",
5
5
  "keywords": [
6
6
  "lint",
@@ -22,8 +22,8 @@
22
22
  "slds-linter": "./build/index.js"
23
23
  },
24
24
  "dependencies": {
25
- "@salesforce-ux/eslint-plugin-slds": "0.0.12-alpha.0",
26
- "@salesforce-ux/stylelint-plugin-slds": "0.0.12-alpha.0",
25
+ "@salesforce-ux/eslint-plugin-slds": "0.0.12-alpha.6",
26
+ "@salesforce-ux/stylelint-plugin-slds": "0.0.12-alpha.6",
27
27
  "@typescript-eslint/eslint-plugin": "^5.0.0",
28
28
  "@typescript-eslint/parser": "^5.0.0",
29
29
  "chalk": "^4.1.2",
@@ -43,5 +43,8 @@
43
43
  "bugs": {
44
44
  "url": "https://github.com/yourusername/linting-cli/issues"
45
45
  },
46
- "homepage": "https://github.com/yourusername/linting-cli#readme"
46
+ "homepage": "https://github.com/yourusername/linting-cli#readme",
47
+ "publishConfig": {
48
+ "registry": "https://registry.npmjs.org"
49
+ }
47
50
  }