-
Notifications
You must be signed in to change notification settings - Fork 58
/
all.js
44 lines (39 loc) · 1.83 KB
/
all.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
const assert = require("chai").assert;
const fs = require("fs");
const path = require("path");
const semver = require("semver");
const examplesDir = path.resolve(__dirname, "../../examples/");
const examples = fs.readdirSync(examplesDir)
.filter(exampleDir => fs.statSync(path.join(examplesDir, exampleDir)).isDirectory())
.filter(exampleDir => fs.existsSync(path.join(examplesDir, exampleDir, "package.json")));
for (const example of examples) {
const cwd = path.join(examplesDir, example);
// The plugin officially supports ESLint as early as v6, but the examples
// use ESLint v7, which has a higher minimum Node.js version than does v6.
// Only exercise the example if the running Node.js version satisfies the
// minimum version constraint. In CI, this will skip these tests in Node.js
// v8 and run them on all other Node.js versions.
const eslintPackageJsonPath = require.resolve("eslint/package.json", {
paths: [cwd]
});
const eslintPackageJson = require(eslintPackageJsonPath);
if (semver.satisfies(process.version, eslintPackageJson.engines.node)) {
describe("examples", function () {
describe(example, () => {
it("reports errors on code blocks in .md files", async () => {
const { ESLint } = require(
require.resolve("eslint", { paths: [cwd] })
);
const eslint = new ESLint({ cwd });
const results = await eslint.lintFiles(["."]);
const readme = results.find(result =>
path.basename(result.filePath) == "README.md"
);
assert.isNotNull(readme);
assert.isAbove(readme.messages.length, 0);
});
});
});
}
}