@salesforce-ux/slds-linter 0.1.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 CHANGED
@@ -66,7 +66,7 @@ Commands:
66
66
  - `npx @salesforce-ux/slds-linter lint` - Runs the ESlint and Stylelint rules on your HTML/CSS/CMP files and outputs issues.
67
67
  - `npx @salesforce-ux/slds-linter lint:styles` - Runs the Stylelint rules on your CSS files and outputs issues.
68
68
  - `npx @salesforce-ux/slds-linter lint:components` - Runs the ESlint rules on your HTML/CMP files and outputs issues.
69
- - `npx @salesforce-ux/slds-linter fix`: Attempts to automatically fix violations.
69
+ - `npx @salesforce-ux/slds-linter lint --fix`: Attempts to automatically fix violations.
70
70
  - `npx @salesforce-ux/slds-linter report`: Generates a SARIF report for static analysis.
71
71
  - `npx @salesforce-ux/slds-linter emit`: Emits the configuration files used by slds-linter cli (defaults to current directory).
72
72
 
@@ -82,7 +82,7 @@ Commands:
82
82
  | `--config-eslint <path>` | Path to eslint config file' | lint |
83
83
  | `--editor <editor>` | Editor to open files with (e.g., vscode, atom, sublime). Defaults to vscode | lint,lint:styles, lint:components |
84
84
 
85
- 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`.
86
86
 
87
87
  #### Detailed Steps
88
88
 
@@ -91,7 +91,7 @@ These options can also be visualised by using `--help` with each command. For ex
91
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
92
  4. Open the generated Sarif file.
93
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 fix` to automatically fix validation errors in bulk.
94
+ 6. Run `npx @salesforce-ux/slds-linter lint --fix` to automatically fix validation errors in bulk.
95
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
96
 
97
97
  #### Troubleshooting SARIF Viewer Navigation
@@ -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 { execSync } from "child_process";
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
- execSync(`cp ${normalizedOptions.configStyle} ${destStyleConfigPath}`);
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
- execSync(
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
  `));
package/build/index.js CHANGED
@@ -9,7 +9,7 @@ var require_package = __commonJS({
9
9
  "package.json"(exports, module) {
10
10
  module.exports = {
11
11
  name: "@salesforce-ux/slds-linter",
12
- version: "0.0.13-alpha.1",
12
+ version: "0.1.0",
13
13
  description: "SLDS Linter CLI tool for linting styles and components",
14
14
  keywords: [
15
15
  "lightning design system linter",
@@ -36,8 +36,8 @@ var require_package = __commonJS({
36
36
  lint: "eslint src/**/*.ts"
37
37
  },
38
38
  dependencies: {
39
- "@salesforce-ux/eslint-plugin-slds": "0.0.13-alpha.1",
40
- "@salesforce-ux/stylelint-plugin-slds": "0.0.13-alpha.1",
39
+ "@salesforce-ux/eslint-plugin-slds": "0.1.0",
40
+ "@salesforce-ux/stylelint-plugin-slds": "0.1.0",
41
41
  "@typescript-eslint/eslint-plugin": "^5.0.0",
42
42
  "@typescript-eslint/parser": "^5.0.0",
43
43
  chalk: "^4.1.2",
@@ -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,7 +22,7 @@ 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
+ ruleId: replaceNamespaceinRules(rule.id),
25
26
  shortDescriptionText: rule.shortDescription?.text
26
27
  });
27
28
  runBuilder.addRule(ruleBuilder);
@@ -53,9 +54,9 @@ var ReportGenerator = class {
53
54
  for (const error of result.errors) {
54
55
  if (!rules.has(error.ruleId)) {
55
56
  rules.set(error.ruleId, {
56
- id: error.ruleId,
57
+ id: replaceNamespaceinRules(error.ruleId),
57
58
  shortDescription: {
58
- text: getRuleDescription(error.ruleId)
59
+ text: getRuleDescription(replaceNamespaceinRules(error.ruleId))
59
60
  },
60
61
  properties: {
61
62
  category: "Style"
@@ -66,9 +67,9 @@ var ReportGenerator = class {
66
67
  for (const warning of result.warnings) {
67
68
  if (!rules.has(warning.ruleId)) {
68
69
  rules.set(warning.ruleId, {
69
- id: warning.ruleId,
70
+ id: replaceNamespaceinRules(warning.ruleId),
70
71
  shortDescription: {
71
- text: getRuleDescription(warning.ruleId)
72
+ text: getRuleDescription(replaceNamespaceinRules(warning.ruleId))
72
73
  },
73
74
  properties: {
74
75
  category: "Style"
@@ -85,7 +86,7 @@ var ReportGenerator = class {
85
86
  static addResultsToSarif(runBuilder, lintResult) {
86
87
  for (const error of lintResult.errors) {
87
88
  const resultBuilder = new SarifResultBuilder().initSimple({
88
- ruleId: error.ruleId,
89
+ ruleId: replaceNamespaceinRules(error.ruleId),
89
90
  level: "error",
90
91
  messageText: error.message,
91
92
  fileUri: lintResult.filePath,
@@ -98,7 +99,7 @@ var ReportGenerator = class {
98
99
  }
99
100
  for (const warning of lintResult.warnings) {
100
101
  const resultBuilder = new SarifResultBuilder().initSimple({
101
- ruleId: warning.ruleId,
102
+ ruleId: replaceNamespaceinRules(warning.ruleId),
102
103
  level: "warning",
103
104
  messageText: warning.message,
104
105
  fileUri: lintResult.filePath,
@@ -1,4 +1,10 @@
1
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;
2
8
  /**
3
9
  * Prints detailed lint results for each file that has issues.
4
10
  *
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce-ux/slds-linter",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "SLDS Linter CLI tool for linting styles and components",
5
5
  "keywords": [
6
6
  "lightning design system linter",
@@ -20,8 +20,8 @@
20
20
  "slds-linter": "./build/index.js"
21
21
  },
22
22
  "dependencies": {
23
- "@salesforce-ux/eslint-plugin-slds": "0.1.0",
24
- "@salesforce-ux/stylelint-plugin-slds": "0.1.0",
23
+ "@salesforce-ux/eslint-plugin-slds": "0.1.1",
24
+ "@salesforce-ux/stylelint-plugin-slds": "0.1.1",
25
25
  "@typescript-eslint/eslint-plugin": "^5.0.0",
26
26
  "@typescript-eslint/parser": "^5.0.0",
27
27
  "chalk": "^4.1.2",