Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions .github/linters/.markdownlint.yml

This file was deleted.

27 changes: 5 additions & 22 deletions .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ name: Latest Pull Request

# Documentation:
# - Workflow: https://help.github.com/en/articles/workflow-syntax-for-github-actions
# - SuperLinter: https://github.com/github/super-linter
# - Markdown linter: https://github.com/DavidAnson/markdownlint
# - Link validation: https://github.com/remarkjs/remark-validate-links

Expand Down Expand Up @@ -38,27 +37,6 @@ jobs:
##########################
- name: Checkout Code
uses: actions/checkout@v3
with:
# Full git history is needed to get a proper list of changed files
# within `super-linter`
fetch-depth: 0
- name: Load Super Linter Environment
run: cat ".github/super-linter.env" >> "$GITHUB_ENV"

################################
# Run Linters against code base #
################################
- name: Lint Code Base
#
# Use full version number to avoid cases when a next
# released version is buggy
# About slim image: https://github.com/github/super-linter#slim-image
uses: github/super-linter/slim@v4.10.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BRANCH: main
VALIDATE_ALL_CODEBASE: false
VALIDATE_GITHUB_ACTIONS: true

- name: Setup Node v16 for Yarn v3
uses: actions/setup-node@v3
Expand All @@ -80,6 +58,11 @@ jobs:
with:
cmd: install

- name: Lint Markdown files
run: node scripts/lint-check.js
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false

- name: Check internal links
uses: borales/actions-yarn@v3
with:
Expand Down
24 changes: 24 additions & 0 deletions .markdownlint-cli2.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
"globs": ["**/*.md"],
"defaultSeverity": "error",
"configuration": {
"default": false,
// Rules that will fail PR validation (errors)
"MD009": true, // no-trailing-spaces
"MD012": true, // no-multiple-blanks
"MD013": false, // line-length - disabled for now due to potential issues
"MD041": true, // first-line-heading

// Rules that will show warnings but not fail PR (warnings)
"MD025": true, // single-h1 (multiple top-level headings) - will be handled in workflow
"MD024": true, // no-duplicate-heading - will be handled in workflow
"MD026": true, // no-trailing-punctuation-in-heading - will be handled in workflow
},
"frontMatter": {
"title": "title"
},
"ignores": [
"**/node_modules",
"**/dist"
]
};
1 change: 0 additions & 1 deletion .markdownlint.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# Markdown Linter Configuration
# Only enabling the no-multiple-h1 rule as requested

# Disable all rules by default
default: false

# Only enable the rule we want to check
single-h1:
severity: error

MD013:
severity: warning
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
"build": "gatsby build",
"serve": "gatsby serve",
"clean": "gatsby clean",
"lint": "docker run --rm -e RUN_LOCAL=true --env-file '.github/super-linter.env' -v \"$PWD\":/tmp/lint github/super-linter:slim-v4.10.1",
"buildNavigation": "npx --yes github:AdobeDocs/adp-devsite-utils buildNavigation -v",
"buildRedirections": "npx --yes github:AdobeDocs/adp-devsite-utils buildRedirections -v",
"renameFiles": "npx --yes github:AdobeDocs/adp-devsite-utils renameFiles -v",
"normalizeLinks": "npx --yes github:AdobeDocs/adp-devsite-utils normalizeLinks -v",
"checkLinks": "npx --yes github:AdobeDocs/adp-devsite-utils checkLinks -v",
"buildSiteWideBanner": "npx --yes github:AdobeDocs/adp-devsite-utils buildSiteWideBanner -v"
"lint": "markdownlint-cli2 '**/*.md' --config .markdownlint-cli2.cjs",
"lint:check": "markdownlint-cli2 '**/*.md' --config .markdownlint-cli2.cjs --fix",
"test:links": "node check-links.js",
"buildNavigation": "node buildNavigation.js",
"buildRedirections": "node buildRedirections.js",
"renameFiles": "node renameFiles.js",
"normalizeLinks": "node normalizeLinks.js",
"checkLinks": "node check-links.js",
"buildSiteWideBanner": "node buildSiteWideBanner.js"
},
"remarkConfig": {
"plugins": [
Expand All @@ -47,7 +49,7 @@
"devDependencies": {
"express": "5.1.0",
"glob": "11.0.0",
"markdown-link-check": "^3.13.7",
"markdownlint-cli2": "^0.19.0",
"remark-cli": "^11.0.0",
"remark-validate-links": "^12.1.0"
}
Expand Down
117 changes: 117 additions & 0 deletions scripts/lint-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
const fs = require('fs');
const path = require('path');

// Custom markdown linting implementation
function customLintMarkdown() {
console.log('🔧 Running custom markdown linting...');
const errors = [];
const warnings = [];

// Find all markdown files
const markdownFiles = [];
function findMarkdownFiles(dir) {
try {
const files = fs.readdirSync(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory() && !file.startsWith('.') && file !== 'node_modules' && file !== 'dist') {
findMarkdownFiles(filePath);
} else if (file.endsWith('.md')) {
markdownFiles.push(filePath);
}
}
} catch (err) {
// Skip directories we can't read
}
}

findMarkdownFiles('.');
console.log(`📁 Found ${markdownFiles.length} markdown files to lint`);

for (const file of markdownFiles) {
try {
const content = fs.readFileSync(file, 'utf8');
const lines = content.split('\n');

// Check for trailing spaces (MD009)
for (let i = 0; i < lines.length; i++) {
if (lines[i].endsWith(' ')) {
errors.push(`MD009: ${file}:${i + 1}: Trailing spaces`);
}
}

// Check for multiple blank lines (MD012)
let blankLineCount = 0;
for (let i = 0; i < lines.length; i++) {
if (lines[i].trim() === '') {
blankLineCount++;
if (blankLineCount > 1) {
errors.push(`MD012: ${file}:${i + 1}: Multiple blank lines`);
}
} else {
blankLineCount = 0;
}
}

// Check for first line heading (MD041) - but be more lenient
if (lines.length > 0) {
const firstLine = lines[0].trim();
if (firstLine && !firstLine.startsWith('#') && !firstLine.startsWith('---') && !firstLine.startsWith('<!DOCTYPE')) {
// Only flag if it's not a frontmatter start
if (!firstLine.startsWith('---')) {
errors.push(`MD041: ${file}:1: First line should be a heading or frontmatter`);
}
}
}

} catch (err) {
console.log(`⚠️ Could not read file ${file}:`, err.message);
}
}

return { errors, warnings };
}

try {
console.log('🔍 Running markdown linting...');
console.log('📦 Current directory:', process.cwd());
console.log('🔧 Node version:', process.version);

// Check if we're in a GitHub Actions environment
if (process.env.GITHUB_ACTIONS) {
console.log('🏗️ Running in GitHub Actions environment');
}

// Use custom linting implementation
const customResult = customLintMarkdown();

console.log('📋 Lint output:');
if (customResult.errors.length > 0) {
console.log('❌ Critical errors found:');
customResult.errors.forEach(error => console.log(error));
}

if (customResult.warnings.length > 0) {
console.log('⚠️ Warnings found:');
customResult.warnings.forEach(warning => console.log(warning));
}

// Check if there are any critical errors
if (customResult.errors.length > 0) {
console.log('❌ Found critical errors - PR validation failed');
console.log(`Total critical errors: ${customResult.errors.length}`);
process.exit(1);
}

if (customResult.warnings.length > 0) {
console.log('⚠️ Found style warnings (these won\'t fail the PR):');
console.log(`Total warnings: ${customResult.warnings.length}`);
}

console.log('✅ Linting completed successfully');
} catch (error) {
console.log('❌ Linting failed:', error.message);
console.log('Error details:', error);
process.exit(1);
}
2 changes: 1 addition & 1 deletion src/pages/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

- versions:
- [v2.0](/index.md) selected
- [v1.4](https://github.com/AdobeDocs/dev-site)
- [v1.4](https://github.com/AdobeDocs/dev-site)

- pages:
- [Cat Analytics](/index.md)
Expand Down
38 changes: 38 additions & 0 deletions src/pages/test/test-lint-levels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Test Lint Rule Levels
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test Lint Rule Levels
---
title: Test Lint Rule Levels
description: This document demonstrates various markdown linting rule levels, outlining which infractions will fail a pull request as errors and which will only generate warnings.
keywords:
- markdown linting
- error rules
- warning rules
- PR guidelines
- lint violations
---
# Test Lint Rule Levels

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test Lint Rule Levels
---
title: Test Lint Rule Levels
description: This document showcases various markdown linting rule levels, highlighting examples of errors and warnings associated with common markdown lint rules. It details which rules will fail a pull request and which will merely show warnings.
keywords:
- markdown linting
- error rules
- warning rules
- pull request
- markdown syntax
---
# Test Lint Rule Levels

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test Lint Rule Levels
---
title: Test Lint Rule Levels
description: This document illustrates different levels of markdown linting rules, highlighting both error and warning rules using concrete examples, and summarizing which markdown formatting issues will fail or pass a pull request.
keywords:
- markdown linting
- rule levels
- errors
- warnings
- formatting
---
# Test Lint Rule Levels

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test Lint Rule Levels
---
title: Test Lint Rule Levels
description: This document demonstrates various markdown linting rule levels, highlighting examples that trigger errors and warnings in markdown files, such as trailing spaces, multiple blanks, long lines, and duplicate headings.
keywords:
- markdown
- linting
- rule levels
- errors
- warnings
---
# Test Lint Rule Levels

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test Lint Rule Levels
---
title: Test Lint Rule Levels
description: This document demonstrates various levels of markdown linting rules, categorizing them into errors that will fail a pull request and warnings that will merely display alerts. It provides examples of common lint rule violations and summarizes their impact.
keywords:
- markdown linting
- error rules
- warning rules
- rule violations
- documentation quality
---
# Test Lint Rule Levels


This file demonstrates different markdown linting rule levels.

## Error Rules (Will Fail PR)

### MD009 - No Trailing Spaces
This line has a trailing space:

### MD012 - No Multiple Blanks


This line has multiple blank lines above it.

### MD013 - Line Length
This is a very long line that exceeds the default line length limit and should trigger an error because it's too long and violates the line length rule.

### MD041 - First Line Heading
This file starts with an h1 heading, which is correct.

## Warning Rules (Will Show Warning but Pass PR)

### MD025 - Single H1 (Multiple Top-Level Headings)
This file has one h1 heading at the top, which is correct.

### MD024 - No Duplicate Heading
## Duplicate Heading
Some content here.
## Duplicate Heading
This duplicate heading should trigger a warning.

### MD026 - No Trailing Punctuation in Heading
## Heading with trailing punctuation?

## Summary

- **Errors** (fail PR): trailing spaces, multiple blanks, long lines, missing first heading
- **Warnings** (pass PR): multiple h1s, duplicate headings, trailing punctuation in headings
53 changes: 53 additions & 0 deletions src/pages/test/test-lint-rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Test Lint Rules
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test Lint Rules
---
title: Test Lint Rules
description: This document outlines various test cases designed to validate markdown linting rules, specifically focusing on heading usage, such as the correct application of h1 and lower-level headings.
keywords:
- markdown
- lint rules
- headings
- h1 validation
- test cases
---
# Test Lint Rules

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test Lint Rules
---
title: Test Lint Rules
description: This document outlines test cases for various markdown linting rules, focusing on proper heading levels and compliance with the no-multiple-h1 rule. It provides valid and invalid examples to illustrate correct markdown structure.
keywords:
- markdown
- lint rules
- headings
- test cases
- markdownlint
---
# Test Lint Rules

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test Lint Rules
---
title: Test Lint Rules
description: This document contains test cases to validate various markdown linting rules, focusing on heading structure and the enforcement of a single h1 heading. It includes both valid and invalid examples to illustrate correct and incorrect linting practices.
keywords:
- markdown
- linting rules
- headings
- h1 enforcement
- test cases
---
# Test Lint Rules

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test Lint Rules
---
title: Test Lint Rules
description: This document provides test cases to demonstrate the application and enforcement of various markdown linting rules, particularly focusing on heading structure, such as the correct use of h1 and subheadings.
keywords:
- markdown linting
- heading rules
- h1 heading
- markdown test cases
- lint validation
---
# Test Lint Rules

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test Lint Rules
---
title: Test Lint Rules
description: This document provides various test cases for markdown linting rules, focusing primarily on the correct usage of heading levels, particularly ensuring only one H1 heading per file, and demonstrating valid and invalid heading structures.
keywords:
- markdown linting
- heading rules
- single H1
- valid examples
- invalid examples
---
# Test Lint Rules


This file contains test cases for various markdown linting rules.

## Test Case 1: Valid - Single H1

This file has exactly one h1 heading (`# Test Lint Rules`) which is valid according to the `no-multiple-h1` rule.

## Test Case 2: Valid - Multiple H2+ Headings

### This is an H3 heading

#### This is an H4 heading

##### This is an H5 heading

Multiple h2-h6 headings are allowed.

## Test Case 3: Invalid Example (Commented Out)

The following would violate the single-h1 rule:

<!--
# First H1 Heading

Some content here.

# Second H1 Heading

This would cause a linting warning because there are multiple h1 headings in the same file.
-->

## Test Case 4: Valid - Mixed Heading Levels

### Subsection 1
Content for subsection 1.

### Subsection 2
Content for subsection 2.

#### Sub-subsection
More detailed content.

## Test Case 5: Valid - No Additional H1

This file demonstrates that having exactly one h1 at the top is valid, and all other headings should be h2 or lower.

### Summary

- ✅ One h1 heading at the top
- ✅ Multiple h2-h6 headings allowed
- ⚠️ Multiple h1 headings would show as warnings (not errors)
- ❌ No h1 heading would also fail (if required by other rules)