@salesforce-ux/slds-linter 1.0.2 → 1.0.3-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.
@@ -6,7 +6,41 @@ import {
6
6
  DEFAULT_ESLINT_CONFIG_PATH
7
7
  } from "../services/config.resolver.js";
8
8
  import path from "path";
9
- import { copyFile } from "fs/promises";
9
+ import { writeFile, readFile } from "fs/promises";
10
+ import sldsPlugin from "@salesforce-ux/eslint-plugin-slds";
11
+ function extractRulesFromConfig(configToExtract) {
12
+ configToExtract = Array.isArray(configToExtract) ? configToExtract : [configToExtract];
13
+ const allRules = {};
14
+ configToExtract.forEach((config) => {
15
+ if (config.rules) Object.assign(allRules, config.rules);
16
+ });
17
+ return Object.keys(allRules).length > 0 ? allRules : null;
18
+ }
19
+ async function loadRuleConfigs() {
20
+ try {
21
+ const plugin = sldsPlugin;
22
+ const configToExtract = plugin.configs?.["flat/recommended"] || plugin.configs?.["recommended"];
23
+ return extractRulesFromConfig(configToExtract);
24
+ } catch (error) {
25
+ return null;
26
+ }
27
+ }
28
+ function formatRulesForConfig(rules) {
29
+ return JSON.stringify(rules, null, 4).replace(/\n/g, "\n ");
30
+ }
31
+ async function generateEnhancedESLintConfig(sourceConfigPath) {
32
+ const config = await readFile(sourceConfigPath, "utf8");
33
+ const rules = await loadRuleConfigs();
34
+ if (rules) {
35
+ const formattedRules = formatRulesForConfig(rules);
36
+ return config.replace(
37
+ /extends:\s*\["@salesforce-ux\/slds\/recommended"\]/,
38
+ `extends: ["@salesforce-ux/slds/recommended"],
39
+ rules: ${formattedRules}`
40
+ );
41
+ }
42
+ return config;
43
+ }
10
44
  function registerEmitCommand(program) {
11
45
  program.command("emit").description("Emits the configuration files used by slds-linter cli").option(
12
46
  "-d, --directory <path>",
@@ -17,14 +51,13 @@ function registerEmitCommand(program) {
17
51
  const normalizedOptions = normalizeCliOptions(options, {
18
52
  configEslint: DEFAULT_ESLINT_CONFIG_PATH
19
53
  });
20
- const destESLintConfigPath = path.join(
21
- normalizedOptions.directory,
22
- path.basename(normalizedOptions.configEslint)
23
- );
24
- await copyFile(normalizedOptions.configEslint, destESLintConfigPath);
54
+ const enhancedConfig = await generateEnhancedESLintConfig(normalizedOptions.configEslint);
55
+ const destESLintConfigPath = path.join(normalizedOptions.directory, path.basename(normalizedOptions.configEslint));
56
+ await writeFile(destESLintConfigPath, enhancedConfig, "utf8");
25
57
  Logger.success(chalk.green(`ESLint configuration created at:
26
58
  ${destESLintConfigPath}
27
59
  `));
60
+ Logger.info(chalk.cyan("Rules are dynamically loaded based on extends configuration."));
28
61
  } catch (error) {
29
62
  Logger.error(
30
63
  chalk.red(`Failed to emit configuration: ${error.message}`)
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.2");
22
+ program.description("SLDS Linter CLI tool for linting styles and components").version("1.0.3-internal");
23
23
  }
24
24
  registerLintCommand(program);
25
25
  registerReportCommand(program);
@@ -157,7 +157,7 @@ var rule_messages_default = {
157
157
  // src/services/config.resolver.ts
158
158
  var DEFAULT_ESLINT_CONFIG_PATH = resolvePath("@salesforce-ux/eslint-plugin-slds/config", import.meta);
159
159
  var ESLINT_VERSION = "9.36.0";
160
- var LINTER_CLI_VERSION = "1.0.2";
160
+ var LINTER_CLI_VERSION = "1.0.3-internal";
161
161
  var getRuleDescription = (ruleId) => {
162
162
  const ruleIdWithoutNameSpace = `${ruleId}`.replace(/\@salesforce-ux\//, "").replace(/^slds\//, "");
163
163
  return rule_messages_default[ruleIdWithoutNameSpace]?.description || "--";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce-ux/slds-linter",
3
- "version": "1.0.2",
3
+ "version": "1.0.3-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.2",
32
+ "@salesforce-ux/eslint-plugin-slds": "1.0.3-internal",
33
33
  "@typescript-eslint/eslint-plugin": "^8.36.0",
34
34
  "@typescript-eslint/parser": "^8.36.0",
35
35
  "chalk": "^4.1.2",