diff --git a/README.md b/README.md index 53041c60..a6deb238 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,12 @@ Blocks that don't specify either `js`, `javascript`, `jsx`, or `node` syntax are print("This doesn't get linted either.") ``` +## Unsatisfiable Rules + +Since code blocks are not files themselves but embedded inside a Markdown document, some rules do not apply to Markdown code blocks, and messages from these rules are automatically suppressed: + +- `eol-last` + ## Contributing ```sh diff --git a/lib/processor.js b/lib/processor.js index 15f9b8e6..4ea292bc 100644 --- a/lib/processor.js +++ b/lib/processor.js @@ -12,6 +12,9 @@ var assign = require("object-assign"); var remark = require("remark"); var SUPPORTED_SYNTAXES = ["js", "javascript", "node", "jsx"]; +var UNSATISFIABLE_RULES = [ + "eol-last" // The Markdown parser strips trailing newlines in code fences +]; var blocks = []; @@ -57,6 +60,15 @@ function preprocess(text) { }); } +/** + * Excludes unsatisfiable rules from the list of messages. + * @param {Message} message A message from the linter. + * @returns {boolean} True if the message should be included in output. + */ +function excludeUnsatisfiableRules(message) { + return UNSATISFIABLE_RULES.indexOf(message.ruleId) < 0; +} + /** * Transforms generated messages for output. * @param {Array} messages An array containing one array of messages @@ -65,7 +77,7 @@ function preprocess(text) { */ function postprocess(messages) { return [].concat.apply([], messages.map(function(group, i) { - return group.map(function(message) { + return group.filter(excludeUnsatisfiableRules).map(function(message) { return assign({}, message, { line: message.line + blocks[i].position.start.line, column: message.column + blocks[i].position.indent[message.line - 1] - 1 diff --git a/tests/plugin.js b/tests/plugin.js index 19236dd7..0ada5675 100644 --- a/tests/plugin.js +++ b/tests/plugin.js @@ -26,6 +26,7 @@ describe("plugin", function() { extensions: ["md", "mkdn", "mdown", "markdown"], ignore: false, rules: { + "eol-last": 2, "no-console": 2 }, useEslintrc: false