Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 7 additions & 4 deletions _linter/markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const markdownlint = require("markdownlint");
const glob = require("glob");
const fs = require('fs');
const YAML = require('yaml');
const ruleURLs = {
'hc': 'https://github.com/arduino/help-center-content/blob/main/_linter/markdownlint/Rules.md',
'md': 'https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md'
};

// Get markdown file paths
let files = glob.sync('content/**/*.md');
Expand All @@ -14,9 +18,6 @@ const customRules = require('./markdownlint/rules/rules.js');
const configJSON = fs.readFileSync('./_linter/markdownlint.yml', 'utf8')
const configYAML = YAML.parse(configJSON);

// treeify
const treeify = require("treeify");

const options = {
"config": configYAML,
"files": files,
Expand Down Expand Up @@ -93,8 +94,10 @@ markdownlint(options, function callback(err, result) {
errorLines += getErrorMessage(error) + '\n';

// make rule violation row
const anchor = error.ruleNames[0].toLowerCase();
const URL = ruleURLs[anchor.substring(0,2)];
violatedRules.add(
error.ruleNames[0] + ': ' + error.ruleInformation
error.ruleNames[0] + ': ' + URL + '#' + anchor
);

errorCount++;
Expand Down
1 change: 1 addition & 0 deletions _linter/markdownlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ HC005:
- labels
HC006:
title_line_length: 124
HC008: true
19 changes: 19 additions & 0 deletions _linter/markdownlint/Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,22 @@ title: "Example title"

### Level 3 heading
```

<a name="hc008"></a>

## HC008 - Filename should match title

Tags: filenames

Aliases: filename-match

Enforces a filename standard based on the article title.

Starting with the article title, the filename is determined by following these steps:

1. Remove all single quotes `'` and double quotes `"`
2. Convert all sequences (1 or more) of non-alphanumeric characters to a single dash `-`
3. Remove any leading or trailing dash `-`
4. Append the `.md` extension

Resolve the error by renaming the file to the expected filename.
46 changes: 0 additions & 46 deletions _linter/markdownlint/rules/Rules.md

This file was deleted.

37 changes: 37 additions & 0 deletions _linter/markdownlint/rules/hc008.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @ts-check

"use strict";

const markdownlintRulesDir = "../..//node_modules/markdownlint/lib/";
const { addErrorDetailIf, filterTokens, frontMatterHasTitle } = require(markdownlintRulesDir + "../helpers");

const path = require("path");

module.exports = {
"names": [ "HC008", "filename-match" ],
"description": "Filename should match title",
"tags": [ "titles" ],
"function": function HC008(params, onError) {
const filename = path.basename(params.name);

const foundFrontMatterTitle =
frontMatterHasTitle(
params.frontMatterLines,
params.config.front_matter_title
);

if (foundFrontMatterTitle) {
const title = params.frontMatterLines.find(a =>a.includes("title: ")).substring(7);

const expectedFilename = title //sanitize(title)
.replace(/['"]+/g, '')
.replace(/[^A-Za-z0-9]+/g, '-')
.replace(/-$/, '') + '.md';
if (filename != expectedFilename) {
addErrorDetailIf(onError, 1,
filename, expectedFilename, null, "Expected: " + expectedFilename
+ "; Actual: " + filename);
}
}
}
};
3 changes: 2 additions & 1 deletion _linter/markdownlint/rules/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const rules = [
require("./hc004"),
require("./hc005"),
require("./hc006"),
require("./hc007")
require("./hc007"),
require("./hc008")
];

rules.forEach((rule) => {
Expand Down
195 changes: 176 additions & 19 deletions _linter/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading