Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tabs_title_markup.js « rules « .markdownlint « doc - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9c1de1e630d7750a832c5cfb96f17e70dfdec00f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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}`,
        });
      }
    });
  },
};