mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Rename rule params.options to .config for API consistency.
This commit is contained in:
parent
a0e3b4db90
commit
f79cdcb0d4
3 changed files with 29 additions and 29 deletions
|
|
@ -231,7 +231,7 @@ function lintContent(
|
||||||
rules.forEach(function forRule(rule) {
|
rules.forEach(function forRule(rule) {
|
||||||
// Configure rule
|
// Configure rule
|
||||||
var ruleName = rule.names[0];
|
var ruleName = rule.names[0];
|
||||||
params.options = mergedRules[ruleName];
|
params.config = mergedRules[ruleName];
|
||||||
var errors = [];
|
var errors = [];
|
||||||
function onError(errorInfo) {
|
function onError(errorInfo) {
|
||||||
errors.push({
|
errors.push({
|
||||||
|
|
|
||||||
54
lib/rules.js
54
lib/rules.js
|
|
@ -254,7 +254,7 @@ module.exports = [
|
||||||
"desc": "First header should be a top level header",
|
"desc": "First header should be a top level header",
|
||||||
"tags": [ "headers" ],
|
"tags": [ "headers" ],
|
||||||
"func": function MD002(params, onError) {
|
"func": function MD002(params, onError) {
|
||||||
var level = params.options.level || 1;
|
var level = params.config.level || 1;
|
||||||
var tag = "h" + level;
|
var tag = "h" + level;
|
||||||
params.tokens.every(function forToken(token) {
|
params.tokens.every(function forToken(token) {
|
||||||
if (token.type === "heading_open") {
|
if (token.type === "heading_open") {
|
||||||
|
|
@ -271,7 +271,7 @@ module.exports = [
|
||||||
"desc": "Header style",
|
"desc": "Header style",
|
||||||
"tags": [ "headers" ],
|
"tags": [ "headers" ],
|
||||||
"func": function MD003(params, onError) {
|
"func": function MD003(params, onError) {
|
||||||
var style = params.options.style || "consistent";
|
var style = params.config.style || "consistent";
|
||||||
filterTokens(params, "heading_open", function forToken(token) {
|
filterTokens(params, "heading_open", function forToken(token) {
|
||||||
var styleForToken = headingStyleFor(token);
|
var styleForToken = headingStyleFor(token);
|
||||||
if (style === "consistent") {
|
if (style === "consistent") {
|
||||||
|
|
@ -307,7 +307,7 @@ module.exports = [
|
||||||
"desc": "Unordered list style",
|
"desc": "Unordered list style",
|
||||||
"tags": [ "bullet", "ul" ],
|
"tags": [ "bullet", "ul" ],
|
||||||
"func": function MD004(params, onError) {
|
"func": function MD004(params, onError) {
|
||||||
var style = params.options.style || "consistent";
|
var style = params.config.style || "consistent";
|
||||||
var expectedStyle = style;
|
var expectedStyle = style;
|
||||||
var nestingStyles = [];
|
var nestingStyles = [];
|
||||||
flattenLists(params).forEach(function forList(list) {
|
flattenLists(params).forEach(function forList(list) {
|
||||||
|
|
@ -373,7 +373,7 @@ module.exports = [
|
||||||
"desc": "Unordered list indentation",
|
"desc": "Unordered list indentation",
|
||||||
"tags": [ "bullet", "ul", "indentation" ],
|
"tags": [ "bullet", "ul", "indentation" ],
|
||||||
"func": function MD007(params, onError) {
|
"func": function MD007(params, onError) {
|
||||||
var optionsIndent = params.options.indent || 2;
|
var optionsIndent = params.config.indent || 2;
|
||||||
var prevIndent = 0;
|
var prevIndent = 0;
|
||||||
flattenLists(params).forEach(function forList(list) {
|
flattenLists(params).forEach(function forList(list) {
|
||||||
if (list.unordered && list.parentsUnordered) {
|
if (list.unordered && list.parentsUnordered) {
|
||||||
|
|
@ -394,8 +394,8 @@ module.exports = [
|
||||||
"desc": "Trailing spaces",
|
"desc": "Trailing spaces",
|
||||||
"tags": [ "whitespace" ],
|
"tags": [ "whitespace" ],
|
||||||
"func": function MD009(params, onError) {
|
"func": function MD009(params, onError) {
|
||||||
var brSpaces = params.options.br_spaces || 0;
|
var brSpaces = params.config.br_spaces || 0;
|
||||||
var listItemEmptyLines = params.options.list_item_empty_lines;
|
var listItemEmptyLines = params.config.list_item_empty_lines;
|
||||||
var allowListItemEmptyLines =
|
var allowListItemEmptyLines =
|
||||||
(listItemEmptyLines === undefined) ? false : !!listItemEmptyLines;
|
(listItemEmptyLines === undefined) ? false : !!listItemEmptyLines;
|
||||||
var listItemLineNumbers = [];
|
var listItemLineNumbers = [];
|
||||||
|
|
@ -424,7 +424,7 @@ module.exports = [
|
||||||
"desc": "Hard tabs",
|
"desc": "Hard tabs",
|
||||||
"tags": [ "whitespace", "hard_tab" ],
|
"tags": [ "whitespace", "hard_tab" ],
|
||||||
"func": function MD010(params, onError) {
|
"func": function MD010(params, onError) {
|
||||||
var codeBlocks = params.options.code_blocks;
|
var codeBlocks = params.config.code_blocks;
|
||||||
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||||
forEachLine(params, function forLine(line, lineIndex, inCode) {
|
forEachLine(params, function forLine(line, lineIndex, inCode) {
|
||||||
if (tabRe.test(line) && (!inCode || includeCodeBlocks)) {
|
if (tabRe.test(line) && (!inCode || includeCodeBlocks)) {
|
||||||
|
|
@ -456,7 +456,7 @@ module.exports = [
|
||||||
"desc": "Multiple consecutive blank lines",
|
"desc": "Multiple consecutive blank lines",
|
||||||
"tags": [ "whitespace", "blank_lines" ],
|
"tags": [ "whitespace", "blank_lines" ],
|
||||||
"func": function MD012(params, onError) {
|
"func": function MD012(params, onError) {
|
||||||
var maximum = params.options.maximum || 1;
|
var maximum = params.config.maximum || 1;
|
||||||
var count = 0;
|
var count = 0;
|
||||||
forEachLine(params, function forLine(line, lineIndex, inCode) {
|
forEachLine(params, function forLine(line, lineIndex, inCode) {
|
||||||
count = (inCode || line.trim().length) ? 0 : count + 1;
|
count = (inCode || line.trim().length) ? 0 : count + 1;
|
||||||
|
|
@ -472,12 +472,12 @@ module.exports = [
|
||||||
"desc": "Line length",
|
"desc": "Line length",
|
||||||
"tags": [ "line_length" ],
|
"tags": [ "line_length" ],
|
||||||
"func": function MD013(params, onError) {
|
"func": function MD013(params, onError) {
|
||||||
var lineLength = params.options.line_length || defaultLineLength;
|
var lineLength = params.config.line_length || defaultLineLength;
|
||||||
var codeBlocks = params.options.code_blocks;
|
var codeBlocks = params.config.code_blocks;
|
||||||
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||||
var tables = params.options.tables;
|
var tables = params.config.tables;
|
||||||
var includeTables = (tables === undefined) ? true : !!tables;
|
var includeTables = (tables === undefined) ? true : !!tables;
|
||||||
var headers = params.options.headers;
|
var headers = params.config.headers;
|
||||||
var includeHeaders = (headers === undefined) ? true : !!headers;
|
var includeHeaders = (headers === undefined) ? true : !!headers;
|
||||||
var headerLineNumbers = [];
|
var headerLineNumbers = [];
|
||||||
if (!includeHeaders) {
|
if (!includeHeaders) {
|
||||||
|
|
@ -678,7 +678,7 @@ module.exports = [
|
||||||
"desc": "Multiple top level headers in the same document",
|
"desc": "Multiple top level headers in the same document",
|
||||||
"tags": [ "headers" ],
|
"tags": [ "headers" ],
|
||||||
"func": function MD025(params, onError) {
|
"func": function MD025(params, onError) {
|
||||||
var level = params.options.level || 1;
|
var level = params.config.level || 1;
|
||||||
var tag = "h" + level;
|
var tag = "h" + level;
|
||||||
var hasTopLevelHeading = false;
|
var hasTopLevelHeading = false;
|
||||||
filterTokens(params, "heading_open", function forToken(token) {
|
filterTokens(params, "heading_open", function forToken(token) {
|
||||||
|
|
@ -698,7 +698,7 @@ module.exports = [
|
||||||
"desc": "Trailing punctuation in header",
|
"desc": "Trailing punctuation in header",
|
||||||
"tags": [ "headers" ],
|
"tags": [ "headers" ],
|
||||||
"func": function MD026(params, onError) {
|
"func": function MD026(params, onError) {
|
||||||
var punctuation = params.options.punctuation || ".,;:!?";
|
var punctuation = params.config.punctuation || ".,;:!?";
|
||||||
var re = new RegExp("[" + punctuation + "]$");
|
var re = new RegExp("[" + punctuation + "]$");
|
||||||
forEachHeading(params, function forHeading(heading, content) {
|
forEachHeading(params, function forHeading(heading, content) {
|
||||||
var match = re.exec(content);
|
var match = re.exec(content);
|
||||||
|
|
@ -769,7 +769,7 @@ module.exports = [
|
||||||
"desc": "Ordered list item prefix",
|
"desc": "Ordered list item prefix",
|
||||||
"tags": [ "ol" ],
|
"tags": [ "ol" ],
|
||||||
"func": function MD029(params, onError) {
|
"func": function MD029(params, onError) {
|
||||||
var style = params.options.style || "one_or_ordered";
|
var style = params.config.style || "one_or_ordered";
|
||||||
var numberRe = /^[\s>]*([^.)]*)[.)]/;
|
var numberRe = /^[\s>]*([^.)]*)[.)]/;
|
||||||
flattenLists(params).forEach(function forList(list) {
|
flattenLists(params).forEach(function forList(list) {
|
||||||
if (!list.unordered) {
|
if (!list.unordered) {
|
||||||
|
|
@ -800,10 +800,10 @@ module.exports = [
|
||||||
"desc": "Spaces after list markers",
|
"desc": "Spaces after list markers",
|
||||||
"tags": [ "ol", "ul", "whitespace" ],
|
"tags": [ "ol", "ul", "whitespace" ],
|
||||||
"func": function MD030(params, onError) {
|
"func": function MD030(params, onError) {
|
||||||
var ulSingle = params.options.ul_single || 1;
|
var ulSingle = params.config.ul_single || 1;
|
||||||
var olSingle = params.options.ol_single || 1;
|
var olSingle = params.config.ol_single || 1;
|
||||||
var ulMulti = params.options.ul_multi || 1;
|
var ulMulti = params.config.ul_multi || 1;
|
||||||
var olMulti = params.options.ol_multi || 1;
|
var olMulti = params.config.ol_multi || 1;
|
||||||
flattenLists(params).forEach(function forList(list) {
|
flattenLists(params).forEach(function forList(list) {
|
||||||
var lineCount = list.lastLineIndex - list.open.map[0];
|
var lineCount = list.lastLineIndex - list.open.map[0];
|
||||||
var allSingle = lineCount === list.items.length;
|
var allSingle = lineCount === list.items.length;
|
||||||
|
|
@ -869,7 +869,7 @@ module.exports = [
|
||||||
"desc": "Inline HTML",
|
"desc": "Inline HTML",
|
||||||
"tags": [ "html" ],
|
"tags": [ "html" ],
|
||||||
"func": function MD033(params, onError) {
|
"func": function MD033(params, onError) {
|
||||||
var allowedElements = (params.options.allowed_elements || [])
|
var allowedElements = (params.config.allowed_elements || [])
|
||||||
.map(function forElement(element) {
|
.map(function forElement(element) {
|
||||||
return element.toLowerCase();
|
return element.toLowerCase();
|
||||||
});
|
});
|
||||||
|
|
@ -927,7 +927,7 @@ module.exports = [
|
||||||
"desc": "Horizontal rule style",
|
"desc": "Horizontal rule style",
|
||||||
"tags": [ "hr" ],
|
"tags": [ "hr" ],
|
||||||
"func": function MD035(params, onError) {
|
"func": function MD035(params, onError) {
|
||||||
var style = params.options.style || "consistent";
|
var style = params.config.style || "consistent";
|
||||||
filterTokens(params, "hr", function forToken(token) {
|
filterTokens(params, "hr", function forToken(token) {
|
||||||
var lineTrim = token.line.trim();
|
var lineTrim = token.line.trim();
|
||||||
if (style === "consistent") {
|
if (style === "consistent") {
|
||||||
|
|
@ -943,7 +943,7 @@ module.exports = [
|
||||||
"desc": "Emphasis used instead of a header",
|
"desc": "Emphasis used instead of a header",
|
||||||
"tags": [ "headers", "emphasis" ],
|
"tags": [ "headers", "emphasis" ],
|
||||||
"func": function MD036(params, onError) {
|
"func": function MD036(params, onError) {
|
||||||
var punctuation = params.options.punctuation || ".,;:!?";
|
var punctuation = params.config.punctuation || ".,;:!?";
|
||||||
var re = new RegExp("[" + punctuation + "]$");
|
var re = new RegExp("[" + punctuation + "]$");
|
||||||
function base(token) {
|
function base(token) {
|
||||||
if (token.type === "paragraph_open") {
|
if (token.type === "paragraph_open") {
|
||||||
|
|
@ -1085,8 +1085,8 @@ module.exports = [
|
||||||
"desc": "First line in file should be a top level header",
|
"desc": "First line in file should be a top level header",
|
||||||
"tags": [ "headers" ],
|
"tags": [ "headers" ],
|
||||||
"func": function MD041(params, onError) {
|
"func": function MD041(params, onError) {
|
||||||
var level = params.options.level || 1;
|
var level = params.config.level || 1;
|
||||||
var frontMatterTitle = params.options.front_matter_title;
|
var frontMatterTitle = params.config.front_matter_title;
|
||||||
var tag = "h" + level;
|
var tag = "h" + level;
|
||||||
var frontMatterTitleRe =
|
var frontMatterTitleRe =
|
||||||
new RegExp(frontMatterTitle || "^\\s*title\\s*[:=]", "i");
|
new RegExp(frontMatterTitle || "^\\s*title\\s*[:=]", "i");
|
||||||
|
|
@ -1149,7 +1149,7 @@ module.exports = [
|
||||||
"desc": "Required header structure",
|
"desc": "Required header structure",
|
||||||
"tags": [ "headers" ],
|
"tags": [ "headers" ],
|
||||||
"func": function MD043(params, onError) {
|
"func": function MD043(params, onError) {
|
||||||
var requiredHeaders = params.options.headers;
|
var requiredHeaders = params.config.headers;
|
||||||
if (requiredHeaders) {
|
if (requiredHeaders) {
|
||||||
var levels = {};
|
var levels = {};
|
||||||
[ 1, 2, 3, 4, 5, 6 ].forEach(function forLevel(level) {
|
[ 1, 2, 3, 4, 5, 6 ].forEach(function forLevel(level) {
|
||||||
|
|
@ -1186,8 +1186,8 @@ module.exports = [
|
||||||
"desc": "Proper names should have the correct capitalization",
|
"desc": "Proper names should have the correct capitalization",
|
||||||
"tags": [ "spelling" ],
|
"tags": [ "spelling" ],
|
||||||
"func": function MD044(params, onError) {
|
"func": function MD044(params, onError) {
|
||||||
var names = params.options.names || [];
|
var names = params.config.names || [];
|
||||||
var codeBlocks = params.options.code_blocks;
|
var codeBlocks = params.config.code_blocks;
|
||||||
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||||
names.forEach(function forName(name) {
|
names.forEach(function forName(name) {
|
||||||
var escapedName = escapeForRegExp(name);
|
var escapedName = escapeForRegExp(name);
|
||||||
|
|
|
||||||
|
|
@ -1149,7 +1149,7 @@ module.exports.doc = function doc(test) {
|
||||||
test.equal(token.content, rule.names[0] + " - " + rule.desc,
|
test.equal(token.content, rule.names[0] + " - " + rule.desc,
|
||||||
"Rule mismatch.");
|
"Rule mismatch.");
|
||||||
ruleUsesParams = rule.func.toString()
|
ruleUsesParams = rule.func.toString()
|
||||||
.match(/params\.options\.[_a-z]*/gi);
|
.match(/params\.config\.[_a-z]*/gi);
|
||||||
if (ruleUsesParams) {
|
if (ruleUsesParams) {
|
||||||
ruleUsesParams = ruleUsesParams.map(function forUse(use) {
|
ruleUsesParams = ruleUsesParams.map(function forUse(use) {
|
||||||
return use.split(".").pop();
|
return use.split(".").pop();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue