@salesforce-ux/slds-linter 1.0.1 → 1.0.2-alpha.0

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.1");
22
+ program.description("SLDS Linter CLI tool for linting styles and components").version("1.0.2-alpha.0");
23
23
  }
24
24
  registerLintCommand(program);
25
25
  registerReportCommand(program);
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Config Loader Service
3
+ * Sets up NODE_PATH to make CLI's bundled dependencies available to user configs
4
+ * This allows users to import @salesforce-ux/eslint-plugin-slds without installing it
5
+ */
6
+ export declare class ConfigLoader {
7
+ private static nodePath;
8
+ /**
9
+ * Initialize module resolution to include CLI's bundled dependencies
10
+ * This allows user configs to import the plugin directly from CLI's node_modules
11
+ */
12
+ static setupBundledDependencies(): void;
13
+ /**
14
+ * Get the path to CLI's node_modules (for reference)
15
+ */
16
+ static getBundledModulesPath(): string | null;
17
+ }
@@ -0,0 +1,42 @@
1
+ // src/services/config-loader.ts
2
+ import { createRequire } from "module";
3
+ import { dirname } from "path";
4
+ import { Logger } from "../utils/logger.js";
5
+ var ConfigLoader = class {
6
+ static nodePath = null;
7
+ /**
8
+ * Initialize module resolution to include CLI's bundled dependencies
9
+ * This allows user configs to import the plugin directly from CLI's node_modules
10
+ */
11
+ static setupBundledDependencies() {
12
+ if (this.nodePath) {
13
+ return;
14
+ }
15
+ try {
16
+ const require2 = createRequire(import.meta.url);
17
+ const pluginMainPath = require2.resolve("@salesforce-ux/eslint-plugin-slds");
18
+ const pluginDir = dirname(pluginMainPath);
19
+ const pluginRoot = dirname(pluginDir);
20
+ const scopeDir = dirname(pluginRoot);
21
+ const cliNodeModules = dirname(scopeDir);
22
+ const existingPath = process.env.NODE_PATH || "";
23
+ process.env.NODE_PATH = existingPath ? `${existingPath}:${cliNodeModules}` : cliNodeModules;
24
+ require2("module").Module._initPaths();
25
+ this.nodePath = cliNodeModules;
26
+ Logger.debug(`Using bundled dependencies from: ${cliNodeModules}`);
27
+ Logger.debug("User configs can now import @salesforce-ux/eslint-plugin-slds");
28
+ } catch (error) {
29
+ Logger.error(`Failed to setup bundled dependencies: ${error.message}`);
30
+ throw new Error(`Could not initialize bundled dependencies: ${error.message}`);
31
+ }
32
+ }
33
+ /**
34
+ * Get the path to CLI's node_modules (for reference)
35
+ */
36
+ static getBundledModulesPath() {
37
+ return this.nodePath;
38
+ }
39
+ };
40
+ export {
41
+ ConfigLoader
42
+ };
@@ -137,7 +137,7 @@ var rule_messages_default = {
137
137
  },
138
138
  "no-hardcoded-values-slds2": {
139
139
  "description": "Replace static values with SLDS 2 styling hooks. For more information, look up design tokens on lightningdesignsystem.com.",
140
- "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-hardcoded-value",
140
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-hardcoded-values-slds2",
141
141
  "type": "suggestion",
142
142
  "messages": {
143
143
  "hardcodedValue": "Consider replacing the {{oldValue}} static value with an SLDS 2 styling hook that has a similar value: {{newValue}}.",
@@ -156,8 +156,8 @@ var rule_messages_default = {
156
156
 
157
157
  // src/services/config.resolver.ts
158
158
  var DEFAULT_ESLINT_CONFIG_PATH = resolvePath("@salesforce-ux/eslint-plugin-slds/config", import.meta);
159
- var ESLINT_VERSION = "9.35.0";
160
- var LINTER_CLI_VERSION = "1.0.1";
159
+ var ESLINT_VERSION = "9.36.0";
160
+ var LINTER_CLI_VERSION = "1.0.2-alpha.0";
161
161
  var getRuleDescription = (ruleId) => {
162
162
  const ruleIdWithoutNameSpace = `${ruleId}`.replace(/\@salesforce-ux\//, "").replace(/^slds\//, "");
163
163
  return rule_messages_default[ruleIdWithoutNameSpace]?.description || "--";
@@ -3,6 +3,7 @@ import path from "path";
3
3
  import { BatchProcessor } from "./batch-processor.js";
4
4
  import { Logger } from "../utils/logger.js";
5
5
  import { resolveDirName } from "../utils/nodeVersionUtil.js";
6
+ import { ConfigLoader } from "./config-loader.js";
6
7
  var LintRunner = class {
7
8
  /**
8
9
  * Run linting on batches of files
@@ -14,6 +15,7 @@ var LintRunner = class {
14
15
  "../workers",
15
16
  "eslint.worker.js"
16
17
  );
18
+ ConfigLoader.setupBundledDependencies();
17
19
  const workerConfig = {
18
20
  configPath: options.configPath,
19
21
  fix: options.fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce-ux/slds-linter",
3
- "version": "1.0.1",
3
+ "version": "1.0.2-alpha.0",
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.1",
32
+ "@salesforce-ux/eslint-plugin-slds": "1.0.2-alpha.0",
33
33
  "@typescript-eslint/eslint-plugin": "^8.36.0",
34
34
  "@typescript-eslint/parser": "^8.36.0",
35
35
  "chalk": "^4.1.2",