Skip to content

Commit

Permalink
Docs: Add eslint-plugin-markdown for JavaScript code samples in docum…
Browse files Browse the repository at this point in the history
…entation (#176)

This applies our JavaScript linting to the JavaScript code samples in the markdown documentation files.

Initially, this is just focused on fixing the syntax errors and a few one-off violations. I have disabled other rules that had many violations. There are some autofixable stylistic rules we can follow-up to fix to ensure code sample formatting consistency.
  • Loading branch information
bmish authored Apr 19, 2021
1 parent 8390fa7 commit a0f21a0
Show file tree
Hide file tree
Showing 10 changed files with 5,614 additions and 14 deletions.
30 changes: 29 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,33 @@
"eslint-plugin/require-meta-type": "error",
"eslint-plugin/test-case-property-ordering": "error",
"eslint-plugin/test-case-shorthand-strings": "error"
}
},

"overrides": [
{
"files": ["**/*.md"],
"processor": "markdown/markdown"
},
{
"files": ["**/*.md/*.js", "**/*.md/*.javascript"],
"plugins": ["markdown"],
"parserOptions": {
"sourceType": "module"
},
"rules": {
"brace-style": "off",
"eqeqeq": "off",
"guard-for-in": "off",
"indent": "off",
"no-constant-condition": "off",
"no-empty-function": "off",
"no-undef": "off",
"no-unused-expressions": "off",
"no-unused-vars": "off",
"no-var": "off",
"quotes": "off",
"space-before-function-paren": "off"
}
}
]
}
2 changes: 1 addition & 1 deletion docs/rules/no-assert-ok.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
An example when using `assert.ok` can involuntarily go wrong:

```js
test('test myFunc returns a truthy value' (assert) => {
test('test myFunc returns a truthy value', (assert) => {
assert.ok(myFunc);
});
```
Expand Down
7 changes: 5 additions & 2 deletions docs/rules/no-early-return.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ QUnit[shouldRunTest() ? "test" : "skip"]("a test", function (assert) {
// Nested function scopes are okay because they do not cause the test to abort
QUnit.test("a test", function (assert) {
(function () {
return;
})();
if (true) {
return;
}
assert.ok(true);
}());
});

if (shouldRunTest()) {
Expand Down
8 changes: 4 additions & 4 deletions docs/rules/no-global-assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ notDeepEqual(a, b);

notPropEqual(a, b);

raises(function (), TypeError);
raises(function () {}, TypeError);

throws(function (), TypeError);
throws(function () {}, TypeError);

```

Expand All @@ -56,9 +56,9 @@ assert.notDeepEqual(a, b);

assert.notPropEqual(a, b);

assert.raises(function (), TypeError);
assert.raises(function () {}, TypeError);

assert.throws(function (), TypeError);
assert.throws(function () {}, TypeError);

```

Expand Down
4 changes: 2 additions & 2 deletions docs/rules/no-loose-assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The `assert.equal`/`assert.notEqual` assertion methods in QUnit use loose equali
An example when using `assert.ok` can involuntarily go wrong:

```js
test('test myFunc returns a truthy value' (assert) => {
test('test myFunc returns a truthy value', (assert) => {
assert.ok(myFunc);
});
```
Expand Down Expand Up @@ -83,7 +83,7 @@ QUnit.test('Name', function (foo) { foo.propEqual(a, b); });

QUnit.test('Name', function () { propEqual(a, b); });

/* eslint no-loose-assertions: ["error", ["strictEqual", "ok", "notOk"]] */
/* With rule config: ["error", ["strictEqual", "ok", "notOk"]] */
QUnit.test('Name', function (assert) { assert.notEqual(a, b); });

```
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-nested-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ QUnit.module('ParentModule', function () {
QUnit.module('ChildModule', function () {
QUnit.test('ChildTest', function () {});
});
})
});

```

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-qunit-stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The following patterns are not warnings:

```js

var done = assert.async():
var done = assert.async();

```

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/require-expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test('name', function(assert) {
});

test('name', function(assert) {
var callback = function() {
function callback() {
assert.ok(true);
}
callback();
Expand Down
Loading

0 comments on commit a0f21a0

Please sign in to comment.