Skip to content

Commit

Permalink
Fix: Exclude eol-last from output (fixes #48)
Browse files Browse the repository at this point in the history
  • Loading branch information
btmills committed Apr 15, 2016
1 parent 48f311d commit 5ef3371
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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<Message[]>} messages An array containing one array of messages
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("plugin", function() {
extensions: ["md", "mkdn", "mdown", "markdown"],
ignore: false,
rules: {
"eol-last": 2,
"no-console": 2
},
useEslintrc: false
Expand Down

0 comments on commit 5ef3371

Please sign in to comment.