Skip to content

Commit e745c01

Browse files
committed
wip
1 parent 11459cc commit e745c01

File tree

11 files changed

+116
-15
lines changed

11 files changed

+116
-15
lines changed

code-pushup.config.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,11 @@ export default mergeConfigs(
3737
{
3838
plugins: [
3939
await stylelintPlugin({
40+
configFile: 'packages/plugin-stylelint/mocks/fixtures/basic/.stylelintrc.json',
4041
files: 'packages/plugin-stylelint/mocks/fixtures/basic/**/*.css', // Adjust the path to your CSS files
4142
config: {
4243
rules: {
4344
'color-no-invalid-hex': true,
44-
'block-no-empty': true,
45-
'unit-no-unknown': true,
46-
'no-duplicate-selectors': true,
47-
'property-no-unknown': true,
48-
'selector-pseudo-class-no-unknown': true,
49-
'declaration-block-no-duplicate-properties': true,
50-
'font-family-no-missing-generic-family-keyword': true,
51-
'string-no-newline': true,
52-
'length-zero-no-unit': true,
5345
},
5446
},
5547
}),

package-lock.json

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"semver": "^7.6.3",
4242
"simple-git": "^3.26.0",
4343
"stylelint": "^16.12.0",
44+
"stylelint-config-standard": "^36.0.1",
4445
"tslib": "^2.6.2",
4546
"vscode-material-icons": "^0.1.1",
4647
"yaml": "^2.5.1",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "stylelint-config-standard",
3+
"rules": {
4+
"block-no-empty": null
5+
}
6+
}

packages/plugin-stylelint/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,8 @@
5555
"@nx/vite": {
5656
"optional": true
5757
}
58+
},
59+
"scripts": {
60+
"postinstall": "node ./src/scripts/postinstall.js"
5861
}
5962
}

packages/plugin-stylelint/project.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"options": {
3737
"configFile": "packages/plugin-stylelint/vite.config.integration.ts"
3838
}
39+
},
40+
"postinstall": {
41+
"command": "tsx --tsconfig=packages/plugin-stylelint/tsconfig.lib.json packages/plugin-stylelint/src/scripts/postinstall/bin.ts"
3942
}
4043
},
4144
"tags": ["scope:plugin", "type:feature", "publishable"]

packages/plugin-stylelint/src/lib/runner/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { LinterOptions } from 'stylelint';
1+
import { type LinterOptions } from 'stylelint';
22
import type { RunnerFunction } from '@code-pushup/models';
33
import { lintStyles } from './stylelint-runner.js';
4-
import { mapStylelintResultsToAudits } from './utils';
4+
import { mapStylelintResultsToAudits } from './utils.js';
55

66
export function createRunnerFunction(opt: LinterOptions): RunnerFunction {
77
return async () => {

packages/plugin-stylelint/src/lib/runner/stylelint-runner.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
import stylelint, { type LinterOptions } from 'stylelint';
2-
import type { Audit } from '@code-pushup/models';
1+
import stylelint, { type LinterOptions, getConfigForFile } from 'stylelint';
32

43
// Run Stylelint Programmatically
5-
export async function lintStyles(opt: LinterOptions) {
4+
export async function lintStyles(opt: Omit<LinterOptions, 'formatter'>) {
5+
console.log('Stylelint props:', Object.keys(stylelint));
6+
7+
const _linter = stylelint._createLinter(opt);
8+
//console.log('Stylelint._createLinter:', Object.keys(_linter));
9+
//console.log('Stylelint._createLinter._extendExplorer:', _linter._extendExplorer);
10+
//console.log('Stylelint._createLinter._extendExplorer.load():', await _linter._extendExplorer.load(opt.configFile ?? ''));
11+
console.log('Stylelint._createLinter.resolveConfig:', await getConfigForFile(opt.configFile ?? '', {
12+
configFile: opt.configFile,
13+
configBasedir: opt.configBasedir,
14+
config: opt.config,
15+
cwd: opt.cwd,
16+
}));
17+
18+
619
try {
20+
// eslint-disable-next-line functional/immutable-data
21+
globalThis.console.assert = globalThis.console.assert || (() => {});
722
const { results } = await stylelint.lint({
823
...opt,
924
formatter: 'json',

packages/plugin-stylelint/src/lib/runner/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LintResult } from 'stylelint';
1+
import stylelint, { type LintResult } from 'stylelint';
22
import type { Audit, AuditReport } from '@code-pushup/models';
33

44
export function mapStylelintResultsToAudits(results: LintResult[]): Audit[] {
@@ -49,3 +49,7 @@ export function mapStylelintResultsToAudits(results: LintResult[]): Audit[] {
4949

5050
return [...auditMap.values()];
5151
}
52+
53+
export function getRules() {
54+
return Object.keys(stylelint.rules);
55+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {patchStylelint} from "./index.js";
2+
3+
(async () => {
4+
await patchStylelint();
5+
console.log("stylelint patched!");
6+
})()

0 commit comments

Comments
 (0)