Skip to content

Commit 37a667b

Browse files
authored
NEW @W-19397402@ root_working_folder can be a relative path (#371)
1 parent 5164475 commit 37a667b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/code-analyzer-core/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class CodeAnalyzerConfig {
151151
custom_engine_plugin_modules: configExtractor.extractArray(FIELDS.CUSTOM_ENGINE_PLUGIN_MODULES,
152152
engApi.ValueValidator.validateString,
153153
DEFAULT_CONFIG.custom_engine_plugin_modules)!,
154-
root_working_folder: !rawConfig.root_working_folder ? os.tmpdir() : validateAbsoluteFolder(rawConfig.root_working_folder, FIELDS.ROOT_WORKING_FOLDER),
154+
root_working_folder: configExtractor.extractFolder(FIELDS.ROOT_WORKING_FOLDER, DEFAULT_CONFIG.root_working_folder)!,
155155
preserve_all_working_folders: configExtractor.extractBoolean(FIELDS.PRESERVE_ALL_WORKING_FOLDERS, DEFAULT_CONFIG.preserve_all_working_folders)!,
156156
rules: extractRulesValue(configExtractor),
157157
engines: extractEnginesValue(configExtractor)

packages/code-analyzer-core/test/config.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,18 @@ describe("Tests for creating and accessing configuration values", () => {
308308
getMessageFromCatalog(SHARED_MESSAGE_CATALOG, 'ConfigValueMustBeOfType','preserve_all_working_folders', 'boolean', 'string'));
309309
})
310310

311-
it("When supplied root_working_folder is a valid absolute path, then we use it", () => {
311+
it.each([
312+
{
313+
case: 'absolute',
314+
testPath: path.join(TEST_DATA_DIR, 'sampleWorkspace')
315+
},
316+
{
317+
case: 'relative',
318+
testPath: path.join('test', 'test-data', 'sampleWorkspace')
319+
}
320+
])("When supplied root_working_folder is a valid $case path, then we use it", ({testPath}) => {
312321
const workingFoldersRootValue: string = path.join(TEST_DATA_DIR, 'sampleWorkspace');
313-
const conf: CodeAnalyzerConfig = CodeAnalyzerConfig.fromObject({root_working_folder: workingFoldersRootValue});
322+
const conf: CodeAnalyzerConfig = CodeAnalyzerConfig.fromObject({root_working_folder: testPath});
314323
expect(conf.getRootWorkingFolder()).toEqual(workingFoldersRootValue);
315324
});
316325

@@ -324,11 +333,6 @@ describe("Tests for creating and accessing configuration values", () => {
324333
getMessageFromCatalog(SHARED_MESSAGE_CATALOG, 'ConfigFolderValueMustNotBeFile', 'root_working_folder', path.resolve('package.json')));
325334
});
326335

327-
it("When supplied root_working_folder is a relative folder, then we error", () => {
328-
expect(() => CodeAnalyzerConfig.fromObject({root_working_folder: 'test/test-data'})).toThrow(
329-
getMessage('ConfigPathValueMustBeAbsolute', 'root_working_folder', 'test/test-data', path.resolve('test', 'test-data')));
330-
});
331-
332336
it("When supplied config_root path is a valid absolute path, then we use it", () => {
333337
const configRootValue: string = path.join(TEST_DATA_DIR, 'sampleWorkspace');
334338
const conf: CodeAnalyzerConfig = CodeAnalyzerConfig.fromObject({config_root: configRootValue});

0 commit comments

Comments
 (0)