mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add MD044 proper-names "Proper names should have the correct capitalization" (fixes #39).
This commit is contained in:
parent
46cbcfa55e
commit
d8975282dc
13 changed files with 185 additions and 5 deletions
|
@ -84,6 +84,7 @@ playground for learning and exploring.
|
|||
* **MD041** *first-line-h1* - First line in file should be a top level header
|
||||
* **MD042** *no-empty-links* - No empty links
|
||||
* **MD043** *required-headers* - Required header structure
|
||||
* **MD044** *proper-names* - Proper names should have the correct capitalization
|
||||
|
||||
See [Rules.md](doc/Rules.md) for more details.
|
||||
|
||||
|
@ -107,6 +108,7 @@ See [Rules.md](doc/Rules.md) for more details.
|
|||
* **links** - MD011, MD034, MD039, MD042
|
||||
* **ol** - MD029, MD030, MD032
|
||||
* **spaces** - MD018, MD019, MD020, MD021, MD023
|
||||
* **spelling** - MD044
|
||||
* **ul** - MD004, MD005, MD006, MD007, MD030, MD032
|
||||
* **url** - MD034
|
||||
* **whitespace** - MD009, MD010, MD012, MD027, MD028, MD030, MD037, MD038, MD039
|
||||
|
|
20
doc/Rules.md
20
doc/Rules.md
|
@ -1119,3 +1119,23 @@ problematic header (otherwise, it outputs the last line number of the file).
|
|||
|
||||
Note that while the `headers` parameter uses the "## Text" ATX header style for
|
||||
simplicity, a file may use any supported header style.
|
||||
|
||||
## MD044 - Proper names should have the correct capitalization
|
||||
|
||||
Tags: spelling
|
||||
|
||||
Aliases: proper-names
|
||||
|
||||
Parameters: names (array of string; default `null` for disabled)
|
||||
|
||||
This rule is triggered when any of the strings in the `names` array do not have
|
||||
the specified capitalization. It can be used to enforce a standard letter case
|
||||
for the names of projects and products.
|
||||
|
||||
For example, the language "JavaScript" is usually written with both the 'J' and
|
||||
'S' capitalized - though sometimes the 's' or 'j' appear in lower-case. To enforce
|
||||
the proper capitalization, specify the desired letter case in the `names` array:
|
||||
|
||||
[
|
||||
"JavaScript"
|
||||
]
|
||||
|
|
22
lib/rules.js
22
lib/rules.js
|
@ -1090,5 +1090,27 @@ module.exports = [
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD044",
|
||||
"desc": "Proper names should have the correct capitalization",
|
||||
"tags": [ "spelling" ],
|
||||
"aliases": [ "proper-names" ],
|
||||
"regexp": null,
|
||||
"func": function MD044(params, errors) {
|
||||
var names = params.options.names || [];
|
||||
names.forEach(function forName(name) {
|
||||
var escapedName = escapeForRegExp(name);
|
||||
var namePattern = "\\b" + escapedName + "\\b";
|
||||
var anyNameRe = new RegExp(namePattern, "gi");
|
||||
forEachLine(params, function forLine(line, lineIndex) {
|
||||
var matches = line.match(anyNameRe) || [];
|
||||
matches.forEach(function forMatch(match) {
|
||||
errors.addDetailIf(lineIndex + 1, name, match);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
|
@ -212,6 +212,18 @@ rules.forEach(function forRule(rule) {
|
|||
}
|
||||
};
|
||||
break;
|
||||
case "MD044":
|
||||
scheme.properties = {
|
||||
"names": {
|
||||
"description": "List of proper names",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": null
|
||||
}
|
||||
};
|
||||
break;
|
||||
default:
|
||||
custom = false;
|
||||
break;
|
||||
|
|
|
@ -871,6 +871,44 @@
|
|||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"MD044": {
|
||||
"description": "MD044/proper-names - Proper names should have the correct capitalization",
|
||||
"type": [
|
||||
"boolean",
|
||||
"object"
|
||||
],
|
||||
"default": true,
|
||||
"properties": {
|
||||
"names": {
|
||||
"description": "List of proper names",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": null
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"proper-names": {
|
||||
"description": "MD044/proper-names - Proper names should have the correct capitalization",
|
||||
"type": [
|
||||
"boolean",
|
||||
"object"
|
||||
],
|
||||
"default": true,
|
||||
"properties": {
|
||||
"names": {
|
||||
"description": "List of proper names",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": null
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"headers": {
|
||||
"description": "headers - MD001, MD002, MD003, MD018, MD019, MD020, MD021, MD022, MD023, MD024, MD025, MD026, MD036, MD041, MD043",
|
||||
"type": "boolean",
|
||||
|
@ -970,6 +1008,11 @@
|
|||
"description": "language - MD040",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"spelling": {
|
||||
"description": "spelling - MD044",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
|
|
@ -7,5 +7,10 @@
|
|||
"#### Header 2 {MD001}",
|
||||
"# Broken"
|
||||
]
|
||||
},
|
||||
"MD044": {
|
||||
"names": [
|
||||
"markdownlint"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,3 +75,5 @@ code fence without language {MD040:73}
|
|||
```
|
||||
|
||||
[empty link]() {MD042}
|
||||
|
||||
markdownLint {MD044}
|
||||
|
|
|
@ -5,5 +5,10 @@
|
|||
"headers": [
|
||||
"# Header"
|
||||
]
|
||||
},
|
||||
"MD044": {
|
||||
"names": [
|
||||
"markdownlint"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
Not a header
|
||||
|
||||
An [empty]() link
|
||||
|
||||
This is a test file for the MARKDOWNLINT package.
|
||||
|
|
|
@ -18,12 +18,21 @@
|
|||
"errorRange": [4, 7]
|
||||
},
|
||||
{
|
||||
"lineNumber": 4,
|
||||
"lineNumber": 6,
|
||||
"ruleName": "MD043",
|
||||
"ruleAlias": "required-headers",
|
||||
"ruleDescription": "Required header structure",
|
||||
"errorDetail": null,
|
||||
"errorContext": "# Header",
|
||||
"errorRange": null
|
||||
},
|
||||
{
|
||||
"lineNumber": 5,
|
||||
"ruleName": "MD044",
|
||||
"ruleAlias": "proper-names",
|
||||
"ruleDescription": "Proper names should have the correct capitalization",
|
||||
"errorDetail": "Expected: markdownlint; Actual: MARKDOWNLINT",
|
||||
"errorContext": null,
|
||||
"errorRange": null
|
||||
}
|
||||
]
|
|
@ -905,7 +905,7 @@ module.exports.missingStringValue = function missingStringValue(test) {
|
|||
};
|
||||
|
||||
module.exports.ruleNamesUpperCase = function ruleNamesUpperCase(test) {
|
||||
test.expect(39);
|
||||
test.expect(40);
|
||||
rules.forEach(function forRule(rule) {
|
||||
test.equal(rule.name, rule.name.toUpperCase(), "Rule name not upper-case.");
|
||||
});
|
||||
|
@ -913,7 +913,7 @@ module.exports.ruleNamesUpperCase = function ruleNamesUpperCase(test) {
|
|||
};
|
||||
|
||||
module.exports.uniqueAliases = function uniqueAliases(test) {
|
||||
test.expect(78);
|
||||
test.expect(80);
|
||||
var tags = [];
|
||||
rules.forEach(function forRule(rule) {
|
||||
Array.prototype.push.apply(tags, rule.tags);
|
||||
|
@ -930,7 +930,7 @@ module.exports.uniqueAliases = function uniqueAliases(test) {
|
|||
};
|
||||
|
||||
module.exports.readme = function readme(test) {
|
||||
test.expect(101);
|
||||
test.expect(104);
|
||||
var tagToRules = {};
|
||||
rules.forEach(function forRule(rule) {
|
||||
rule.tags.forEach(function forTag(tag) {
|
||||
|
@ -991,7 +991,7 @@ module.exports.readme = function readme(test) {
|
|||
};
|
||||
|
||||
module.exports.doc = function doc(test) {
|
||||
test.expect(295);
|
||||
test.expect(303);
|
||||
fs.readFile("doc/Rules.md", shared.utf8Encoding,
|
||||
function readFile(err, contents) {
|
||||
test.ifError(err);
|
||||
|
|
13
test/proper-names.json
Normal file
13
test/proper-names.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"default": true,
|
||||
"MD044": {
|
||||
"names": [
|
||||
"markdownlint",
|
||||
"JavaScript",
|
||||
"Node.js",
|
||||
"GitHub",
|
||||
"npm",
|
||||
"Internet Explorer"
|
||||
]
|
||||
}
|
||||
}
|
45
test/proper-names.md
Normal file
45
test/proper-names.md
Normal file
|
@ -0,0 +1,45 @@
|
|||
# markdownlint test file
|
||||
|
||||
Markdownlint is a tool {MD044}
|
||||
|
||||
JavaScript is a language
|
||||
|
||||
JavaScript is not Java
|
||||
|
||||
Nor is it Javascript. {MD044}
|
||||
|
||||
markdownlint runs on Node.js via npm
|
||||
|
||||
Node is an environment
|
||||
|
||||
Install into it with NPM {MD044}
|
||||
|
||||
Node.JSX is not a real thing
|
||||
|
||||
Nor is nodesjs or NPMI
|
||||
|
||||
npm can npm stand npm for npm many npm things
|
||||
|
||||
Writing npm is right, but NPM is wrong {MD044}
|
||||
|
||||
Get excited about Github! {MD044}
|
||||
|
||||
Share code on GitHub via Git
|
||||
|
||||
Internet Explorer is a web browser
|
||||
|
||||
OTOH, "internet explorer" is a job {MD044}
|
||||
|
||||
## node.js instructions {MD044}
|
||||
|
||||
Code in `javascript` {MD044}
|
||||
|
||||
Execute `via the node.js engine` {MD044}
|
||||
|
||||
* Use NPM {MD044}
|
||||
|
||||
> Run Markdownlint on your README {MD044}
|
||||
|
||||
Upload the code (to github) {MD044}
|
||||
|
||||
Link to [github](https://github.com/). {MD044}
|
Loading…
Add table
Add a link
Reference in a new issue