| import { addError } from 'markdownlint-rule-helpers' |
| import type { RuleParams, RuleErrorCallback } from '../../types' |
|
|
| import { getFrontmatter } from '../helpers/utils' |
|
|
| export const frontmatterHiddenDocs = { |
| names: ['GHD010', 'frontmatter-hidden-docs'], |
| description: |
| 'Articles with frontmatter property `hidden` can only be located in specific products', |
| tags: ['frontmatter', 'feature', 'early-access'], |
| function: (params: RuleParams, onError: RuleErrorCallback) => { |
| const fm = getFrontmatter(params.lines) |
| if (!fm || !fm.hidden) return |
|
|
| |
| if (fm.hasExperimentalAlternative) return |
|
|
| |
| const allowedProductPaths = [ |
| 'content/early-access', |
| 'content/site-policy', |
| 'content/search', |
| 'content/video-transcripts', |
| ] |
|
|
| if (allowedProductPaths.some((allowedPath) => params.name.includes(allowedPath))) return |
|
|
| const hiddenLine = params.lines.find((line: string) => line.startsWith('hidden:')) |
| if (!hiddenLine) return |
| const lineNumber = params.lines.indexOf(hiddenLine) + 1 |
|
|
| addError( |
| onError, |
| lineNumber, |
| `The 'hidden' frontmatter property is only allowed in these directories: ${allowedProductPaths.join( |
| ', ', |
| )}`, |
| hiddenLine, |
| [1, hiddenLine.length], |
| null, |
| ) |
| }, |
| } |
|
|