Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot
2022-10-31 09:09:32 +00:00
parent 853c0c530b
commit 5025412fc4
41 changed files with 729 additions and 472 deletions

View File

@ -0,0 +1,14 @@
/**
* Look up the global node modules directory.
*
* Because we install markdownlint packages globally
* in the Docker image where this runs, we need to
* provide the path to the global install location
* when referencing global functions from our own node
* modules.
*
* Image:
* https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/dockerfiles/gitlab-docs-lint-markdown.Dockerfile
*/
const { execSync } = require('child_process');
module.exports.globalPath = execSync('yarn global dir').toString().trim() + '/node_modules/';

View File

@ -0,0 +1,26 @@
const { globalPath } = require('../require_helper');
const {
forEachLine,
getLineMetadata,
isBlankLine,
} = require(`${globalPath}/markdownlint-rule-helpers`);
module.exports = {
names: ['tabs-blank-lines'],
description: 'Tab elements must be surrounded by blank lines',
tags: ['gitlab-docs', 'tabs'],
function: (params, onError) => {
const tabElements = ['::Tabs', '::EndTabs', ':::TabTitle'];
forEachLine(getLineMetadata(params), (line, lineIndex) => {
const lineHasTab = tabElements.includes(line.split(' ')[0]);
const prevLine = params.lines[lineIndex - 1];
const nextLine = params.lines[lineIndex + 1];
if (lineHasTab && (!isBlankLine(prevLine) || !isBlankLine(nextLine))) {
onError({
lineNumber: lineIndex + 1,
});
}
});
},
};

View File

@ -0,0 +1,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}`,
});
}
});
},
};

View File

@ -0,0 +1,23 @@
const { globalPath } = require('../require_helper');
const {
forEachLine,
getLineMetadata,
isBlankLine,
} = require(`${globalPath}/markdownlint-rule-helpers`);
module.exports = {
names: ['tabs-title-text'],
description: 'Tab without title text',
information: new URL('https://docs.gitlab.com/ee/development/documentation/styleguide/#tabs'),
tags: ['gitlab-docs', 'tabs'],
function: (params, onError) => {
forEachLine(getLineMetadata(params), (line, lineIndex) => {
if (!isBlankLine(line) && line.replace(':::TabTitle', '').trim() === '') {
onError({
lineNumber: lineIndex + 1,
detail: 'Expected: :::TabTitle <your title here>; Actual: :::TabTitle',
});
}
});
},
};

View File

@ -0,0 +1,21 @@
module.exports = {
names: ['tabs-wrapper-tags'],
description: 'Unequal number of tab start and end tags',
information: new URL('https://docs.gitlab.com/ee/development/documentation/styleguide/#tabs'),
tags: ['gitlab-docs', 'tabs'],
function: function rule(params, onError) {
const tabStarts = params.lines.filter((line) => line === '::Tabs');
const tabEnds = params.lines.filter((line) => line === '::EndTabs');
if (tabStarts.length !== tabEnds.length) {
const errorIndex =
params.lines.indexOf('::Tabs') > 0
? params.lines.indexOf('::Tabs')
: params.lines.indexOf('::EndTabs');
onError({
lineNumber: errorIndex + 1,
detail: `Opening tags: ${tabStarts.length}; Closing tags: ${tabEnds.length}`,
});
}
},
};