-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(linter): update eslint config lookup to correctly handle configs …
…at the root (#26508)
- Loading branch information
1 parent
0018842
commit 0a4551c
Showing
3 changed files
with
177 additions
and
12 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
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,106 @@ | ||
import { TempFs } from '@nx/devkit/internal-testing-utils'; | ||
import { join } from 'path'; | ||
import { | ||
ESLINT_FLAT_CONFIG_FILENAMES, | ||
ESLINT_OLD_CONFIG_FILENAMES, | ||
findFlatConfigFile, | ||
findOldConfigFile, | ||
} from './config-file'; | ||
|
||
describe('config-file', () => { | ||
let fs: TempFs; | ||
|
||
beforeEach(() => { | ||
fs = new TempFs('eslint-config-file'); | ||
}); | ||
|
||
afterEach(() => { | ||
fs.cleanup(); | ||
}); | ||
|
||
describe('findFlatConfigFile', () => { | ||
it.each(ESLINT_FLAT_CONFIG_FILENAMES)( | ||
'should find flat config file "%s" when it exists in the directory', | ||
(configFile) => { | ||
fs.createFilesSync({ | ||
[`libs/lib1/${configFile}`]: '', | ||
}); | ||
|
||
const result = findFlatConfigFile('libs/lib1', fs.tempDir); | ||
|
||
expect(result).toEqual(join(fs.tempDir, `libs/lib1/${configFile}`)); | ||
} | ||
); | ||
|
||
it.each(ESLINT_FLAT_CONFIG_FILENAMES)( | ||
'should find flat config file "%s" when it exists in a parent directory', | ||
(configFile) => { | ||
fs.createFilesSync({ | ||
[`libs/${configFile}`]: '', | ||
'libs/lib1/src/index.ts': '', | ||
}); | ||
|
||
const result = findFlatConfigFile('libs/lib1', fs.tempDir); | ||
|
||
expect(result).toEqual(join(fs.tempDir, `libs/${configFile}`)); | ||
} | ||
); | ||
|
||
it.each(ESLINT_FLAT_CONFIG_FILENAMES)( | ||
'should find flat config file "%s" when it exists at the workspace root', | ||
(configFile) => { | ||
fs.createFilesSync({ | ||
[configFile]: '', | ||
'libs/lib1/src/index.ts': '', | ||
}); | ||
|
||
const result = findFlatConfigFile('libs/lib1', fs.tempDir); | ||
|
||
expect(result).toEqual(join(fs.tempDir, configFile)); | ||
} | ||
); | ||
}); | ||
|
||
describe('findOldConfigFile', () => { | ||
it.each(ESLINT_OLD_CONFIG_FILENAMES)( | ||
'should find flat config file "%s" when it exists in the directory', | ||
(configFile) => { | ||
fs.createFilesSync({ | ||
[`libs/lib1/${configFile}`]: '', | ||
}); | ||
|
||
const result = findOldConfigFile('libs/lib1', fs.tempDir); | ||
|
||
expect(result).toEqual(join(fs.tempDir, `libs/lib1/${configFile}`)); | ||
} | ||
); | ||
|
||
it.each(ESLINT_OLD_CONFIG_FILENAMES)( | ||
'should find flat config file "%s" when it exists in a parent directory', | ||
(configFile) => { | ||
fs.createFilesSync({ | ||
[`libs/${configFile}`]: '', | ||
'libs/lib1/src/index.ts': '', | ||
}); | ||
|
||
const result = findOldConfigFile('libs/lib1', fs.tempDir); | ||
|
||
expect(result).toEqual(join(fs.tempDir, `libs/${configFile}`)); | ||
} | ||
); | ||
|
||
it.each(ESLINT_OLD_CONFIG_FILENAMES)( | ||
'should find flat config file "%s" when it exists at the workspace root', | ||
(configFile) => { | ||
fs.createFilesSync({ | ||
[configFile]: '', | ||
'libs/lib1/src/index.ts': '', | ||
}); | ||
|
||
const result = findOldConfigFile('libs/lib1', fs.tempDir); | ||
|
||
expect(result).toEqual(join(fs.tempDir, 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