Add Folder Trust Support To Hooks (#15325)

This commit is contained in:
Sehoon Shon
2025-12-22 11:46:38 -05:00
committed by GitHub
parent d6a2f1d670
commit dced409ac4
10 changed files with 188 additions and 23 deletions
+11 -12
View File
@@ -6,19 +6,9 @@
import type { Config } from '../config/config.js';
import type { HookDefinition, HookConfig } from './types.js';
import { HookEventName } from './types.js';
import { HookEventName, ConfigSource } from './types.js';
import { debugLogger } from '../utils/debugLogger.js';
/**
* Configuration source levels in precedence order (highest to lowest)
*/
export enum ConfigSource {
Project = 'project',
User = 'user',
System = 'system',
Extensions = 'extensions',
}
/**
* Hook registry entry with source information
*/
@@ -111,7 +101,13 @@ export class HookRegistry {
// Get hooks from the main config (this comes from the merged settings)
const configHooks = this.config.getHooks();
if (configHooks) {
this.processHooksConfiguration(configHooks, ConfigSource.Project);
if (this.config.isTrustedFolder()) {
this.processHooksConfiguration(configHooks, ConfigSource.Project);
} else {
debugLogger.warn(
'Project hooks disabled because the folder is not trusted.',
);
}
}
// Get hooks from extensions
@@ -189,6 +185,9 @@ export class HookRegistry {
} as HookRegistryEntry);
const isDisabled = disabledHooks.includes(hookName);
// Add source to hook config
hookConfig.source = source;
this.entries.push({
config: hookConfig,
source,