MCPcopy Create free account
hub / github.com/conventional-changelog/commitlint / getEditValue

Function getEditValue

@commitlint/cli/src/cli.ts:446–487  ·  view source on GitHub ↗
(flags: CliFlags)

Source from the content-addressed store, hash-verified

444}
445
446function getEditValue(flags: CliFlags) {
447 if (flags.env) {
448 if (!(flags.env in process.env)) {
449 throw new Error(
450 `Received '${flags.env}' as value for -E | --env, but environment variable '${flags.env}' is not available globally`,
451 );
452 }
453 return process.env[flags.env];
454 }
455 const { edit } = flags;
456 // If the edit flag is set but empty (i.e '-e') we default
457 // to .git/COMMIT_EDITMSG
458 if (edit === "") {
459 return true;
460 }
461 if (typeof edit === "boolean") {
462 return edit;
463 }
464 // The recommended method to specify -e with husky was `commitlint -e $HUSKY_GIT_PARAMS`
465 // This does not work properly with win32 systems, where env variable declarations
466 // use a different syntax
467 // See https://github.com/conventional-changelog/commitlint/issues/103 for details
468 // This has been superseded by the `-E GIT_PARAMS` / `-E HUSKY_GIT_PARAMS`
469 const isGitParams = edit === "$GIT_PARAMS" || edit === "%GIT_PARAMS%";
470 const isHuskyParams = edit === "$HUSKY_GIT_PARAMS" || edit === "%HUSKY_GIT_PARAMS%";
471
472 if (isGitParams || isHuskyParams) {
473 console.warn(`Using environment variable syntax (${edit}) in -e |\
474--edit is deprecated. Use '{-E|--env} HUSKY_GIT_PARAMS instead'`);
475
476 if (isGitParams && "GIT_PARAMS" in process.env) {
477 return process.env.GIT_PARAMS;
478 }
479 if ("HUSKY_GIT_PARAMS" in process.env) {
480 return process.env.HUSKY_GIT_PARAMS;
481 }
482 throw new Error(
483 `Received ${edit} as value for -e | --edit, but GIT_PARAMS or HUSKY_GIT_PARAMS are not available globally.`,
484 );
485 }
486 return edit;
487}
488
489async function loadConfig(flags: CliFlags): Promise<QualifiedConfig> {
490 const loaded = await load(getSeed(flags), {

Callers 1

normalizeFlagsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected