-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
122 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/plugin-stylelint/mocks/fixtures/basic/.stylelintrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"extends": "stylelint-config-standard", | ||
"rules": { | ||
"block-no-empty": null | ||
"block-no-empty": "impossibleValue" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { type LinterOptions } from 'stylelint'; | ||
import type { RunnerFunction } from '@code-pushup/models'; | ||
import type { Audit, RunnerFunction } from '@code-pushup/models'; | ||
import { lintStyles } from './stylelint-runner.js'; | ||
import { mapStylelintResultsToAudits } from './utils.js'; | ||
|
||
export function createRunnerFunction(opt: LinterOptions): RunnerFunction { | ||
export function createRunnerFunction( | ||
opt: LinterOptions, | ||
expectedAudits: Audit[], | ||
): RunnerFunction { | ||
return async () => { | ||
const report = await lintStyles(opt); | ||
return mapStylelintResultsToAudits(report); | ||
return mapStylelintResultsToAudits(report, expectedAudits); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type NormalizedStyleLintConfig = { | ||
config: { rules: Record<string, unknown[]> }; | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/plugin-stylelint/src/lib/runner/normalize-config.integration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import path from 'node:path'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { getNormalizedConfigForFile } from './normalize-config'; | ||
|
||
describe('getNormalizedConfigForFile', () => { | ||
it('should load config from specified configFile and respect the value of specifically set rules', async () => { | ||
const configFile = path.join( | ||
process.cwd(), | ||
'packages/plugin-stylelint/mocks/fixtures/basic/.stylelintrc.json', | ||
); | ||
|
||
const parsed = await getNormalizedConfigForFile({ configFile }); | ||
|
||
expect(parsed.config.rules['block-no-empty']).toStrictEqual([ | ||
'impossibleValue', | ||
]); // The default value is [ true ], so having the not even valid value from the config file is correct | ||
}); | ||
|
||
it('should load config from specified configFile and add default rules', async () => { | ||
const configFile = path.join( | ||
process.cwd(), | ||
'packages/plugin-stylelint/mocks/fixtures/basic/.stylelintrc.json', | ||
); | ||
|
||
const parsed = await getNormalizedConfigForFile({ configFile }); | ||
expect(Object.keys(parsed.config.rules).length).toBeGreaterThan(1); | ||
}); | ||
}); |
16 changes: 10 additions & 6 deletions
16
packages/plugin-stylelint/src/lib/runner/normalize-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import stylelint, {getConfigForFile, type LinterOptions} from "stylelint"; | ||
import path from "node:path"; | ||
import * as process from "node:process"; | ||
import path from 'node:path'; | ||
import * as process from 'node:process'; | ||
import stylelint, { type LinterOptions, getConfigForFile } from 'stylelint'; | ||
import type { NormalizedStyleLintConfig } from './model.js'; | ||
|
||
export function getNormalizedConfigForFile(options: LinterOptions) { | ||
export function getNormalizedConfigForFile( | ||
options: LinterOptions, | ||
): NormalizedStyleLintConfig { | ||
const _linter = stylelint._createLinter(options); | ||
const configFile = options.configFile ?? path.join(options?.cwd ?? process.cwd(), '.stylelintrc.json'); | ||
const configFile = | ||
options.configFile ?? | ||
path.join(options?.cwd ?? process.cwd(), '.stylelintrc.json'); | ||
return getConfigForFile(_linter, configFile); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import {patchStylelint} from "./index.js"; | ||
import { patchStylelint } from './index.js'; | ||
|
||
(async () => { | ||
await patchStylelint(); | ||
console.log("stylelint patched!"); | ||
})() | ||
console.log('stylelint patched!'); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters