mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-07-23 00:47:51 +00:00
Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
14
doc/.markdownlint/require_helper.js
Normal file
14
doc/.markdownlint/require_helper.js
Normal 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/';
|
26
doc/.markdownlint/rules/tabs_blank_lines.js
Normal file
26
doc/.markdownlint/rules/tabs_blank_lines.js
Normal 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,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
31
doc/.markdownlint/rules/tabs_title_markup.js
Normal file
31
doc/.markdownlint/rules/tabs_title_markup.js
Normal 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}`,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
23
doc/.markdownlint/rules/tabs_title_text.js
Normal file
23
doc/.markdownlint/rules/tabs_title_text.js
Normal 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',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
21
doc/.markdownlint/rules/tabs_wrapper_tags.js
Normal file
21
doc/.markdownlint/rules/tabs_wrapper_tags.js
Normal 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}`,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user