Skip to content

Commit

Permalink
feat: support globals
Browse files Browse the repository at this point in the history
Fixes #79
  • Loading branch information
AndersDJohnson committed Jul 7, 2017
1 parent 7ed8342 commit 5cc1c97
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function traverse(node, callbacks, parent) {
function getComment(html) {
var commentStart = "<!--";
var commentEnd = "-->";
var prefix = "eslint";
var regex = /^(eslint\b|global\s)/;

if (
html.slice(0, commentStart.length) !== commentStart ||
Expand All @@ -58,7 +58,7 @@ function getComment(html) {

html = html.slice(commentStart.length, -commentEnd.length);

if (html.trim().slice(0, prefix.length) !== prefix) {
if (!html.trim().match(regex)) {
return "";
}

Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/long.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,14 @@ console.log("Error!");
!@#$%^&*()
```

```js
foo
```

<!-- global foo -->

```js
foo
```

The end.
5 changes: 4 additions & 1 deletion tests/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("plugin", function() {
var report = cli.executeOnFiles([path.resolve(__dirname, "../fixtures/long.md")]);

assert.equal(report.results.length, 1);
assert.equal(report.results[0].messages.length, 5);
assert.equal(report.results[0].messages.length, 6);
assert.equal(report.results[0].messages[0].message, "Unexpected console statement.");
assert.equal(report.results[0].messages[0].line, 10);
assert.equal(report.results[0].messages[0].column, 1);
Expand All @@ -92,6 +92,9 @@ describe("plugin", function() {
assert.equal(report.results[0].messages[4].message, "Parsing error: Unexpected character '@'");
assert.equal(report.results[0].messages[4].line, 46);
assert.equal(report.results[0].messages[4].column, 2);
assert.equal(report.results[0].messages[5].message, "'foo' is not defined.");
assert.equal(report.results[0].messages[5].line, 50);
assert.equal(report.results[0].messages[5].column, 1);
});

describe("configuration comments", function() {
Expand Down

0 comments on commit 5cc1c97

Please sign in to comment.