fix: skip template lines to avoid parser errors

Fixes #26
This commit is contained in:
Karl-Philipp Wulfert
2019-06-04 15:15:02 +02:00
parent 1252c612f0
commit b995bb5c14

View File

@@ -483,13 +483,28 @@ export function checkContributors(path: PathLike, packageJson: PackageJSON): voi
* @param path Path to CI config * @param path Path to CI config
*/ */
export function checkCIConfig(rules: Rules, path: string): void { export function checkCIConfig(rules: Rules, path: string): void {
// check CI config if it exists
const pathToCiConfig = resolve(path, '.gitlab-ci.yml'); const pathToCiConfig = resolve(path, '.gitlab-ci.yml');
// check CI config if it exists
if (existsSync(pathToCiConfig)) { if (existsSync(pathToCiConfig)) {
// read CI config // read CI config
const buffer = readFileSync(pathToCiConfig); const content = readFileSync(pathToCiConfig)
.toString();
let ciConfigWithoutTemplates = '';
for (const line of content.split('\n')) {
const match = line
.trim()
.match(/^<</);
if (match === null) {
ciConfigWithoutTemplates += `${line}\n`;
}
}
try { try {
const ciConfig = parse(buffer.toString()); const ciConfig = parse(ciConfigWithoutTemplates);
// check entries // check entries
for (const entry in rules.ciConfig) { for (const entry in rules.ciConfig) {