mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add noInlineConfig option to disable inline config comments.
This commit is contained in:
parent
ac6b80b42a
commit
614ac8fa23
4 changed files with 110 additions and 45 deletions
|
@ -56,7 +56,7 @@
|
||||||
"max-len": "error",
|
"max-len": "error",
|
||||||
"max-lines": "off",
|
"max-lines": "off",
|
||||||
"max-nested-callbacks": "error",
|
"max-nested-callbacks": "error",
|
||||||
"max-params": ["error", 6],
|
"max-params": ["error", 7],
|
||||||
"max-statements": ["error", 30],
|
"max-statements": ["error", 30],
|
||||||
"max-statements-per-line": "error",
|
"max-statements-per-line": "error",
|
||||||
"multiline-ternary": "off",
|
"multiline-ternary": "off",
|
||||||
|
|
67
README.md
67
README.md
|
@ -206,34 +206,6 @@ Example:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
##### options.frontMatter
|
|
||||||
|
|
||||||
Type: `RegExp`
|
|
||||||
|
|
||||||
Matches any [front matter](https://jekyllrb.com/docs/frontmatter/) found at the
|
|
||||||
beginning of a file.
|
|
||||||
|
|
||||||
Some Markdown content begins with metadata; the default `RegExp` for this option
|
|
||||||
ignores common forms of "front matter". To match differently, specify a custom
|
|
||||||
`RegExp` or use the value `null` to disable the feature.
|
|
||||||
|
|
||||||
Note: Matches must occur at the start of the file.
|
|
||||||
|
|
||||||
Default:
|
|
||||||
|
|
||||||
```js
|
|
||||||
/^---$[^]*?^---$(\r\n|\r|\n)/m
|
|
||||||
```
|
|
||||||
|
|
||||||
Ignores:
|
|
||||||
|
|
||||||
```text
|
|
||||||
---
|
|
||||||
layout: post
|
|
||||||
title: Title
|
|
||||||
---
|
|
||||||
```
|
|
||||||
|
|
||||||
##### options.config
|
##### options.config
|
||||||
|
|
||||||
Type: `Object` mapping `String` to `Boolean | Object`
|
Type: `Object` mapping `String` to `Boolean | Object`
|
||||||
|
@ -318,6 +290,45 @@ var options = {
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### options.frontMatter
|
||||||
|
|
||||||
|
Type: `RegExp`
|
||||||
|
|
||||||
|
Matches any [front matter](https://jekyllrb.com/docs/frontmatter/) found at the
|
||||||
|
beginning of a file.
|
||||||
|
|
||||||
|
Some Markdown content begins with metadata; the default `RegExp` for this option
|
||||||
|
ignores common forms of "front matter". To match differently, specify a custom
|
||||||
|
`RegExp` or use the value `null` to disable the feature.
|
||||||
|
|
||||||
|
Note: Matches must occur at the start of the file.
|
||||||
|
|
||||||
|
Default:
|
||||||
|
|
||||||
|
```js
|
||||||
|
/^---$[^]*?^---$(\r\n|\r|\n)/m
|
||||||
|
```
|
||||||
|
|
||||||
|
Ignores:
|
||||||
|
|
||||||
|
```text
|
||||||
|
---
|
||||||
|
layout: post
|
||||||
|
title: Title
|
||||||
|
---
|
||||||
|
```
|
||||||
|
|
||||||
|
##### options.noInlineConfig
|
||||||
|
|
||||||
|
Type: `Boolean`
|
||||||
|
|
||||||
|
Disables the use of HTML comments like `<!-- markdownlint-disable -->` to toggle
|
||||||
|
rules within the body of Markdown content.
|
||||||
|
|
||||||
|
By default, properly-formatted inline comments can be used to create exceptions
|
||||||
|
for parts of a document. Setting `noInlineConfig` to `true` ignores all such
|
||||||
|
comments.
|
||||||
|
|
||||||
##### options.resultVersion
|
##### options.resultVersion
|
||||||
|
|
||||||
Type: `Number`
|
Type: `Number`
|
||||||
|
|
|
@ -84,7 +84,8 @@ function uniqueFilterForSortedErrors(value, index, array) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lints a single string
|
// Lints a single string
|
||||||
function lintContent(content, config, frontMatter, resultVersion) {
|
function lintContent(
|
||||||
|
content, config, frontMatter, noInlineConfig, resultVersion) {
|
||||||
// Remove UTF-8 byte order marker (if present)
|
// Remove UTF-8 byte order marker (if present)
|
||||||
if (content.charCodeAt(0) === 0xfeff) {
|
if (content.charCodeAt(0) === 0xfeff) {
|
||||||
content = content.slice(1);
|
content = content.slice(1);
|
||||||
|
@ -192,12 +193,14 @@ function lintContent(content, config, frontMatter, resultVersion) {
|
||||||
}
|
}
|
||||||
var enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length);
|
var enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length);
|
||||||
lines.forEach(function forLine(line) {
|
lines.forEach(function forLine(line) {
|
||||||
var match = shared.inlineCommentRe.exec(line);
|
if (!noInlineConfig) {
|
||||||
if (match) {
|
var match = shared.inlineCommentRe.exec(line);
|
||||||
enabledRules = shared.clone(enabledRules);
|
if (match) {
|
||||||
while (match) {
|
enabledRules = shared.clone(enabledRules);
|
||||||
forMatch(match);
|
while (match) {
|
||||||
match = shared.inlineCommentRe.exec(line);
|
forMatch(match);
|
||||||
|
match = shared.inlineCommentRe.exec(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enabledRulesPerLineNumber.push(enabledRules);
|
enabledRulesPerLineNumber.push(enabledRules);
|
||||||
|
@ -303,6 +306,7 @@ function lintFile(
|
||||||
file,
|
file,
|
||||||
config,
|
config,
|
||||||
frontMatter,
|
frontMatter,
|
||||||
|
noInlineConfig,
|
||||||
resultVersion,
|
resultVersion,
|
||||||
synchronous,
|
synchronous,
|
||||||
callback) {
|
callback) {
|
||||||
|
@ -310,7 +314,8 @@ function lintFile(
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
var result = lintContent(content, config, frontMatter, resultVersion);
|
var result = lintContent(
|
||||||
|
content, config, frontMatter, noInlineConfig, resultVersion);
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
}
|
}
|
||||||
// Make a/synchronous call to read file
|
// Make a/synchronous call to read file
|
||||||
|
@ -347,9 +352,10 @@ function markdownlint(options, callback) {
|
||||||
files = [ String(options.files) ];
|
files = [ String(options.files) ];
|
||||||
}
|
}
|
||||||
var strings = options.strings || {};
|
var strings = options.strings || {};
|
||||||
|
var config = options.config || { "default": true };
|
||||||
var frontMatter = (options.frontMatter === undefined) ?
|
var frontMatter = (options.frontMatter === undefined) ?
|
||||||
shared.frontMatterRe : options.frontMatter;
|
shared.frontMatterRe : options.frontMatter;
|
||||||
var config = options.config || { "default": true };
|
var noInlineConfig = !!options.noInlineConfig;
|
||||||
var resultVersion = options.resultVersion || 0;
|
var resultVersion = options.resultVersion || 0;
|
||||||
var synchronous = (callback === markdownlintSynchronousCallback);
|
var synchronous = (callback === markdownlintSynchronousCallback);
|
||||||
var results = new Results();
|
var results = new Results();
|
||||||
|
@ -357,7 +363,13 @@ function markdownlint(options, callback) {
|
||||||
function lintFilesArray() {
|
function lintFilesArray() {
|
||||||
var file = files.shift();
|
var file = files.shift();
|
||||||
if (file) {
|
if (file) {
|
||||||
lintFile(file, config, frontMatter, resultVersion, synchronous,
|
lintFile(
|
||||||
|
file,
|
||||||
|
config,
|
||||||
|
frontMatter,
|
||||||
|
noInlineConfig,
|
||||||
|
resultVersion,
|
||||||
|
synchronous,
|
||||||
function lintedFile(err, result) {
|
function lintedFile(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
@ -376,6 +388,7 @@ function markdownlint(options, callback) {
|
||||||
strings[key] || "",
|
strings[key] || "",
|
||||||
config,
|
config,
|
||||||
frontMatter,
|
frontMatter,
|
||||||
|
noInlineConfig,
|
||||||
resultVersion);
|
resultVersion);
|
||||||
results[key] = result;
|
results[key] = result;
|
||||||
});
|
});
|
||||||
|
|
|
@ -83,11 +83,15 @@ module.exports.projectFiles = function projectFiles(test) {
|
||||||
test.expect(2);
|
test.expect(2);
|
||||||
var options = {
|
var options = {
|
||||||
"files": [ "README.md" ],
|
"files": [ "README.md" ],
|
||||||
"config": { "MD013": { "line_length": 150 } }
|
"noInlineConfig": true,
|
||||||
|
"config": {
|
||||||
|
"MD013": { "line_length": 150 },
|
||||||
|
"MD024": false
|
||||||
|
}
|
||||||
};
|
};
|
||||||
markdownlint(options, function callback(err, actual) {
|
markdownlint(options, function callback(err, actual) {
|
||||||
test.ifError(err);
|
test.ifError(err);
|
||||||
var expected = { "README.md": { "MD024": [ 392, 398 ] } };
|
var expected = { "README.md": {} };
|
||||||
test.deepEqual(actual, expected, "Issue(s) with project files.");
|
test.deepEqual(actual, expected, "Issue(s) with project files.");
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
|
@ -762,10 +766,42 @@ module.exports.customFrontMatter = function customFrontMatter(test) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.noInlineConfig = function noInlineConfig(test) {
|
||||||
|
test.expect(2);
|
||||||
|
markdownlint({
|
||||||
|
"strings": {
|
||||||
|
"content": [
|
||||||
|
"# Heading",
|
||||||
|
"",
|
||||||
|
"\tTab",
|
||||||
|
"",
|
||||||
|
"<!-- markdownlint-disable-->",
|
||||||
|
"",
|
||||||
|
"\tTab",
|
||||||
|
"",
|
||||||
|
"<!-- markdownlint-enable-->",
|
||||||
|
"",
|
||||||
|
"\tTab"
|
||||||
|
].join("\n")
|
||||||
|
},
|
||||||
|
"noInlineConfig": true
|
||||||
|
}, function callback(err, result) {
|
||||||
|
test.ifError(err);
|
||||||
|
var expectedResult = {
|
||||||
|
"content": {
|
||||||
|
"MD010": [ 3, 7, 11 ]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
test.deepEqual(result, expectedResult, "Undetected issues.");
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.readmeHeaders = function readmeHeaders(test) {
|
module.exports.readmeHeaders = function readmeHeaders(test) {
|
||||||
test.expect(2);
|
test.expect(2);
|
||||||
markdownlint({
|
markdownlint({
|
||||||
"files": "README.md",
|
"files": "README.md",
|
||||||
|
"noInlineConfig": true,
|
||||||
"config": {
|
"config": {
|
||||||
"default": false,
|
"default": false,
|
||||||
"MD013": {
|
"MD013": {
|
||||||
|
@ -786,8 +822,9 @@ module.exports.readmeHeaders = function readmeHeaders(test) {
|
||||||
"#### options",
|
"#### options",
|
||||||
"##### options.files",
|
"##### options.files",
|
||||||
"##### options.strings",
|
"##### options.strings",
|
||||||
"##### options.frontMatter",
|
|
||||||
"##### options.config",
|
"##### options.config",
|
||||||
|
"##### options.frontMatter",
|
||||||
|
"##### options.noInlineConfig",
|
||||||
"##### options.resultVersion",
|
"##### options.resultVersion",
|
||||||
"#### callback",
|
"#### callback",
|
||||||
"#### result",
|
"#### result",
|
||||||
|
@ -803,7 +840,7 @@ module.exports.readmeHeaders = function readmeHeaders(test) {
|
||||||
}
|
}
|
||||||
}, function callback(err, result) {
|
}, function callback(err, result) {
|
||||||
test.ifError(err);
|
test.ifError(err);
|
||||||
var expected = { "README.md": { "MD024": [ 392, 398 ] } };
|
var expected = { "README.md": {} };
|
||||||
test.deepEqual(result, expected, "Unexpected issues.");
|
test.deepEqual(result, expected, "Unexpected issues.");
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
|
@ -827,10 +864,14 @@ module.exports.filesArrayAsString = function filesArrayAsString(test) {
|
||||||
test.expect(2);
|
test.expect(2);
|
||||||
markdownlint({
|
markdownlint({
|
||||||
"files": "README.md",
|
"files": "README.md",
|
||||||
"config": { "MD013": { "line_length": 150 } }
|
"noInlineConfig": true,
|
||||||
|
"config": {
|
||||||
|
"MD013": { "line_length": 150 },
|
||||||
|
"MD024": false
|
||||||
|
}
|
||||||
}, function callback(err, actual) {
|
}, function callback(err, actual) {
|
||||||
test.ifError(err);
|
test.ifError(err);
|
||||||
var expected = { "README.md": { "MD024": [ 392, 398 ] } };
|
var expected = { "README.md": {} };
|
||||||
test.deepEqual(actual, expected, "Unexpected issues.");
|
test.deepEqual(actual, expected, "Unexpected issues.");
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue