debian-mirror-gitlab/doc/.markdownlint/rules/tabs_title_markup.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-01-13 00:05:48 +05:30
const { globalPath } = require('../require_helper');
const { forEachLine, getLineMetadata } = require(`${globalPath}/markdownlint-rule-helpers`);
module.exports = {
names: ['tabs-title-markup'],
description: 'Incorrect number of colon characters for tag',
information: new URL('https://docs.gitlab.com/ee/development/documentation/styleguide/#tabs'),
tags: ['gitlab-docs', 'tabs'],
function: (params, onError) => {
// Note the correct number of colons in each tab tag type.
const wrapperColons = 2;
const titleColons = 3;
forEachLine(getLineMetadata(params), (line, lineIndex) => {
// Get the number of colons in this line.
const colonCount = [...line].filter((x) => x === ':').length;
// Throw an error in the case of a mismatch.
if (
((line.includes(':Tabs') || line.includes(':EndTabs')) && colonCount !== wrapperColons) ||
(line.includes(':TabTitle') && colonCount !== titleColons)
) {
const correctColonCount = line.includes(':TabTitle') ? wrapperColons : titleColons;
onError({
lineNumber: lineIndex + 1,
detail: `Actual: ${colonCount}; Expected: ${correctColonCount}`,
});
}
});
},
};