@@ -1887,6 +1887,120 @@ describe("ESLint", () => {
18871887 assert . strictEqual ( results [ 0 ] . filePath , getFixturePath ( "ignores-directory/subdir/subsubdir/a.js" ) ) ;
18881888 } ) ;
18891889
1890+ // https://github.com/eslint/eslint/issues/17964#issuecomment-1879840650
1891+ it ( "should allow directories to be unignored without also unignoring all files in them" , async ( ) => {
1892+ eslint = new ESLint ( {
1893+ cwd : getFixturePath ( "ignores-directory-deep" ) ,
1894+ overrideConfigFile : true ,
1895+ overrideConfig : {
1896+ ignores : [
1897+
1898+ // ignore all files and directories
1899+ "tests/format/**/*" ,
1900+
1901+ // unignore all directories
1902+ "!tests/format/**/*/" ,
1903+
1904+ // unignore only specific files
1905+ "!tests/format/**/jsfmt.spec.js"
1906+ ]
1907+ }
1908+ } ) ;
1909+ const results = await eslint . lintFiles ( [ "." ] ) ;
1910+
1911+ assert . strictEqual ( results . length , 2 ) ;
1912+ assert . strictEqual ( results [ 0 ] . errorCount , 0 ) ;
1913+ assert . strictEqual ( results [ 0 ] . warningCount , 0 ) ;
1914+ assert . strictEqual ( results [ 0 ] . filePath , getFixturePath ( "ignores-directory-deep/tests/format/jsfmt.spec.js" ) ) ;
1915+ assert . strictEqual ( results [ 1 ] . errorCount , 0 ) ;
1916+ assert . strictEqual ( results [ 1 ] . warningCount , 0 ) ;
1917+ assert . strictEqual ( results [ 1 ] . filePath , getFixturePath ( "ignores-directory-deep/tests/format/subdir/jsfmt.spec.js" ) ) ;
1918+ } ) ;
1919+
1920+ it ( "should allow only subdirectories to be ignored by a pattern ending with '/'" , async ( ) => {
1921+ eslint = new ESLint ( {
1922+ cwd : getFixturePath ( "ignores-directory-deep" ) ,
1923+ overrideConfigFile : true ,
1924+ overrideConfig : {
1925+ ignores : [
1926+ "tests/format/*/"
1927+ ]
1928+ }
1929+ } ) ;
1930+ const results = await eslint . lintFiles ( [ "." ] ) ;
1931+
1932+ assert . strictEqual ( results . length , 2 ) ;
1933+ assert . strictEqual ( results [ 0 ] . errorCount , 0 ) ;
1934+ assert . strictEqual ( results [ 0 ] . warningCount , 0 ) ;
1935+ assert . strictEqual ( results [ 0 ] . filePath , getFixturePath ( "ignores-directory-deep/tests/format/foo.js" ) ) ;
1936+ assert . strictEqual ( results [ 1 ] . errorCount , 0 ) ;
1937+ assert . strictEqual ( results [ 1 ] . warningCount , 0 ) ;
1938+ assert . strictEqual ( results [ 1 ] . filePath , getFixturePath ( "ignores-directory-deep/tests/format/jsfmt.spec.js" ) ) ;
1939+ } ) ;
1940+
1941+ it ( "should allow only contents of a directory but not the directory itself to be ignored by a pattern ending with '**/*'" , async ( ) => {
1942+ eslint = new ESLint ( {
1943+ cwd : getFixturePath ( "ignores-directory-deep" ) ,
1944+ overrideConfigFile : true ,
1945+ overrideConfig : {
1946+ ignores : [
1947+ "tests/format/**/*" ,
1948+ "!tests/format/jsfmt.spec.js"
1949+ ]
1950+ }
1951+ } ) ;
1952+ const results = await eslint . lintFiles ( [ "." ] ) ;
1953+
1954+ assert . strictEqual ( results . length , 1 ) ;
1955+ assert . strictEqual ( results [ 0 ] . errorCount , 0 ) ;
1956+ assert . strictEqual ( results [ 0 ] . warningCount , 0 ) ;
1957+ assert . strictEqual ( results [ 0 ] . filePath , getFixturePath ( "ignores-directory-deep/tests/format/jsfmt.spec.js" ) ) ;
1958+ } ) ;
1959+
1960+ it ( "should skip ignored files in an unignored directory" , async ( ) => {
1961+ eslint = new ESLint ( {
1962+ cwd : getFixturePath ( "ignores-directory-deep" ) ,
1963+ overrideConfigFile : true ,
1964+ overrideConfig : {
1965+ ignores : [
1966+
1967+ // ignore 'tests/format/' and all its contents
1968+ "tests/format/**" ,
1969+
1970+ // unignore 'tests/format/', but its contents is still ignored
1971+ "!tests/format/"
1972+ ]
1973+ }
1974+ } ) ;
1975+
1976+ await assert . rejects ( async ( ) => {
1977+ await eslint . lintFiles ( [ "." ] ) ;
1978+ } , / A l l f i l e s m a t c h e d b y ' .' a r e i g n o r e d / u) ;
1979+ } ) ;
1980+
1981+ it ( "should skip files in an ignored directory even if they are matched by a negated pattern" , async ( ) => {
1982+ eslint = new ESLint ( {
1983+ cwd : getFixturePath ( "ignores-directory-deep" ) ,
1984+ overrideConfigFile : true ,
1985+ overrideConfig : {
1986+ ignores : [
1987+
1988+ // ignore 'tests/format/' and all its contents
1989+ "tests/format/**" ,
1990+
1991+ // this patterns match some or all of its contents, but 'tests/format/' is still ignored
1992+ "!tests/format/jsfmt.spec.js" ,
1993+ "!tests/format/**/jsfmt.spec.js" ,
1994+ "!tests/format/*" ,
1995+ "!tests/format/**/*"
1996+ ]
1997+ }
1998+ } ) ;
1999+
2000+ await assert . rejects ( async ( ) => {
2001+ await eslint . lintFiles ( [ "." ] ) ;
2002+ } , / A l l f i l e s m a t c h e d b y ' .' a r e i g n o r e d / u) ;
2003+ } ) ;
18902004
18912005 } ) ;
18922006
0 commit comments