mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
dec41b697e
test(manager/terraform): close the terraform family coverage gaps Adds two terraform extractions that no test covered: a lock file that cannot be read, and one that holds no locks. Both leave the deps without a locked version. Marks three guards. The lockfile update path needs a change that also satisfies the recorded constraints, `extractTFLintPlugin()` never returns null, and only terragrunt's already-ignored default case leaves its result unset. Two implicit elses stay counted, in the terraform module extractor and the tflint key parser: a coverage-ignore hint does not attach to an `else if`, so they carry a plain note. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { logger } from '../../../logger/index.ts';
|
|
import { newlineRegex, regEx } from '../../../util/regex.ts';
|
|
import type {
|
|
ExtractConfig,
|
|
PackageDependency,
|
|
PackageFileContent,
|
|
} from '../types.ts';
|
|
import { extractTFLintPlugin } from './plugins.ts';
|
|
import type { ExtractionResult } from './types.ts';
|
|
import { checkFileContainsPlugins } from './util.ts';
|
|
|
|
const dependencyBlockExtractionRegex = regEx(
|
|
/^\s*plugin\s+"(?<pluginName>[^"]+)"\s+{\s*$/,
|
|
);
|
|
|
|
export function extractPackageFile(
|
|
content: string,
|
|
packageFile: string,
|
|
_config: ExtractConfig,
|
|
): PackageFileContent | null {
|
|
logger.trace({ content }, `tflint.extractPackageFile(${packageFile})`);
|
|
if (!checkFileContainsPlugins(content)) {
|
|
logger.debug(
|
|
{ packageFile },
|
|
'preflight content check has not found any relevant content',
|
|
);
|
|
return null;
|
|
}
|
|
|
|
let deps: PackageDependency[] = [];
|
|
|
|
try {
|
|
const lines = content.split(newlineRegex);
|
|
|
|
for (let lineNumber = 0; lineNumber < lines.length; lineNumber += 1) {
|
|
const line = lines[lineNumber];
|
|
const tfLintPlugin = dependencyBlockExtractionRegex.exec(line);
|
|
if (tfLintPlugin?.groups) {
|
|
logger.trace(`Matched TFLint plugin on line ${lineNumber}`);
|
|
let result: ExtractionResult | null = null;
|
|
result = extractTFLintPlugin(
|
|
lineNumber,
|
|
lines,
|
|
tfLintPlugin.groups.pluginName,
|
|
);
|
|
// v8 ignore else -- `extractTFLintPlugin()` always returns a result
|
|
if (result) {
|
|
lineNumber = result.lineNumber;
|
|
deps = deps.concat(result.dependencies);
|
|
result = null;
|
|
}
|
|
}
|
|
}
|
|
} catch (err) /* istanbul ignore next */ {
|
|
logger.debug({ err, packageFile }, 'Error extracting TFLint plugins');
|
|
}
|
|
|
|
return deps.length ? { deps } : null;
|
|
}
|