@@ -4,8 +4,14 @@ import {spawnSync} from 'node:child_process';
44import { resolve , sep , dirname } from 'node:path' ;
55import { fileURLToPath } from 'node:url' ;
66
7+ import stylelint from 'stylelint' ;
8+
9+ import baseConfig from './fixtures/stylelint.config.js' ;
10+
711const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
812
13+ const stylelintCwd = `${ __dirname } /fixtures` ;
14+
915/**
1016 * Tests that report errors in multiple files may change the order of the files
1117 * across multiple runs.
@@ -65,15 +71,33 @@ describe('E2E Tests', () => {
6571 assert . strictEqual ( result . error , expectedResult ) ;
6672 assert . strictEqual ( result . status , 0 ) ;
6773 } ) ;
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+ } ) ;
6893} ) ;
6994
7095function runStylelint ( pattern ) {
7196 const stylelintCmd = resolve ( `${ __dirname } /../node_modules/.bin/stylelint` ) ;
72- const cwd = `${ __dirname } /fixtures` ;
7397
7498 // Use github formatter as it is less likely to change across releases
7599 const result = spawnSync ( stylelintCmd , [ '--formatter=github' , pattern ] , {
76- cwd,
100+ cwd : stylelintCwd ,
77101 } ) ;
78102
79103 return {
@@ -82,6 +106,6 @@ function runStylelint(pattern) {
82106 error : result . stderr
83107 . toString ( )
84108 . trim ( )
85- . replaceAll ( `file=${ cwd } ${ sep } ` , 'file=' ) ,
109+ . replaceAll ( `file=${ stylelintCwd } ${ sep } ` , 'file=' ) ,
86110 } ;
87111}
0 commit comments