@codacy/tools-stylelint-0 0.24.0 → 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 +57 -35
- 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
|
|
@@ -3487,7 +3487,21 @@ var descriptor = {
|
|
|
3487
3487
|
frameworkMappings
|
|
3488
3488
|
};
|
|
3489
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
|
+
|
|
3490
3503
|
// src/plugin-registry.ts
|
|
3504
|
+
var import_tooling = require("@codacy/tooling");
|
|
3491
3505
|
var A11Y_RULE_NAMES = /* @__PURE__ */ new Set([
|
|
3492
3506
|
"content-property-no-static-value",
|
|
3493
3507
|
"font-size-is-readable",
|
|
@@ -3536,7 +3550,7 @@ function findPluginForCodacyRule(codacyRuleId) {
|
|
|
3536
3550
|
function findPluginForStylelintRule(stylelintRuleId) {
|
|
3537
3551
|
return PLUGINS.find((p) => p.matchesStylelintRule(stylelintRuleId));
|
|
3538
3552
|
}
|
|
3539
|
-
async function loadRequiredPlugins(codacyRuleIds) {
|
|
3553
|
+
async function loadRequiredPlugins(codacyRuleIds, payloadRoot) {
|
|
3540
3554
|
const needed = /* @__PURE__ */ new Set();
|
|
3541
3555
|
for (const id of codacyRuleIds) {
|
|
3542
3556
|
const def = findPluginForCodacyRule(id);
|
|
@@ -3545,8 +3559,7 @@ async function loadRequiredPlugins(codacyRuleIds) {
|
|
|
3545
3559
|
const perPackage = await Promise.all(
|
|
3546
3560
|
Array.from(needed, async (def) => {
|
|
3547
3561
|
try {
|
|
3548
|
-
const
|
|
3549
|
-
const exported = mod.default ?? mod;
|
|
3562
|
+
const exported = await (0, import_tooling.importFromRoot)(payloadRoot, def.packageName);
|
|
3550
3563
|
return Array.isArray(exported) ? exported : [exported];
|
|
3551
3564
|
} catch {
|
|
3552
3565
|
return [];
|
|
@@ -3583,7 +3596,7 @@ function ruleMetadata(ruleId) {
|
|
|
3583
3596
|
const patternId = `${TOOL_ID}_${ruleId}`;
|
|
3584
3597
|
return PATTERN_META.get(patternId) ?? { category: "CodeStyle", severity: "Info" };
|
|
3585
3598
|
}
|
|
3586
|
-
async function buildStylelintConfig(patterns, logger) {
|
|
3599
|
+
async function buildStylelintConfig(patterns, payloadRoot, logger) {
|
|
3587
3600
|
const rules = {};
|
|
3588
3601
|
const prefix = `${TOOL_ID}_`;
|
|
3589
3602
|
const codacyRuleIds = [];
|
|
@@ -3606,7 +3619,7 @@ async function buildStylelintConfig(patterns, logger) {
|
|
|
3606
3619
|
rules[stylelintRuleId] = true;
|
|
3607
3620
|
}
|
|
3608
3621
|
}
|
|
3609
|
-
const plugins = await loadRequiredPlugins(codacyRuleIds);
|
|
3622
|
+
const plugins = await loadRequiredPlugins(codacyRuleIds, payloadRoot);
|
|
3610
3623
|
const config = { rules };
|
|
3611
3624
|
if (plugins.length > 0) {
|
|
3612
3625
|
config.plugins = plugins;
|
|
@@ -3633,8 +3646,8 @@ function readLine(filePath, lineNumber) {
|
|
|
3633
3646
|
return "";
|
|
3634
3647
|
}
|
|
3635
3648
|
}
|
|
3636
|
-
async function importStylelint() {
|
|
3637
|
-
const mod = await
|
|
3649
|
+
async function importStylelint(payloadRoot) {
|
|
3650
|
+
const mod = await (0, import_tooling2.importFromRoot)(payloadRoot, "stylelint", { raw: true });
|
|
3638
3651
|
return mod.lint ? mod : mod.default;
|
|
3639
3652
|
}
|
|
3640
3653
|
var adapter = {
|
|
@@ -3644,24 +3657,27 @@ var adapter = {
|
|
|
3644
3657
|
website: "https://stylelint.io",
|
|
3645
3658
|
prerequisites: [],
|
|
3646
3659
|
/**
|
|
3647
|
-
*
|
|
3648
|
-
*
|
|
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.
|
|
3649
3663
|
*/
|
|
3650
3664
|
async checkAvailability(ctx) {
|
|
3651
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
|
+
}
|
|
3652
3675
|
try {
|
|
3653
|
-
const mod = await importStylelint();
|
|
3676
|
+
const mod = await importStylelint(payload.root);
|
|
3654
3677
|
await mod.lint({ code: "", config: { rules: {} } });
|
|
3655
|
-
|
|
3656
|
-
try {
|
|
3657
|
-
const stylelintPath = require.resolve("stylelint");
|
|
3658
|
-
const pkgPath = import_path.default.join(import_path.default.dirname(stylelintPath), "..", "package.json");
|
|
3659
|
-
const pkgJson = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf-8"));
|
|
3660
|
-
version = pkgJson.version ?? "unknown";
|
|
3661
|
-
} catch {
|
|
3662
|
-
}
|
|
3678
|
+
const version = (0, import_tooling2.payloadPackageVersion)(payload.root, "stylelint") ?? payload.version;
|
|
3663
3679
|
ctx.logger.debug("Availability check result", { toolId: TOOL_ID, available: true, version });
|
|
3664
|
-
return { available: true, version, installation:
|
|
3680
|
+
return { available: true, version, path: payload.root, installation: payload.source };
|
|
3665
3681
|
} catch (err) {
|
|
3666
3682
|
const reason = `stylelint package not loadable: ${err instanceof Error ? err.message : String(err)}`;
|
|
3667
3683
|
ctx.logger.debug("Availability check result", { toolId: TOOL_ID, available: false, reason });
|
|
@@ -3669,12 +3685,12 @@ var adapter = {
|
|
|
3669
3685
|
}
|
|
3670
3686
|
},
|
|
3671
3687
|
/**
|
|
3672
|
-
*
|
|
3688
|
+
* Installs the pinned Stylelint payload into the Codacy-managed directory
|
|
3689
|
+
* with `npm ci` against the committed lockfile. Refuses in container mode.
|
|
3673
3690
|
*/
|
|
3674
3691
|
async install(ctx) {
|
|
3675
3692
|
ctx.logger.info("Starting install", { toolId: TOOL_ID });
|
|
3676
|
-
|
|
3677
|
-
return { success: true, installedVersion: adapter.preferredVersion };
|
|
3693
|
+
return (0, import_tooling2.installNpmPayload)(ctx, PAYLOAD);
|
|
3678
3694
|
},
|
|
3679
3695
|
/**
|
|
3680
3696
|
* Looks for any of the standard Stylelint config file names in the
|
|
@@ -3683,7 +3699,7 @@ var adapter = {
|
|
|
3683
3699
|
async checkLocalConfigurationFile(ctx) {
|
|
3684
3700
|
ctx.logger.debug("Checking for local config", { toolId: TOOL_ID });
|
|
3685
3701
|
for (const name of LOCAL_CONFIG_FILES) {
|
|
3686
|
-
const candidate =
|
|
3702
|
+
const candidate = import_path2.default.join(ctx.repositoryRoot, name);
|
|
3687
3703
|
try {
|
|
3688
3704
|
import_fs.default.accessSync(candidate);
|
|
3689
3705
|
ctx.logger.debug("Local config check", { toolId: TOOL_ID, found: true, path: candidate });
|
|
@@ -3708,14 +3724,16 @@ var adapter = {
|
|
|
3708
3724
|
const startedAt = /* @__PURE__ */ new Date();
|
|
3709
3725
|
const issues = [];
|
|
3710
3726
|
const errors = [];
|
|
3711
|
-
const absoluteFiles = ctx.targetFiles.map((f) =>
|
|
3727
|
+
const absoluteFiles = ctx.targetFiles.map((f) => import_path2.default.resolve(ctx.repositoryRoot, f));
|
|
3712
3728
|
if (absoluteFiles.length === 0) {
|
|
3713
3729
|
const completedAt2 = /* @__PURE__ */ new Date();
|
|
3714
|
-
return (0,
|
|
3730
|
+
return (0, import_tooling2.buildResult)(TOOL_ID, startedAt, completedAt2, issues, errors, ctx.targetFiles.length);
|
|
3715
3731
|
}
|
|
3716
3732
|
let stylelint;
|
|
3733
|
+
let payloadRoot;
|
|
3717
3734
|
try {
|
|
3718
|
-
|
|
3735
|
+
payloadRoot = (0, import_tooling2.requirePayload)(ctx, PAYLOAD).root;
|
|
3736
|
+
stylelint = await importStylelint(payloadRoot);
|
|
3719
3737
|
} catch (err) {
|
|
3720
3738
|
const completedAt2 = /* @__PURE__ */ new Date();
|
|
3721
3739
|
errors.push({
|
|
@@ -3725,24 +3743,28 @@ var adapter = {
|
|
|
3725
3743
|
message: `Failed to load stylelint: ${err instanceof Error ? err.message : String(err)}`,
|
|
3726
3744
|
level: "error"
|
|
3727
3745
|
});
|
|
3728
|
-
return (0,
|
|
3746
|
+
return (0, import_tooling2.buildResult)(TOOL_ID, startedAt, completedAt2, issues, errors, ctx.targetFiles.length);
|
|
3729
3747
|
}
|
|
3730
3748
|
const lintOptions = { files: absoluteFiles };
|
|
3731
3749
|
if (codacyConfig.useLocalConfigurationFile && codacyConfig.localConfigurationFile) {
|
|
3732
3750
|
lintOptions.configFile = codacyConfig.localConfigurationFile;
|
|
3733
3751
|
} else if (codacyConfig.patterns.length > 0) {
|
|
3734
|
-
lintOptions.config = await buildStylelintConfig(
|
|
3752
|
+
lintOptions.config = await buildStylelintConfig(
|
|
3753
|
+
codacyConfig.patterns,
|
|
3754
|
+
payloadRoot,
|
|
3755
|
+
ctx.logger
|
|
3756
|
+
);
|
|
3735
3757
|
} else {
|
|
3736
3758
|
ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
|
|
3737
3759
|
toolId: TOOL_ID
|
|
3738
3760
|
});
|
|
3739
|
-
return (0,
|
|
3761
|
+
return (0, import_tooling2.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
3740
3762
|
}
|
|
3741
3763
|
try {
|
|
3742
3764
|
const result = await stylelint.lint(lintOptions);
|
|
3743
3765
|
for (const fileResult of result.results) {
|
|
3744
3766
|
if (!fileResult.source) continue;
|
|
3745
|
-
const relPath =
|
|
3767
|
+
const relPath = import_path2.default.relative(ctx.repositoryRoot, fileResult.source);
|
|
3746
3768
|
for (const warning of fileResult.warnings) {
|
|
3747
3769
|
if (!warning.rule) {
|
|
3748
3770
|
errors.push({
|
|
@@ -3790,9 +3812,9 @@ var adapter = {
|
|
|
3790
3812
|
errorCount: errors.length,
|
|
3791
3813
|
durationMs: Date.now() - startMs
|
|
3792
3814
|
});
|
|
3793
|
-
return (0,
|
|
3815
|
+
return (0, import_tooling2.buildResult)(TOOL_ID, startedAt, completedAt, issues, errors, ctx.targetFiles.length);
|
|
3794
3816
|
}
|
|
3795
3817
|
};
|
|
3796
3818
|
|
|
3797
3819
|
// src/index.ts
|
|
3798
|
-
var index_default = (0,
|
|
3820
|
+
var index_default = (0, import_tooling3.defineToolAdapter)(adapter);
|
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.24.0"
|
|
18
|
+
"stylelint-scss": "^6.12.1"
|
|
16
19
|
},
|
|
17
20
|
"license": "MIT",
|
|
18
21
|
"author": "Codacy <support@codacy.com> (https://www.codacy.com)",
|