Skip to content

Commit

Permalink
markdownlint script updates (#38855)
Browse files Browse the repository at this point in the history
Co-authored-by: Grace Park <[email protected]>
  • Loading branch information
rachmari and gracepark authored Jul 12, 2023
1 parent ac68047 commit f2b5c53
Show file tree
Hide file tree
Showing 12 changed files with 627 additions and 322 deletions.
503 changes: 310 additions & 193 deletions package-lock.json

Large diffs are not rendered by default.

61 changes: 31 additions & 30 deletions src/content-linter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,38 @@

We are using the [markdownlint](https://github.com/DavidAnson/markdownlint) framework to implement custom and existing markdown linter rules to check the markdown content in our `content` and `data` directory files. Here is the list of our current rules implemented in our [markdownlint.js script](./scripts/markdownlint.js):

| **Rule ID** | **Description** | **Severity** |
Each rule listed below is configured in a src/content-linter/style file, which is where the rule's severity is defined. The goal is to get to a point where all rules have a severity of `error` and we can set them to `warning` until the occurrences are handled in the content.

| **Rule ID** | **Description** |
|---|---|---|
| [MD001](https://github.com/DavidAnson/markdownlint/blob/main/doc/md001.md) | Header levels can only increments by one level at a time. | error |
| [MD002](https://github.com/DavidAnson/markdownlint/blob/main/doc/md002.md) | Ensure that headings start with an H2 heading. | error |
| [MD004](https://github.com/DavidAnson/markdownlint/blob/main/doc/md004.md) | Unordered list style must be a dash. | error |
| [MD009](https://github.com/DavidAnson/markdownlint/blob/main/doc/md009.md) | No unnecessary whitespace from the end of the line. | warning |
| [MD012](https://github.com/DavidAnson/markdownlint/blob/main/doc/md012.md) | No unnecessary blank lines. | warning |
| [MD014](https://github.com/DavidAnson/markdownlint/blob/main/doc/md014.md) | Dollar signs should not be used before commands without showing output. | error |
| [MD018](https://github.com/DavidAnson/markdownlint/blob/main/doc/md018.md) | Must have one space after a hash style heading. | error |
| [MD019](https://github.com/DavidAnson/markdownlint/blob/main/doc/md019.md) | Must not have spaces after a hash style heading. | error |
| [MD022](https://github.com/DavidAnson/markdownlint/blob/main/doc/md022.md) | Headings must be surrounded by a blank line. | warning |
| [MD023](https://github.com/DavidAnson/markdownlint/blob/main/doc/md023.md) | Headings must start at the beginning of the line. | error |
| [MD024](https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md) | Disallow headings with the same content. | error |
| [MD027](https://github.com/DavidAnson/markdownlint/blob/main/doc/md027.md) | Catches multiple spaces after blockquote symbol. | warning |
| [MD029](https://github.com/DavidAnson/markdownlint/blob/main/doc/md029.md) | All ordered lists should be prefixed with `1.`. | error |
| [MD030](https://github.com/DavidAnson/markdownlint/blob/main/doc/md030.md) | Only allow one space after list markers. | error |
| [MD031](https://github.com/DavidAnson/markdownlint/blob/main/doc/md031.md) | Fenced code blocks must be surrounded by blank lines. | warning |
| [MD037](https://github.com/DavidAnson/markdownlint/blob/main/doc/md037.md) | Remove extra spacing inside emphasis markers. | warning |
| [MD039](https://github.com/DavidAnson/markdownlint/blob/main/doc/md039.md) | Remove spacing around image text. | warning |
| [MD040](https://github.com/DavidAnson/markdownlint/blob/main/doc/md040.md) | Code fences must have a language specified. | warning |
| [MD042](https://github.com/DavidAnson/markdownlint/blob/main/doc/md042.md) | Do not allow empty links. | error |
| [MD047](https://github.com/DavidAnson/markdownlint/blob/main/doc/md047.md) | All files should end with a new line character. | warning |
| [MD049](https://github.com/DavidAnson/markdownlint/blob/main/doc/md049.md) | All emphasis styling should use underscores. | warning |
| [MD050](https://github.com/DavidAnson/markdownlint/blob/main/doc/md050.md) | All strong styling should use asterisks. | warning |
| [MD011](https://github.com/DavidAnson/markdownlint/blob/main/doc/md011.md) | Make sure that link syntax is not reversed. | error |
| [MD111](./linting-rules/image-alt-text-length.js) | Images alternate text should be between 40-150 characters. | warning |
| [MD112](./linting-rules/image-alt-text-end-punctuation.js) | Images alternate text should end with a punctuation. | error |
| [MD113](./linting-rules/internal-links-slash.js) | Internal links must start with a `/`. | error |
| [MD114](./linting-rules/internal-links-lang.js) | Internal links must not have a hardcoded language code. | error |
| [MD115](./linting-rules/image-file-kebab.js) | Image file names should be lowercase kebab case. | error |
| [MD117](./linting-rules/code-fence-line-length.js) | Code fence content should be 60 lines or less in length. | warning |
| [MD001](https://github.com/DavidAnson/markdownlint/blob/main/doc/md001.md) | Header levels can only increments by one level at a time. |
| [MD002](https://github.com/DavidAnson/markdownlint/blob/main/doc/md002.md) | Ensure that headings start with an H2 heading. |
| [MD004](https://github.com/DavidAnson/markdownlint/blob/main/doc/md004.md) | Unordered list style must be a dash. |
| [MD009](https://github.com/DavidAnson/markdownlint/blob/main/doc/md009.md) | No unnecessary whitespace from the end of the line. |
| [MD012](https://github.com/DavidAnson/markdownlint/blob/main/doc/md012.md) | No unnecessary blank lines. |
| [MD014](https://github.com/DavidAnson/markdownlint/blob/main/doc/md014.md) | Dollar signs should not be used before commands without showing output. |
| [MD018](https://github.com/DavidAnson/markdownlint/blob/main/doc/md018.md) | Must have one space after a hash style heading. |
| [MD019](https://github.com/DavidAnson/markdownlint/blob/main/doc/md019.md) | Must not have spaces after a hash style heading. |
| [MD022](https://github.com/DavidAnson/markdownlint/blob/main/doc/md022.md) | Headings must be surrounded by a blank line. |
| [MD023](https://github.com/DavidAnson/markdownlint/blob/main/doc/md023.md) | Headings must start at the beginning of the line. |
| [MD027](https://github.com/DavidAnson/markdownlint/blob/main/doc/md027.md) | Catches multiple spaces after blockquote symbol. |
| [MD029](https://github.com/DavidAnson/markdownlint/blob/main/doc/md029.md) | All ordered lists should be prefixed with `1.`. |
| [MD030](https://github.com/DavidAnson/markdownlint/blob/main/doc/md030.md) | Only allow one space after list markers. |
| [MD031](https://github.com/DavidAnson/markdownlint/blob/main/doc/md031.md) | Fenced code blocks must be surrounded by blank lines. |
| [MD037](https://github.com/DavidAnson/markdownlint/blob/main/doc/md037.md) | Remove extra spacing inside emphasis markers. |
| [MD039](https://github.com/DavidAnson/markdownlint/blob/main/doc/md039.md) | Remove spacing around image text. |
| [MD040](https://github.com/DavidAnson/markdownlint/blob/main/doc/md040.md) | Code fences must have a language specified. |
| [MD042](https://github.com/DavidAnson/markdownlint/blob/main/doc/md042.md) | Do not allow empty links. |
| [MD047](https://github.com/DavidAnson/markdownlint/blob/main/doc/md047.md) | All files should end with a new line character. |
| [MD049](https://github.com/DavidAnson/markdownlint/blob/main/doc/md049.md) | All emphasis styling should use underscores. |
| [MD050](https://github.com/DavidAnson/markdownlint/blob/main/doc/md050.md) | All strong styling should use asterisks. |
| [MD011](https://github.com/DavidAnson/markdownlint/blob/main/doc/md011.md) | Make sure that link syntax is not reversed. |
| [GHD001](./linting-rules/code-fence-line-length.js) | Code fence content should be 60 lines or less in length. |
| [GHD002](./linting-rules/image-alt-text-end-punctuation.js) | Images alternate text should end with a punctuation. |
| [GHD003](./linting-rules/image-alt-text-length.js) | Images alternate text should be between 40-150 characters. |
| [GHD004](./linting-rules/internal-links-slash.js) | Internal links must start with a `/`. |
| [GHD005](./linting-rules/internal-links-lang.js) | Internal links must not have a hardcoded language code. |
| [GHD006](./linting-rules/image-file-kebab.js) | Image file names should be lowercase kebab case. |

## Linting Tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { addError } from 'markdownlint-rule-helpers'
import { getCodeFenceTokens, getCodeFenceLines } from '../markdownlint-helpers.js'

export const codeFenceLineLength = {
names: ['MD117', 'code-fence-line-length'],
names: ['GHD001', 'code-fence-line-length'],
description: 'Code fence lines should not exceed a maximum length',
tags: ['code'],
severity: 'warning',
function: function MD117(params, onError) {
function: function GHD001(params, onError) {
const MAX_LINE_LENGTH = String(params.config.maxLength || 60)
const codeFenceTokens = getCodeFenceTokens(params)
codeFenceTokens.forEach((token) => {
Expand All @@ -24,7 +24,6 @@ export const codeFenceLineLength = {
`Code fence line exceeds ${MAX_LINE_LENGTH} characters.`,
undefined, // N/A
undefined, // N/A
undefined, // N/A
)
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { addError, forEachInlineChild } from 'markdownlint-rule-helpers'

export const imageAltTextEndPunctuation = {
names: ['MD112', 'image-alt-text-end-punctuation'],
names: ['GHD002', 'image-alt-text-end-punctuation'],
description: 'Images alternate text should end with a punctuation.',
severity: 'error',
tags: ['accessibility', 'images'],
function: function MD112(params, onError) {
function: function GHD003(params, onError) {
forEachInlineChild(params, 'image', function forToken(token) {
const quoteRegex = /[.?!]['"]$/
const endRegex = /[.?!]$/
Expand Down
4 changes: 2 additions & 2 deletions src/content-linter/lib/linting-rules/image-alt-text-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { addError, forEachInlineChild } from 'markdownlint-rule-helpers'
import { liquid } from '#src/content-render/index.js'

export const incorrectAltTextLength = {
names: ['MD111', 'incorrect-alt-text-length'],
names: ['GHD003', 'incorrect-alt-text-length'],
severity: 'warning',
description: 'Images alternate text should be between 40-150 characters',
tags: ['accessibility', 'images'],
function: function MD111(params, onError) {
function: function GHD004(params, onError) {
forEachInlineChild(params, 'image', async function forToken(token) {
let renderedString = token.content
if (token.content.includes('{%') || token.content.includes('{{')) {
Expand Down
6 changes: 3 additions & 3 deletions src/content-linter/lib/linting-rules/image-file-kebab.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { addError, forEachInlineChild } from 'markdownlint-rule-helpers'

export const imageFileKebab = {
names: ['MD115', 'image-file-kebab'],
names: ['GHD004', 'image-file-kebab'],
description: 'Image file names should always be lowercase kebab case',
severity: 'PLACEHOLDER',
severity: 'warning',
tags: ['accessibility', 'images'],
function: function MD115(params, onError) {
function: function GHD005(params, onError) {
forEachInlineChild(params, 'image', async function forToken(token) {
const imageFileName = token.attrs[0][1].split('/').pop().split('.')[0]
const nonKebabRegex = /([A-Z]|_)/
Expand Down
17 changes: 17 additions & 0 deletions src/content-linter/lib/linting-rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { codeFenceLineLength } from './code-fence-line-length.js'
import { imageAltTextEndPunctuation } from './image-alt-text-end-punctuation.js'
import { imageFileKebab } from './image-file-kebab.js'
import { incorrectAltTextLength } from './image-alt-text-length.js'
import { internalLinksLang } from './internal-links-lang.js'
import { internalLinksSlash } from './internal-links-slash.js'

export const gitHubDocsMarkdownlint = {
rules: [
codeFenceLineLength,
imageAltTextEndPunctuation,
imageFileKebab,
incorrectAltTextLength,
internalLinksLang,
internalLinksSlash,
],
}
4 changes: 2 additions & 2 deletions src/content-linter/lib/linting-rules/internal-links-lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { addError, filterTokens } from 'markdownlint-rule-helpers'
import { languageKeys } from '../../../../lib/languages.js'

export const internalLinksLang = {
names: ['MD114', 'internal-links-lang'],
names: ['GHD005', 'internal-links-lang'],
description: 'Internal links must not have a hardcoded language code',
severity: 'error',
tags: ['links', 'url'],
function: function MD114(params, onError) {
function: function GHD006(params, onError) {
filterTokens(params, 'inline', (token) => {
let linkHref = ''
let internalLinkHasLang = false
Expand Down
4 changes: 2 additions & 2 deletions src/content-linter/lib/linting-rules/internal-links-slash.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { addError, filterTokens } from 'markdownlint-rule-helpers'

export const internalLinksSlash = {
names: ['MD113', 'internal-links-slash'],
names: ['GHD006', 'internal-links-slash'],
description: 'Internal links must start with a /',
severity: 'error',
tags: ['links', 'url'],
function: function MD113(params, onError) {
function: function GHD007(params, onError) {
filterTokens(params, 'inline', (token) => {
let linkHref = ''
let internalLinkHasSlash = true
Expand Down
Loading

0 comments on commit f2b5c53

Please sign in to comment.