@codacy/tools-stylelint-0 0.23.1 → 0.25.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.
- package/README.md +15 -13
- package/dist/index.js +58 -35
- package/dist/metadata.js +1 -0
- package/package.json +7 -4
- package/payload/package-lock.json +1496 -0
- package/payload/package.json +11 -0
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @codacy/tools-stylelint-0
|
|
2
2
|
|
|
3
3
|
## Table of Contents
|
|
4
|
+
|
|
4
5
|
- [Overview](#overview)
|
|
5
6
|
- [Updating patterns](#updating-patterns)
|
|
6
7
|
- [Updating the Stylelint version](#updating-the-stylelint-version)
|
|
@@ -13,14 +14,14 @@
|
|
|
13
14
|
|
|
14
15
|
CSS/SCSS/Less linter using [Stylelint](https://stylelint.io). Uses the Library execution strategy — calls the Stylelint API directly rather than spawning a subprocess.
|
|
15
16
|
|
|
16
|
-
| Property
|
|
17
|
-
|
|
18
|
-
| Tool ID
|
|
19
|
-
| Codacy UUID
|
|
20
|
-
| Strategy
|
|
21
|
-
| Languages
|
|
22
|
-
| Dependency
|
|
23
|
-
| File patterns | `**/*.css`, `**/*.scss`, `**/*.less`
|
|
17
|
+
| Property | Value |
|
|
18
|
+
| ------------- | -------------------------------------- |
|
|
19
|
+
| Tool ID | `Stylelint` |
|
|
20
|
+
| Codacy UUID | `1f03328a-086e-459e-bfa3-73e56f01020f` |
|
|
21
|
+
| Strategy | Library |
|
|
22
|
+
| Languages | CSS, LESS, SASS |
|
|
23
|
+
| Dependency | `stylelint` npm package (v16.x) |
|
|
24
|
+
| File patterns | `**/*.css`, `**/*.scss`, `**/*.less` |
|
|
24
25
|
|
|
25
26
|
## Updating patterns
|
|
26
27
|
|
|
@@ -36,11 +37,12 @@ Pattern IDs follow the format `Stylelint_block-no-empty`, `Stylelint_color-no-in
|
|
|
36
37
|
|
|
37
38
|
## Updating the Stylelint version
|
|
38
39
|
|
|
39
|
-
1. Update the `stylelint` version in `package.json`
|
|
40
|
+
1. Update the `stylelint` version in `devDependencies` of `package.json`, and `preferredVersion` in `src/metadata.ts`
|
|
40
41
|
2. Run `pnpm install`
|
|
41
|
-
3. Run `pnpm
|
|
42
|
-
4. Run `pnpm
|
|
43
|
-
5.
|
|
42
|
+
3. Run `pnpm generate-payloads stylelint-0` from the repo root to re-pin `payload/package.json` and regenerate its lockfile
|
|
43
|
+
4. Run `pnpm prefetch` to check for new/removed rules
|
|
44
|
+
5. Run `pnpm test` to verify compatibility
|
|
45
|
+
6. If the major version changes, create a new adapter package (`stylelint-1/`)
|
|
44
46
|
|
|
45
47
|
## Development
|
|
46
48
|
|
|
@@ -55,4 +57,4 @@ pnpm test # Run tests
|
|
|
55
57
|
- `stylelint-config-standard` is used as the default config when no local config or Codacy patterns are provided. Without it, Stylelint has zero rules enabled.
|
|
56
58
|
- Stylelint appends the rule name in parentheses to warning text (e.g. `"Unexpected empty block (block-no-empty)"`). The adapter strips this suffix for cleaner messages.
|
|
57
59
|
- `checkAvailability` dynamically imports Stylelint and runs a trivial lint to verify it loads.
|
|
58
|
-
-
|
|
60
|
+
- The tool is an npm _payload_, not a dependency: it is resolved at run time (a Codacy-managed install under `~/.codacy/tools/<id>/`, a `CODACY_TOOL_ROOT_<ID>` root, or this package's own `node_modules` in the monorepo) and `install` runs `npm ci` against the committed `payload/package-lock.json`. See `src/payload.ts`.
|
package/dist/index.js
CHANGED
|
@@ -33,11 +33,11 @@ __export(index_exports, {
|
|
|
33
33
|
default: () => index_default
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
var
|
|
36
|
+
var import_tooling3 = require("@codacy/tooling");
|
|
37
37
|
|
|
38
38
|
// src/adapter.ts
|
|
39
|
-
var
|
|
40
|
-
var
|
|
39
|
+
var import_tooling2 = require("@codacy/tooling");
|
|
40
|
+
var import_path2 = __toESM(require("path"));
|
|
41
41
|
var import_fs = __toESM(require("fs"));
|
|
42
42
|
|
|
43
43
|
// src/patterns.json
|
|
@@ -3476,6 +3476,7 @@ var pattern_mappings_default = {
|
|
|
3476
3476
|
var frameworkMappings = pattern_mappings_default;
|
|
3477
3477
|
var descriptor = {
|
|
3478
3478
|
id: "Stylelint",
|
|
3479
|
+
shortName: "stylelint",
|
|
3479
3480
|
displayName: "Stylelint",
|
|
3480
3481
|
preferredVersion: "16.26.1",
|
|
3481
3482
|
languages: ["CSS", "LESS", "SASS"],
|
|
@@ -3486,7 +3487,21 @@ var descriptor = {
|
|
|
3486
3487
|
frameworkMappings
|
|
3487
3488
|
};
|
|
3488
3489
|
|
|
3490
|
+
// src/payload.ts
|
|
3491
|
+
var import_path = __toESM(require("path"));
|
|
3492
|
+
var PACKAGE_ROOT = import_path.default.resolve(__dirname, "..");
|
|
3493
|
+
var PAYLOAD = {
|
|
3494
|
+
adapterId: descriptor.id,
|
|
3495
|
+
displayName: descriptor.displayName,
|
|
3496
|
+
version: descriptor.preferredVersion,
|
|
3497
|
+
manifestDir: import_path.default.join(PACKAGE_ROOT, "payload"),
|
|
3498
|
+
probe: "stylelint",
|
|
3499
|
+
adjacentFrom: PACKAGE_ROOT,
|
|
3500
|
+
isCompatible: (version) => version.startsWith("16.")
|
|
3501
|
+
};
|
|
3502
|
+
|
|
3489
3503
|
// src/plugin-registry.ts
|
|
3504
|
+
var import_tooling = require("@codacy/tooling");
|
|
3490
3505
|
var A11Y_RULE_NAMES = /* @__PURE__ */ new Set([
|
|
3491
3506
|
"content-property-no-static-value",
|
|
3492
3507
|
"font-size-is-readable",
|
|
@@ -3535,7 +3550,7 @@ function findPluginForCodacyRule(codacyRuleId) {
|
|
|
3535
3550
|
function findPluginForStylelintRule(stylelintRuleId) {
|
|
3536
3551
|
return PLUGINS.find((p) => p.matchesStylelintRule(stylelintRuleId));
|
|
3537
3552
|
}
|
|
3538
|
-
async function loadRequiredPlugins(codacyRuleIds) {
|
|
3553
|
+
async function loadRequiredPlugins(codacyRuleIds, payloadRoot) {
|
|
3539
3554
|
const needed = /* @__PURE__ */ new Set();
|
|
3540
3555
|
for (const id of codacyRuleIds) {
|
|
3541
3556
|
const def = findPluginForCodacyRule(id);
|
|
@@ -3544,8 +3559,7 @@ async function loadRequiredPlugins(codacyRuleIds) {
|
|
|
3544
3559
|
const perPackage = await Promise.all(
|
|
3545
3560
|
Array.from(needed, async (def) => {
|
|
3546
3561
|
try {
|
|
3547
|
-
const
|
|
3548
|
-
const exported = mod.default ?? mod;
|
|
3562
|
+
const exported = await (0, import_tooling.importFromRoot)(payloadRoot, def.packageName);
|
|
3549
3563
|
return Array.isArray(exported) ? exported : [exported];
|
|
3550
3564
|
} catch {
|
|
3551
3565
|
return [];
|
|
@@ -3582,7 +3596,7 @@ function ruleMetadata(ruleId) {
|
|
|
3582
3596
|
const patternId = `${TOOL_ID}_${ruleId}`;
|
|
3583
3597
|
return PATTERN_META.get(patternId) ?? { category: "CodeStyle", severity: "Info" };
|
|
3584
3598
|
}
|
|
3585
|
-
async function buildStylelintConfig(patterns, logger) {
|
|
3599
|
+
async function buildStylelintConfig(patterns, payloadRoot, logger) {
|
|
3586
3600
|
const rules = {};
|
|
3587
3601
|
const prefix = `${TOOL_ID}_`;
|
|
3588
3602
|
const codacyRuleIds = [];
|
|
@@ -3605,7 +3619,7 @@ async function buildStylelintConfig(patterns, logger) {
|
|
|
3605
3619
|
rules[stylelintRuleId] = true;
|
|
3606
3620
|
}
|
|
3607
3621
|
}
|
|
3608
|
-
const plugins = await loadRequiredPlugins(codacyRuleIds);
|
|
3622
|
+
const plugins = await loadRequiredPlugins(codacyRuleIds, payloadRoot);
|
|
3609
3623
|
const config = { rules };
|
|
3610
3624
|
if (plugins.length > 0) {
|
|
3611
3625
|
config.plugins = plugins;
|
|
@@ -3632,8 +3646,8 @@ function readLine(filePath, lineNumber) {
|
|
|
3632
3646
|
return "";
|
|
3633
3647
|
}
|
|
3634
3648
|
}
|
|
3635
|
-
async function importStylelint() {
|
|
3636
|
-
const mod = await
|
|
3649
|
+
async function importStylelint(payloadRoot) {
|
|
3650
|
+
const mod = await (0, import_tooling2.importFromRoot)(payloadRoot, "stylelint", { raw: true });
|
|
3637
3651
|
return mod.lint ? mod : mod.default;
|
|
3638
3652
|
}
|
|
3639
3653
|
var adapter = {
|
|
@@ -3643,24 +3657,27 @@ var adapter = {
|
|
|
3643
3657
|
website: "https://stylelint.io",
|
|
3644
3658
|
prerequisites: [],
|
|
3645
3659
|
/**
|
|
3646
|
-
*
|
|
3647
|
-
*
|
|
3660
|
+
* Resolves the Stylelint payload, verifies it is loadable with a trivial
|
|
3661
|
+
* lint, and returns its version and where it was found — or, when it is not
|
|
3662
|
+
* installed anywhere, the roots searched and how to install it.
|
|
3648
3663
|
*/
|
|
3649
3664
|
async checkAvailability(ctx) {
|
|
3650
3665
|
ctx.logger.debug("Checking availability", { toolId: TOOL_ID });
|
|
3666
|
+
const payload = (0, import_tooling2.resolvePayload)(ctx, PAYLOAD);
|
|
3667
|
+
if (!payload.found) {
|
|
3668
|
+
ctx.logger.debug("Availability check result", {
|
|
3669
|
+
toolId: TOOL_ID,
|
|
3670
|
+
available: false,
|
|
3671
|
+
reason: payload.reason
|
|
3672
|
+
});
|
|
3673
|
+
return (0, import_tooling2.payloadUnavailable)(payload, PAYLOAD);
|
|
3674
|
+
}
|
|
3651
3675
|
try {
|
|
3652
|
-
const mod = await importStylelint();
|
|
3676
|
+
const mod = await importStylelint(payload.root);
|
|
3653
3677
|
await mod.lint({ code: "", config: { rules: {} } });
|
|
3654
|
-
|
|
3655
|
-
try {
|
|
3656
|
-
const stylelintPath = require.resolve("stylelint");
|
|
3657
|
-
const pkgPath = import_path.default.join(import_path.default.dirname(stylelintPath), "..", "package.json");
|
|
3658
|
-
const pkgJson = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf-8"));
|
|
3659
|
-
version = pkgJson.version ?? "unknown";
|
|
3660
|
-
} catch {
|
|
3661
|
-
}
|
|
3678
|
+
const version = (0, import_tooling2.payloadPackageVersion)(payload.root, "stylelint") ?? payload.version;
|
|
3662
3679
|
ctx.logger.debug("Availability check result", { toolId: TOOL_ID, available: true, version });
|
|
3663
|
-
return { available: true, version, installation:
|
|
3680
|
+
return { available: true, version, path: payload.root, installation: payload.source };
|
|
3664
3681
|
} catch (err) {
|
|
3665
3682
|
const reason = `stylelint package not loadable: ${err instanceof Error ? err.message : String(err)}`;
|
|
3666
3683
|
ctx.logger.debug("Availability check result", { toolId: TOOL_ID, available: false, reason });
|
|
@@ -3668,12 +3685,12 @@ var adapter = {
|
|
|
3668
3685
|
}
|
|
3669
3686
|
},
|
|
3670
3687
|
/**
|
|
3671
|
-
*
|
|
3688
|
+
* Installs the pinned Stylelint payload into the Codacy-managed directory
|
|
3689
|
+
* with `npm ci` against the committed lockfile. Refuses in container mode.
|
|
3672
3690
|
*/
|
|
3673
3691
|
async install(ctx) {
|
|
3674
3692
|
ctx.logger.info("Starting install", { toolId: TOOL_ID });
|
|
3675
|
-
|
|
3676
|
-
return { success: true, installedVersion: adapter.preferredVersion };
|
|
3693
|
+
return (0, import_tooling2.installNpmPayload)(ctx, PAYLOAD);
|
|
3677
3694
|
},
|
|
3678
3695
|
/**
|
|
3679
3696
|
* Looks for any of the standard Stylelint config file names in the
|
|
@@ -3682,7 +3699,7 @@ var adapter = {
|
|
|
3682
3699
|
async checkLocalConfigurationFile(ctx) {
|
|
3683
3700
|
ctx.logger.debug("Checking for local config", { toolId: TOOL_ID });
|
|
3684
3701
|
for (const name of LOCAL_CONFIG_FILES) {
|
|
3685
|
-
const candidate =
|
|
3702
|
+
const candidate = import_path2.default.join(ctx.repositoryRoot, name);
|
|
3686
3703
|
try {
|
|
3687
3704
|
import_fs.default.accessSync(candidate);
|
|
3688
3705
|
ctx.logger.debug("Local config check", { toolId: TOOL_ID, found: true, path: candidate });
|
|
@@ -3707,14 +3724,16 @@ var adapter = {
|
|
|
3707
3724
|
const startedAt = /* @__PURE__ */ new Date();
|
|
3708
3725
|
const issues = [];
|
|
3709
3726
|
const errors = [];
|
|
3710
|
-
const absoluteFiles = ctx.targetFiles.map((f) =>
|
|
3727
|
+
const absoluteFiles = ctx.targetFiles.map((f) => import_path2.default.resolve(ctx.repositoryRoot, f));
|
|
3711
3728
|
if (absoluteFiles.length === 0) {
|
|
3712
3729
|
const completedAt2 = /* @__PURE__ */ new Date();
|
|
3713
|
-
return (0,
|
|
3730
|
+
return (0, import_tooling2.buildResult)(TOOL_ID, startedAt, completedAt2, issues, errors, ctx.targetFiles.length);
|
|
3714
3731
|
}
|
|
3715
3732
|
let stylelint;
|
|
3733
|
+
let payloadRoot;
|
|
3716
3734
|
try {
|
|
3717
|
-
|
|
3735
|
+
payloadRoot = (0, import_tooling2.requirePayload)(ctx, PAYLOAD).root;
|
|
3736
|
+
stylelint = await importStylelint(payloadRoot);
|
|
3718
3737
|
} catch (err) {
|
|
3719
3738
|
const completedAt2 = /* @__PURE__ */ new Date();
|
|
3720
3739
|
errors.push({
|
|
@@ -3724,24 +3743,28 @@ var adapter = {
|
|
|
3724
3743
|
message: `Failed to load stylelint: ${err instanceof Error ? err.message : String(err)}`,
|
|
3725
3744
|
level: "error"
|
|
3726
3745
|
});
|
|
3727
|
-
return (0,
|
|
3746
|
+
return (0, import_tooling2.buildResult)(TOOL_ID, startedAt, completedAt2, issues, errors, ctx.targetFiles.length);
|
|
3728
3747
|
}
|
|
3729
3748
|
const lintOptions = { files: absoluteFiles };
|
|
3730
3749
|
if (codacyConfig.useLocalConfigurationFile && codacyConfig.localConfigurationFile) {
|
|
3731
3750
|
lintOptions.configFile = codacyConfig.localConfigurationFile;
|
|
3732
3751
|
} else if (codacyConfig.patterns.length > 0) {
|
|
3733
|
-
lintOptions.config = await buildStylelintConfig(
|
|
3752
|
+
lintOptions.config = await buildStylelintConfig(
|
|
3753
|
+
codacyConfig.patterns,
|
|
3754
|
+
payloadRoot,
|
|
3755
|
+
ctx.logger
|
|
3756
|
+
);
|
|
3734
3757
|
} else {
|
|
3735
3758
|
ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
|
|
3736
3759
|
toolId: TOOL_ID
|
|
3737
3760
|
});
|
|
3738
|
-
return (0,
|
|
3761
|
+
return (0, import_tooling2.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
3739
3762
|
}
|
|
3740
3763
|
try {
|
|
3741
3764
|
const result = await stylelint.lint(lintOptions);
|
|
3742
3765
|
for (const fileResult of result.results) {
|
|
3743
3766
|
if (!fileResult.source) continue;
|
|
3744
|
-
const relPath =
|
|
3767
|
+
const relPath = import_path2.default.relative(ctx.repositoryRoot, fileResult.source);
|
|
3745
3768
|
for (const warning of fileResult.warnings) {
|
|
3746
3769
|
if (!warning.rule) {
|
|
3747
3770
|
errors.push({
|
|
@@ -3789,9 +3812,9 @@ var adapter = {
|
|
|
3789
3812
|
errorCount: errors.length,
|
|
3790
3813
|
durationMs: Date.now() - startMs
|
|
3791
3814
|
});
|
|
3792
|
-
return (0,
|
|
3815
|
+
return (0, import_tooling2.buildResult)(TOOL_ID, startedAt, completedAt, issues, errors, ctx.targetFiles.length);
|
|
3793
3816
|
}
|
|
3794
3817
|
};
|
|
3795
3818
|
|
|
3796
3819
|
// src/index.ts
|
|
3797
|
-
var index_default = (0,
|
|
3820
|
+
var index_default = (0, import_tooling3.defineToolAdapter)(adapter);
|
package/dist/metadata.js
CHANGED
package/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codacy/tools-stylelint-0",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Stylelint adapter — Library-mode CSS/SCSS/Less linter",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist"
|
|
8
|
+
"dist",
|
|
9
|
+
"payload"
|
|
9
10
|
],
|
|
10
11
|
"dependencies": {
|
|
12
|
+
"@codacy/tooling": "0.25.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
11
15
|
"@double-great/stylelint-a11y": "^3.0.3",
|
|
12
16
|
"stylelint": "^16.0.0",
|
|
13
17
|
"stylelint-config-standard": "^36.0.0",
|
|
14
|
-
"stylelint-scss": "^6.12.1"
|
|
15
|
-
"@codacy/tooling": "0.23.1"
|
|
18
|
+
"stylelint-scss": "^6.12.1"
|
|
16
19
|
},
|
|
17
20
|
"license": "MIT",
|
|
18
21
|
"author": "Codacy <support@codacy.com> (https://www.codacy.com)",
|