@@ -201,7 +201,7 @@ describe("ESLint", () => {
201201 } ) ;
202202
203203 // https://github.com/eslint/eslint/issues/2380
204- it ( "should not modify baseConfig when format is specified " , ( ) => {
204+ it ( "should not modify baseConfig in the constructor " , ( ) => {
205205 const customBaseConfig = { root : true } ;
206206
207207 new ESLint ( { baseConfig : customBaseConfig , flags } ) ; // eslint-disable-line no-new -- Check for argument side effects
@@ -390,7 +390,7 @@ describe("ESLint", () => {
390390 assert . strictEqual ( results [ 0 ] . suppressedMessages . length , 0 ) ;
391391 } ) ;
392392
393- it ( "should report the total and per file warnings when using local cwd .eslintrc " , async ( ) => {
393+ it ( "should report the total and per file warnings when not using a config file " , async ( ) => {
394394 eslint = new ESLint ( {
395395 flags,
396396 overrideConfig : {
@@ -524,6 +524,36 @@ describe("ESLint", () => {
524524 assert . strictEqual ( results [ 0 ] . suppressedMessages . length , 0 ) ;
525525 } ) ;
526526
527+ if ( os . platform ( ) === "win32" ) {
528+ it ( "should return a warning when given a filename on a different drive by --stdin-filename if warnIgnored is true on Windows" , async ( ) => {
529+ const currentRoot = path . resolve ( "\\" ) ;
530+ const otherRoot = currentRoot === "A:\\" ? "B:\\" : "A:\\" ;
531+
532+ eslint = new ESLint ( {
533+ flags,
534+ cwd : getFixturePath ( ) ,
535+ overrideConfigFile : true
536+ } ) ;
537+
538+ const filePath = `${ otherRoot } file.js` ;
539+ const options = { filePath, warnIgnored : true } ;
540+ const results = await eslint . lintText ( "var bar = foo;" , options ) ;
541+
542+ assert . strictEqual ( results . length , 1 ) ;
543+ assert . strictEqual ( results [ 0 ] . filePath , filePath ) ;
544+ assert . strictEqual ( results [ 0 ] . messages [ 0 ] . severity , 1 ) ;
545+ assert . strictEqual ( results [ 0 ] . messages [ 0 ] . message , "File ignored because outside of base path." ) ;
546+ assert . strictEqual ( results [ 0 ] . messages [ 0 ] . output , void 0 ) ;
547+ assert . strictEqual ( results [ 0 ] . errorCount , 0 ) ;
548+ assert . strictEqual ( results [ 0 ] . warningCount , 1 ) ;
549+ assert . strictEqual ( results [ 0 ] . fatalErrorCount , 0 ) ;
550+ assert . strictEqual ( results [ 0 ] . fixableErrorCount , 0 ) ;
551+ assert . strictEqual ( results [ 0 ] . fixableWarningCount , 0 ) ;
552+ assert . strictEqual ( results [ 0 ] . usedDeprecatedRules . length , 0 ) ;
553+ assert . strictEqual ( results [ 0 ] . suppressedMessages . length , 0 ) ;
554+ } ) ;
555+ }
556+
527557 it ( "should return a warning when given a filename by --stdin-filename in excluded files list if constructor warnIgnored is false, but lintText warnIgnored is true" , async ( ) => {
528558 eslint = new ESLint ( {
529559 flags,
@@ -2937,6 +2967,126 @@ describe("ESLint", () => {
29372967 assert . strictEqual ( results [ 0 ] . messages [ 0 ] . message , "Program is disallowed." ) ;
29382968 } ) ;
29392969
2970+ // https://github.com/eslint/eslint/issues/18575
2971+ describe ( "on Windows" , ( ) => {
2972+ if ( os . platform ( ) !== "win32" ) {
2973+ return ;
2974+ }
2975+
2976+ let otherDriveLetter ;
2977+ const exec = util . promisify ( require ( "node:child_process" ) . exec ) ;
2978+
2979+ /*
2980+ * Map the fixture directory to a new virtual drive.
2981+ * Use the first drive letter available.
2982+ */
2983+ before ( async ( ) => {
2984+ const substDir = getFixturePath ( ) ;
2985+
2986+ for ( const driveLetter of "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) {
2987+ try {
2988+
2989+ // More info on this command at https://en.wikipedia.org/wiki/SUBST
2990+ await exec ( `subst ${ driveLetter } : "${ substDir } "` ) ;
2991+ } catch {
2992+ continue ;
2993+ }
2994+ otherDriveLetter = driveLetter ;
2995+ break ;
2996+ }
2997+ if ( ! otherDriveLetter ) {
2998+ throw Error ( "Unable to assign a virtual drive letter." ) ;
2999+ }
3000+ } ) ;
3001+
3002+ /*
3003+ * Delete the virtual drive.
3004+ */
3005+ after ( async ( ) => {
3006+ if ( otherDriveLetter ) {
3007+ try {
3008+ await exec ( `subst /D ${ otherDriveLetter } :` ) ;
3009+ } catch ( { message } ) {
3010+ throw new Error ( `Unable to unassign virtual drive letter ${ otherDriveLetter } : - ${ message } ` ) ;
3011+ }
3012+ }
3013+ } ) ;
3014+
3015+ it ( "should return a warning when an explicitly given file is on a different drive" , async ( ) => {
3016+ eslint = new ESLint ( {
3017+ flags,
3018+ overrideConfigFile : true ,
3019+ cwd : getFixturePath ( )
3020+ } ) ;
3021+ const filePath = `${ otherDriveLetter } :\\passing.js` ;
3022+ const results = await eslint . lintFiles ( [ filePath ] ) ;
3023+
3024+ assert . strictEqual ( results . length , 1 ) ;
3025+ assert . strictEqual ( results [ 0 ] . filePath , filePath ) ;
3026+ assert . strictEqual ( results [ 0 ] . messages [ 0 ] . severity , 1 ) ;
3027+ assert . strictEqual ( results [ 0 ] . messages [ 0 ] . message , "File ignored because outside of base path." ) ;
3028+ assert . strictEqual ( results [ 0 ] . errorCount , 0 ) ;
3029+ assert . strictEqual ( results [ 0 ] . warningCount , 1 ) ;
3030+ assert . strictEqual ( results [ 0 ] . fatalErrorCount , 0 ) ;
3031+ assert . strictEqual ( results [ 0 ] . fixableErrorCount , 0 ) ;
3032+ assert . strictEqual ( results [ 0 ] . fixableWarningCount , 0 ) ;
3033+ assert . strictEqual ( results [ 0 ] . suppressedMessages . length , 0 ) ;
3034+ } ) ;
3035+
3036+ it ( "should not ignore an explicitly given file that is on the same drive as cwd" , async ( ) => {
3037+ eslint = new ESLint ( {
3038+ flags,
3039+ overrideConfigFile : true ,
3040+ cwd : `${ otherDriveLetter } :\\`
3041+ } ) ;
3042+ const filePath = `${ otherDriveLetter } :\\passing.js` ;
3043+ const results = await eslint . lintFiles ( [ filePath ] ) ;
3044+
3045+ assert . strictEqual ( results . length , 1 ) ;
3046+ assert . strictEqual ( results [ 0 ] . filePath , filePath ) ;
3047+ assert . strictEqual ( results [ 0 ] . messages . length , 0 ) ;
3048+ assert . strictEqual ( results [ 0 ] . errorCount , 0 ) ;
3049+ assert . strictEqual ( results [ 0 ] . warningCount , 0 ) ;
3050+ assert . strictEqual ( results [ 0 ] . fatalErrorCount , 0 ) ;
3051+ assert . strictEqual ( results [ 0 ] . fixableErrorCount , 0 ) ;
3052+ assert . strictEqual ( results [ 0 ] . fixableWarningCount , 0 ) ;
3053+ assert . strictEqual ( results [ 0 ] . suppressedMessages . length , 0 ) ;
3054+ } ) ;
3055+
3056+ it ( "should not ignore a file on the same drive as cwd that matches a glob pattern" , async ( ) => {
3057+ eslint = new ESLint ( {
3058+ flags,
3059+ overrideConfigFile : true ,
3060+ cwd : `${ otherDriveLetter } :\\`
3061+ } ) ;
3062+ const pattern = `${ otherDriveLetter } :\\pa*ng.*` ;
3063+ const results = await eslint . lintFiles ( [ pattern ] ) ;
3064+
3065+ assert . strictEqual ( results . length , 1 ) ;
3066+ assert . strictEqual ( results [ 0 ] . filePath , `${ otherDriveLetter } :\\passing.js` ) ;
3067+ assert . strictEqual ( results [ 0 ] . messages . length , 0 ) ;
3068+ assert . strictEqual ( results [ 0 ] . errorCount , 0 ) ;
3069+ assert . strictEqual ( results [ 0 ] . warningCount , 0 ) ;
3070+ assert . strictEqual ( results [ 0 ] . fatalErrorCount , 0 ) ;
3071+ assert . strictEqual ( results [ 0 ] . fixableErrorCount , 0 ) ;
3072+ assert . strictEqual ( results [ 0 ] . fixableWarningCount , 0 ) ;
3073+ assert . strictEqual ( results [ 0 ] . suppressedMessages . length , 0 ) ;
3074+ } ) ;
3075+
3076+ it ( "should throw an error when a glob pattern matches only files on different drive" , async ( ) => {
3077+ eslint = new ESLint ( {
3078+ flags,
3079+ overrideConfigFile : true ,
3080+ cwd : getFixturePath ( )
3081+ } ) ;
3082+ const pattern = `${ otherDriveLetter } :\\pa**ng.*` ;
3083+
3084+ await assert . rejects (
3085+ eslint . lintFiles ( [ pattern ] ) ,
3086+ `All files matched by '${ otherDriveLetter } :\\pa**ng.*' are ignored.`
3087+ ) ;
3088+ } ) ;
3089+ } ) ;
29403090 } ) ;
29413091
29423092
@@ -6110,6 +6260,22 @@ describe("ESLint", () => {
61106260 assert ( await engine . isPathIgnored ( "node_modules/foo.js" ) ) ;
61116261 } ) ;
61126262
6263+ if ( os . platform ( ) === "win32" ) {
6264+ it ( "should return true for a file on a different drive on Windows" , async ( ) => {
6265+ const currentRoot = path . resolve ( "\\" ) ;
6266+ const otherRoot = currentRoot === "A:\\" ? "B:\\" : "A:\\" ;
6267+ const engine = new ESLint ( {
6268+ flags,
6269+ overrideConfigFile : true ,
6270+ cwd : currentRoot
6271+ } ) ;
6272+
6273+ assert ( ! await engine . isPathIgnored ( `${ currentRoot } file.js` ) ) ;
6274+ assert ( await engine . isPathIgnored ( `${ otherRoot } file.js` ) ) ;
6275+ assert ( await engine . isPathIgnored ( "//SERVER//share//file.js" ) ) ;
6276+ } ) ;
6277+ }
6278+
61136279 describe ( "about the default ignore patterns" , ( ) => {
61146280 it ( "should always apply default ignore patterns if ignore option is true" , async ( ) => {
61156281 const cwd = getFixturePath ( "ignored-paths" ) ;
0 commit comments