-
Notifications
You must be signed in to change notification settings - Fork 4
NEW @W-19397402@ Implemented hidden config property for keeping working d… #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -326,21 +326,29 @@ export class CodeAnalyzer { | |
|
|
||
| const runPromises: Promise<EngineRunResults>[] = ruleSelection.getEngineNames().map(async (engineName) => { | ||
| const workingFolder: string = await this.tempFolder.makeSubfolder(runWorkingFolderName, engineName); | ||
| if (this.config.getPreserveAllWorkingDirectories()) { | ||
| this.tempFolder.markToBeKept(runWorkingFolderName, engineName); | ||
| } | ||
| const engineRunOptions: engApi.RunOptions = { | ||
| logFolder: this.config.getLogFolder(), | ||
| workingFolder: workingFolder, | ||
| workspace: engApiWorkspace | ||
| }; | ||
| const errorCallback: () => void = () => { | ||
| // istanbul ignore else | ||
| if (!this.tempFolder.isKept(runWorkingFolderName, engineName)) { | ||
| this.emitLogEvent(LogLevel.Debug, getMessage('EngineWorkingFolderKept', engineName, workingFolder)); | ||
| this.emitLogEvent(LogLevel.Debug, getMessage('EngineWorkingFolderKeptDueToError', engineName, workingFolder)); | ||
| this.tempFolder.markToBeKept(runWorkingFolderName, engineName); | ||
| } | ||
| }; | ||
| const results: EngineRunResults = await this.runEngineAndValidateResults(engineName, ruleSelection, engineRunOptions, errorCallback); | ||
| await this.tempFolder.removeIfNotKept(runWorkingFolderName, engineName); | ||
| return results; | ||
| }); | ||
| if (this.config.getPreserveAllWorkingDirectories()) { | ||
| this.tempFolder.markToBeKept(runWorkingFolderName); | ||
| this.emitLogEvent(LogLevel.Debug, getMessage('AllWorkingFoldersKept', await this.tempFolder.getPath(runWorkingFolderName))); | ||
| } | ||
| const engineRunResultsList: EngineRunResults[] = await Promise.all(runPromises); | ||
|
|
||
| await this.tempFolder.removeIfNotKept(runWorkingFolderName); | ||
|
|
@@ -377,14 +385,19 @@ export class CodeAnalyzer { | |
|
|
||
| const rulePromises: Promise<RuleImpl[]>[] = this.getEngineNames().map(async (engineName) => { | ||
| const workingFolder: string = await this.tempFolder.makeSubfolder(rulesWorkingFolderName, engineName); | ||
|
|
||
| if (this.config.getPreserveAllWorkingDirectories()) { | ||
| this.tempFolder.markToBeKept(rulesWorkingFolderName, engineName) | ||
| } | ||
|
|
||
| const describeOptions: engApi.DescribeOptions = { | ||
| workspace: engApiWorkspace, | ||
| workingFolder: workingFolder, | ||
| logFolder: this.config.getLogFolder() | ||
| }; | ||
| const errorCallback: () => void = () => { | ||
| if (!this.tempFolder.isKept(rulesWorkingFolderName, engineName)) { | ||
| this.emitLogEvent(LogLevel.Debug, getMessage('EngineWorkingFolderKept', engineName, workingFolder)); | ||
| this.emitLogEvent(LogLevel.Debug, getMessage('EngineWorkingFolderKeptDueToError', engineName, workingFolder)); | ||
| this.tempFolder.markToBeKept(rulesWorkingFolderName, engineName); | ||
| } | ||
| }; | ||
|
|
@@ -393,6 +406,11 @@ export class CodeAnalyzer { | |
| return rules; | ||
| }); | ||
|
|
||
| if (this.config.getPreserveAllWorkingDirectories()) { | ||
| this.tempFolder.markToBeKept(rulesWorkingFolderName); | ||
|
||
| this.emitLogEvent(LogLevel.Debug, getMessage('AllWorkingFoldersKept', await this.tempFolder.getPath(rulesWorkingFolderName))); | ||
| } | ||
|
|
||
| this.rulesCache.set(cacheKey, (await Promise.all(rulePromises)).flat()); | ||
|
|
||
| await this.tempFolder.removeIfNotKept(rulesWorkingFolderName); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ export const FIELDS = { | |
| LOG_FOLDER: 'log_folder', | ||
| LOG_LEVEL: 'log_level', | ||
| CUSTOM_ENGINE_PLUGIN_MODULES: 'custom_engine_plugin_modules', // Hidden | ||
| PRESERVE_ALL_WORKING_DIRECTORIES: 'preserve_all_working_directories', // Hidden | ||
| RULES: 'rules', | ||
| ENGINES: 'engines', | ||
| SEVERITY: 'severity', | ||
|
|
@@ -41,6 +42,7 @@ type TopLevelConfig = { | |
| log_level: LogLevel | ||
| rules: Record<string, RuleOverrides> | ||
| engines: Record<string, EngineOverrides> | ||
| preserve_all_working_directories: boolean // INTERNAL USE ONLY | ||
|
||
| custom_engine_plugin_modules: string[] // INTERNAL USE ONLY | ||
| } | ||
|
|
||
|
|
@@ -51,6 +53,7 @@ export const DEFAULT_CONFIG: TopLevelConfig = { | |
| log_level: LogLevel.Debug, | ||
| rules: {}, | ||
| engines: {}, | ||
| preserve_all_working_directories: false, // INTERNAL USE ONLY | ||
| custom_engine_plugin_modules: [], // INTERNAL USE ONLY | ||
| }; | ||
|
|
||
|
|
@@ -136,7 +139,7 @@ export class CodeAnalyzerConfig { | |
| configRoot = !rawConfig.config_root ? (configRoot ?? process.cwd()) : | ||
| validateAbsoluteFolder(rawConfig.config_root, FIELDS.CONFIG_ROOT); | ||
| const configExtractor: engApi.ConfigValueExtractor = new engApi.ConfigValueExtractor(rawConfig, '', configRoot); | ||
| configExtractor.addKeysThatBypassValidation([FIELDS.CUSTOM_ENGINE_PLUGIN_MODULES]); // Because custom_engine_plugin_modules is currently hidden | ||
| configExtractor.addKeysThatBypassValidation([FIELDS.CUSTOM_ENGINE_PLUGIN_MODULES, FIELDS.PRESERVE_ALL_WORKING_DIRECTORIES]); // Hidden fields bypass validation | ||
| configExtractor.validateContainsOnlySpecifiedKeys([FIELDS.CONFIG_ROOT, FIELDS.LOG_FOLDER, FIELDS.LOG_LEVEL ,FIELDS.RULES, FIELDS.ENGINES]); | ||
| const config: TopLevelConfig = { | ||
| config_root: configRoot, | ||
|
|
@@ -145,6 +148,7 @@ export class CodeAnalyzerConfig { | |
| custom_engine_plugin_modules: configExtractor.extractArray(FIELDS.CUSTOM_ENGINE_PLUGIN_MODULES, | ||
| engApi.ValueValidator.validateString, | ||
| DEFAULT_CONFIG.custom_engine_plugin_modules)!, | ||
| preserve_all_working_directories: configExtractor.extractBoolean(FIELDS.PRESERVE_ALL_WORKING_DIRECTORIES, DEFAULT_CONFIG.preserve_all_working_directories)!, | ||
| rules: extractRulesValue(configExtractor), | ||
| engines: extractEnginesValue(configExtractor) | ||
| } | ||
|
|
@@ -226,6 +230,14 @@ export class CodeAnalyzerConfig { | |
| return this.config.custom_engine_plugin_modules; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a boolean indicating whether working directories should be preserved even if their engine succeeds, as opposed | ||
| * to being kept only for failed engines. | ||
|
||
| */ | ||
| public getPreserveAllWorkingDirectories(): boolean { | ||
| return this.config.preserve_all_working_directories; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a {@link RuleOverrides} instance containing the user specified overrides for all rules associated with the specified engine | ||
| * @param engineName name of the engine | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
this.tempFolder.markToBeKept(runWorkingFolderName);isn't needed. Line 330 already marks the subfolders as kept and therefore the parent folder (runWorkingFolderName) is already kept by the way the temp folder preserves parents.I'm on the fence about needing a single debug message. We could just debug each engine folder instead to keep a log code simple with the log being below line 330. But I see the motivation here - to have a single log for all things under the run folder.