-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Docs: Add React example * Docs: Ignore lint errors in examples * Docs: Test examples report errors
- Loading branch information
Showing
8 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use strict"; | ||
|
||
module.exports = { | ||
root: true, | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:markdown/recommended", | ||
"plugin:react/recommended", | ||
], | ||
settings: { | ||
react: { | ||
version: "16.8.0" | ||
} | ||
}, | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true | ||
}, | ||
ecmaVersion: 2015, | ||
sourceType: "module" | ||
}, | ||
env: { | ||
browser: true, | ||
es6: true | ||
}, | ||
overrides: [ | ||
{ | ||
files: [".eslintrc.js"], | ||
env: { | ||
node: true | ||
} | ||
}, | ||
{ | ||
files: ["**/*.md/*.jsx"], | ||
globals: { | ||
// For code examples, `import React from "react";` at the top | ||
// of every code block is distracting, so pre-define the | ||
// `React` global. | ||
React: false | ||
}, | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# React Example | ||
|
||
```jsx | ||
function App({ name }) { | ||
return ( | ||
<div> | ||
<p>Hello, {name}!</p> | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
```sh | ||
$ git clone https://github.com/eslint/eslint-plugin-markdown.git | ||
$ cd eslint-plugin-markdown/examples/react | ||
$ npm install | ||
$ npm test | ||
|
||
eslint-plugin-markdown/examples/react/README.md | ||
4:10 error 'App' is defined but never used no-unused-vars | ||
4:16 error 'name' is missing in props validation react/prop-types | ||
|
||
✖ 2 problems (2 errors, 0 warnings) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"test": "eslint ." | ||
}, | ||
"devDependencies": { | ||
"eslint": "^7.5.0", | ||
"eslint-plugin-markdown": "file:../..", | ||
"eslint-plugin-react": "^7.20.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"use strict"; | ||
|
||
const assert = require("chai").assert; | ||
const execSync = require("child_process").execSync; | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const semver = require("semver"); | ||
|
||
const examples = path.resolve(__dirname, "../../examples/"); | ||
for (const example of fs.readdirSync(examples)) { | ||
const cwd = path.join(examples, 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); | ||
}); | ||
}); | ||
}); | ||
} | ||
} |