@salesforce-ux/slds-linter 1.0.2 → 1.0.4-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.4-internal");
23
23
  }
24
24
  registerLintCommand(program);
25
25
  registerReportCommand(program);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Config Loader - Simple import rewriter for custom configs
3
+ * Only rewrites imports if dependencies aren't already installed
4
+ */
5
+ export declare class ConfigLoader {
6
+ /**
7
+ * Check if package is installed in user's workspace
8
+ */
9
+ private static isPackageInstalled;
10
+ /**
11
+ * Process custom .mjs config - only rewrite if dependencies not installed
12
+ */
13
+ static processConfig(configPath: string | undefined): Promise<string | undefined>;
14
+ }
@@ -0,0 +1,59 @@
1
+ // src/services/config-loader.ts
2
+ import { readFile, writeFile } from "fs/promises";
3
+ import { createRequire } from "module";
4
+ import { join } from "path";
5
+ import { tmpdir } from "os";
6
+ import { Logger } from "../utils/logger.js";
7
+ var ConfigLoader = class {
8
+ /**
9
+ * Check if package is installed in user's workspace
10
+ */
11
+ static isPackageInstalled(packageName, fromPath) {
12
+ try {
13
+ const require2 = createRequire(fromPath);
14
+ require2.resolve(packageName);
15
+ return true;
16
+ } catch {
17
+ return false;
18
+ }
19
+ }
20
+ /**
21
+ * Process custom .mjs config - only rewrite if dependencies not installed
22
+ */
23
+ static async processConfig(configPath) {
24
+ if (!configPath?.endsWith(".mjs")) {
25
+ return configPath;
26
+ }
27
+ try {
28
+ const userConfigUrl = `file://${configPath}`;
29
+ const pluginInstalled = this.isPackageInstalled("@salesforce-ux/eslint-plugin-slds", userConfigUrl);
30
+ const eslintInstalled = this.isPackageInstalled("eslint", userConfigUrl);
31
+ if (pluginInstalled && eslintInstalled) {
32
+ Logger.debug("Dependencies already installed, using config as-is");
33
+ return configPath;
34
+ }
35
+ Logger.debug("Dependencies not installed, rewriting imports");
36
+ const configContent = await readFile(configPath, "utf-8");
37
+ const require2 = createRequire(import.meta.url);
38
+ const pluginPath = require2.resolve("@salesforce-ux/eslint-plugin-slds");
39
+ const eslintConfigPath = require2.resolve("eslint/config");
40
+ const rewritten = configContent.replace(
41
+ /import\s+(\w+)\s+from\s+['"]@salesforce-ux\/eslint-plugin-slds['"]/g,
42
+ `import $1 from '${pluginPath}'`
43
+ ).replace(
44
+ /import\s+({[^}]+})\s+from\s+['"]eslint\/config['"]/g,
45
+ `import $1 from '${eslintConfigPath}'`
46
+ );
47
+ const tempPath = join(tmpdir(), `slds-config-${Date.now()}.mjs`);
48
+ await writeFile(tempPath, rewritten, "utf-8");
49
+ Logger.debug(`Rewritten config: ${tempPath}`);
50
+ return tempPath;
51
+ } catch (error) {
52
+ Logger.error(`Config processing failed: ${error.message}`);
53
+ throw error;
54
+ }
55
+ }
56
+ };
57
+ export {
58
+ ConfigLoader
59
+ };
@@ -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.36.0";
160
- var LINTER_CLI_VERSION = "1.0.2";
159
+ var ESLINT_VERSION = "9.37.0";
160
+ var LINTER_CLI_VERSION = "1.0.4-internal";
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,8 +15,9 @@ var LintRunner = class {
14
15
  "../workers",
15
16
  "eslint.worker.js"
16
17
  );
18
+ const configPath = await ConfigLoader.processConfig(options.configPath);
17
19
  const workerConfig = {
18
- configPath: options.configPath,
20
+ configPath,
19
21
  fix: options.fix
20
22
  };
21
23
  const results = await BatchProcessor.processBatches(
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.4-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.4-internal",
33
33
  "@typescript-eslint/eslint-plugin": "^8.36.0",
34
34
  "@typescript-eslint/parser": "^8.36.0",
35
35
  "chalk": "^4.1.2",