@codacy/tools-stylelint-0 0.6.0 → 0.6.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/dist/index.js +95 -8
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -3461,6 +3461,75 @@ var descriptor = {
|
|
|
3461
3461
|
supportedRunners: ["local", "container"]
|
|
3462
3462
|
};
|
|
3463
3463
|
|
|
3464
|
+
// src/plugin-registry.ts
|
|
3465
|
+
var A11Y_RULE_NAMES = /* @__PURE__ */ new Set([
|
|
3466
|
+
"content-property-no-static-value",
|
|
3467
|
+
"font-size-is-readable",
|
|
3468
|
+
"line-height-is-vertical-rhythmed",
|
|
3469
|
+
"media-prefers-color-scheme",
|
|
3470
|
+
"media-prefers-reduced-motion",
|
|
3471
|
+
"no-display-none",
|
|
3472
|
+
"no-obsolete-attribute",
|
|
3473
|
+
"no-obsolete-element",
|
|
3474
|
+
"no-outline-none",
|
|
3475
|
+
"no-spread-text",
|
|
3476
|
+
"no-text-align-justify",
|
|
3477
|
+
"selector-pseudo-class-focus"
|
|
3478
|
+
]);
|
|
3479
|
+
var DEPRECATED_RULES = /* @__PURE__ */ new Set([
|
|
3480
|
+
"scss_at-import-no-partial-leading-underscore",
|
|
3481
|
+
"scss_at-import-partial-extension",
|
|
3482
|
+
"scss_at-import-partial-extension-blacklist",
|
|
3483
|
+
"scss_at-import-partial-extension-whitelist"
|
|
3484
|
+
]);
|
|
3485
|
+
function isDeprecatedRule(codacyRuleId) {
|
|
3486
|
+
return DEPRECATED_RULES.has(codacyRuleId);
|
|
3487
|
+
}
|
|
3488
|
+
var SCSS_PREFIX = "scss_";
|
|
3489
|
+
var SCSS_NAMESPACE = "scss/";
|
|
3490
|
+
var A11Y_NAMESPACE = "a11y/";
|
|
3491
|
+
var PLUGINS = [
|
|
3492
|
+
{
|
|
3493
|
+
packageName: "stylelint-scss",
|
|
3494
|
+
matchesCodacyRule: (id) => id.startsWith(SCSS_PREFIX),
|
|
3495
|
+
codacyToStylelint: (id) => SCSS_NAMESPACE + id.slice(SCSS_PREFIX.length),
|
|
3496
|
+
matchesStylelintRule: (id) => id.startsWith(SCSS_NAMESPACE),
|
|
3497
|
+
stylelintToCodacy: (id) => SCSS_PREFIX + id.slice(SCSS_NAMESPACE.length)
|
|
3498
|
+
},
|
|
3499
|
+
{
|
|
3500
|
+
packageName: "@double-great/stylelint-a11y",
|
|
3501
|
+
matchesCodacyRule: (id) => A11Y_RULE_NAMES.has(id),
|
|
3502
|
+
codacyToStylelint: (id) => A11Y_NAMESPACE + id,
|
|
3503
|
+
matchesStylelintRule: (id) => id.startsWith(A11Y_NAMESPACE),
|
|
3504
|
+
stylelintToCodacy: (id) => id.slice(A11Y_NAMESPACE.length)
|
|
3505
|
+
}
|
|
3506
|
+
];
|
|
3507
|
+
function findPluginForCodacyRule(codacyRuleId) {
|
|
3508
|
+
return PLUGINS.find((p) => p.matchesCodacyRule(codacyRuleId));
|
|
3509
|
+
}
|
|
3510
|
+
function findPluginForStylelintRule(stylelintRuleId) {
|
|
3511
|
+
return PLUGINS.find((p) => p.matchesStylelintRule(stylelintRuleId));
|
|
3512
|
+
}
|
|
3513
|
+
async function loadRequiredPlugins(codacyRuleIds) {
|
|
3514
|
+
const needed = /* @__PURE__ */ new Set();
|
|
3515
|
+
for (const id of codacyRuleIds) {
|
|
3516
|
+
const def = findPluginForCodacyRule(id);
|
|
3517
|
+
if (def) needed.add(def);
|
|
3518
|
+
}
|
|
3519
|
+
const perPackage = await Promise.all(
|
|
3520
|
+
Array.from(needed, async (def) => {
|
|
3521
|
+
try {
|
|
3522
|
+
const mod = await import(def.packageName);
|
|
3523
|
+
const exported = mod.default ?? mod;
|
|
3524
|
+
return Array.isArray(exported) ? exported : [exported];
|
|
3525
|
+
} catch {
|
|
3526
|
+
return [];
|
|
3527
|
+
}
|
|
3528
|
+
})
|
|
3529
|
+
);
|
|
3530
|
+
return perPackage.flat();
|
|
3531
|
+
}
|
|
3532
|
+
|
|
3464
3533
|
// src/adapter.ts
|
|
3465
3534
|
var TOOL_ID = "Stylelint";
|
|
3466
3535
|
var LOCAL_CONFIG_FILES = [
|
|
@@ -3488,19 +3557,35 @@ function ruleMetadata(ruleId) {
|
|
|
3488
3557
|
const patternId = `${TOOL_ID}_${ruleId}`;
|
|
3489
3558
|
return PATTERN_META.get(patternId) ?? { category: "CodeStyle", severity: "Info" };
|
|
3490
3559
|
}
|
|
3491
|
-
function buildStylelintConfig(patterns) {
|
|
3560
|
+
async function buildStylelintConfig(patterns, logger) {
|
|
3492
3561
|
const rules = {};
|
|
3493
3562
|
const prefix = `${TOOL_ID}_`;
|
|
3563
|
+
const codacyRuleIds = [];
|
|
3494
3564
|
for (const p of patterns) {
|
|
3495
|
-
const
|
|
3565
|
+
const codacyRuleId = p.patternId.startsWith(prefix) ? p.patternId.slice(prefix.length) : p.patternId;
|
|
3566
|
+
if (isDeprecatedRule(codacyRuleId)) {
|
|
3567
|
+
logger?.debug("Skipping deprecated stylelint rule", {
|
|
3568
|
+
toolId: TOOL_ID,
|
|
3569
|
+
patternId: p.patternId
|
|
3570
|
+
});
|
|
3571
|
+
continue;
|
|
3572
|
+
}
|
|
3573
|
+
codacyRuleIds.push(codacyRuleId);
|
|
3574
|
+
const plugin = findPluginForCodacyRule(codacyRuleId);
|
|
3575
|
+
const stylelintRuleId = plugin ? plugin.codacyToStylelint(codacyRuleId) : codacyRuleId;
|
|
3496
3576
|
if (p.parameters && Object.keys(p.parameters).length > 0) {
|
|
3497
3577
|
const paramValues = Object.values(p.parameters).map(parseParamValue);
|
|
3498
|
-
rules[
|
|
3578
|
+
rules[stylelintRuleId] = paramValues.length === 1 ? paramValues[0] : paramValues;
|
|
3499
3579
|
} else {
|
|
3500
|
-
rules[
|
|
3580
|
+
rules[stylelintRuleId] = true;
|
|
3501
3581
|
}
|
|
3502
3582
|
}
|
|
3503
|
-
|
|
3583
|
+
const plugins = await loadRequiredPlugins(codacyRuleIds);
|
|
3584
|
+
const config = { rules };
|
|
3585
|
+
if (plugins.length > 0) {
|
|
3586
|
+
config.plugins = plugins;
|
|
3587
|
+
}
|
|
3588
|
+
return config;
|
|
3504
3589
|
}
|
|
3505
3590
|
function parseParamValue(value) {
|
|
3506
3591
|
const trimmed = value.trim();
|
|
@@ -3619,7 +3704,7 @@ var adapter = {
|
|
|
3619
3704
|
if (codacyConfig.useLocalConfigurationFile && codacyConfig.localConfigurationFile) {
|
|
3620
3705
|
lintOptions.configFile = codacyConfig.localConfigurationFile;
|
|
3621
3706
|
} else if (codacyConfig.patterns.length > 0) {
|
|
3622
|
-
lintOptions.config = buildStylelintConfig(codacyConfig.patterns);
|
|
3707
|
+
lintOptions.config = await buildStylelintConfig(codacyConfig.patterns, ctx.logger);
|
|
3623
3708
|
} else {
|
|
3624
3709
|
ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
|
|
3625
3710
|
toolId: TOOL_ID
|
|
@@ -3643,11 +3728,13 @@ var adapter = {
|
|
|
3643
3728
|
});
|
|
3644
3729
|
continue;
|
|
3645
3730
|
}
|
|
3646
|
-
const
|
|
3731
|
+
const plugin = findPluginForStylelintRule(warning.rule);
|
|
3732
|
+
const codacyRuleId = plugin ? plugin.stylelintToCodacy(warning.rule) : warning.rule;
|
|
3733
|
+
const meta = ruleMetadata(codacyRuleId);
|
|
3647
3734
|
const message = warning.text.replace(` (${warning.rule})`, "");
|
|
3648
3735
|
issues.push({
|
|
3649
3736
|
filePath: relPath,
|
|
3650
|
-
patternId: `${TOOL_ID}_${
|
|
3737
|
+
patternId: `${TOOL_ID}_${codacyRuleId}`,
|
|
3651
3738
|
toolId: TOOL_ID,
|
|
3652
3739
|
line: warning.line,
|
|
3653
3740
|
column: warning.column,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codacy/tools-stylelint-0",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Stylelint adapter — Library-mode CSS/SCSS/Less linter",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"@double-great/stylelint-a11y": "^3.0.3",
|
|
11
12
|
"stylelint": "^16.0.0",
|
|
12
13
|
"stylelint-config-standard": "^36.0.0",
|
|
13
|
-
"
|
|
14
|
+
"stylelint-scss": "^6.12.1",
|
|
15
|
+
"@codacy/tooling": "0.6.1"
|
|
14
16
|
},
|
|
15
17
|
"license": "MIT",
|
|
16
18
|
"author": "Codacy <support@codacy.com> (https://www.codacy.com)",
|