@@ -4,8 +4,14 @@ import {spawnSync} from 'node:child_process';
4
4
import { resolve , sep , dirname } from 'node:path' ;
5
5
import { fileURLToPath } from 'node:url' ;
6
6
7
+ import stylelint from 'stylelint' ;
8
+
9
+ import baseConfig from './fixtures/stylelint.config.js' ;
10
+
7
11
const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
8
12
13
+ const stylelintCwd = `${ __dirname } /fixtures` ;
14
+
9
15
/**
10
16
* Tests that report errors in multiple files may change the order of the files
11
17
* across multiple runs.
@@ -65,15 +71,33 @@ describe('E2E Tests', () => {
65
71
assert . strictEqual ( result . error , expectedResult ) ;
66
72
assert . strictEqual ( result . status , 0 ) ;
67
73
} ) ;
74
+
75
+ /** @see https://github.com/prettier/stylelint-prettier/issues/354 */
76
+ test ( 'the --fix option works correctly with other rules' , async ( ) => {
77
+ const inputCode = `.a {\n color: #ffffff;\n font-size: 16px\n}\n` ;
78
+ const fixConfig = structuredClone ( baseConfig ) ;
79
+ fixConfig . rules [ 'color-hex-length' ] = 'short' ;
80
+
81
+ const { code : outputCode } = await stylelint . lint ( {
82
+ code : inputCode ,
83
+ configBasedir : stylelintCwd ,
84
+ fix : true ,
85
+ config : fixConfig ,
86
+ } ) ;
87
+
88
+ assert . strictEqual (
89
+ outputCode ,
90
+ '.a {\n color: #fff;\n font-size: 16px;\n}\n'
91
+ ) ;
92
+ } ) ;
68
93
} ) ;
69
94
70
95
function runStylelint ( pattern ) {
71
96
const stylelintCmd = resolve ( `${ __dirname } /../node_modules/.bin/stylelint` ) ;
72
- const cwd = `${ __dirname } /fixtures` ;
73
97
74
98
// Use github formatter as it is less likely to change across releases
75
99
const result = spawnSync ( stylelintCmd , [ '--formatter=github' , pattern ] , {
76
- cwd,
100
+ cwd : stylelintCwd ,
77
101
} ) ;
78
102
79
103
return {
@@ -82,6 +106,6 @@ function runStylelint(pattern) {
82
106
error : result . stderr
83
107
. toString ( )
84
108
. trim ( )
85
- . replaceAll ( `file=${ cwd } ${ sep } ` , 'file=' ) ,
109
+ . replaceAll ( `file=${ stylelintCwd } ${ sep } ` , 'file=' ) ,
86
110
} ;
87
111
}
0 commit comments