Skip to content

Commit

Permalink
feat(reporter): include default reporter
Browse files Browse the repository at this point in the history
Make reporting simpler so if you just want to see an output you dont need to do anything.
BREAKING CHANGE: Retext plugins will report by default, set `reporter` to `false` to avoid this.
  • Loading branch information
NickColley committed Nov 18, 2022
1 parent d3e1aff commit 499e3d7
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 37 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ It will render like this:
| textTransforms | [retext plugins] | `[]` |
| transformsDirectory | directory with your transforms | `"."` |
| textParser | retext parser | [retext-english] |
| reporter | [vfile reporter] | `undefined` |
| reporter | [vfile reporter] | [vfile-reporter] |

[remark plugins]: https://unifiedjs.com/explore/keyword/remark
[rehype plugins]: https://unifiedjs.com/explore/keyword/rehype
[retext plugins]: https://unifiedjs.com/explore/keyword/retext
[retext-english]: https://www.npmjs.com/package/retext-english
[vfile-reporter]: https://github.com/vfile/vfile-reporter
[vfile reporter]: https://github.com/vfile/vfile#reporters

---
Expand All @@ -76,6 +77,8 @@ It will render like this:

### [Reporting and linting with retext](./docs/text.md)

- [Configuring the reporter](./docs/text.md#configuring-the-reporter)
- [Turning off default reporter](./docs/text.md#turning-off-default-reporter)
- [Configuring text parser language](./docs/text.md#configuring-text-parser-language)

### Configure options for transforms
Expand Down
26 changes: 25 additions & 1 deletion docs/text.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# Reporting and linting with retext

The default reporter used is [`vfile-reporter`](https://github.com/vfile/vfile-reporter).

```javascript
eleventyConfig.addPlugin(EleventyUnifiedPlugin, {
textTransforms: ["retext-repeated-words"],
});
```

## Configuring the reporter

```bash
npm install eleventy-plugin-unified retext-repeated-words vfile-reporter
```

```javascript
eleventyConfig.addPlugin(EleventyUnifiedPlugin, {
reporter: "vfile-reporter",
reporter: "vfile-reporter-json",
textTransforms: ["retext-repeated-words"],
});
```
Expand All @@ -22,6 +32,20 @@ eleventyConfig.addPlugin(EleventyUnifiedPlugin, {
});
```


## Turning off default reporter

```bash
npm install eleventy-plugin-unified retext-latin
```

```javascript
eleventyConfig.addPlugin(EleventyUnifiedPlugin, {
reporter: false,
textTransforms: ["retext-repeated-words"],
});
```

## Configuring text parser language

```bash
Expand Down
42 changes: 11 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"remark-parse": "^10.0.1",
"remark-rehype": "^10.1.0",
"retext-english": "^4.1.0",
"unified": "^10.1.2"
"unified": "^10.1.2",
"vfile-reporter": "^7.0.4"
},
"devDependencies": {
"@11ty/eleventy": "^1.0.2",
Expand All @@ -59,8 +60,7 @@
"retext-repeated-words": "^4.2.0",
"semantic-release": "^19.0.5",
"to-mock": "^1.6.2",
"unist-util-visit": "^4.1.1",
"vfile-reporter": "^7.0.4"
"unist-util-visit": "^4.1.1"
},
"release": {
"branches": [
Expand Down
2 changes: 1 addition & 1 deletion src/rehype.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default async function rehype(
htmlTransforms,
textTransforms,
textParser = "retext-english",
reporter,
reporter = "vfile-reporter",
transformsDirectory,
pageContext,
eleventyConfig,
Expand Down
46 changes: 46 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@ test.serial("reporter › console.logs", async (assert) => {
});
});

test.serial("reporter › default reporter", async (assert) => {
await new Promise((resolve) => {
const MockedConsole = toMock(global.console);
const RealConsole = global.console;
MockedConsole.log = (log) => {
assert.truthy(log.includes("once, not twice"));
global.console = RealConsole;
resolve();
};
const eleventyConfig = {
addTransform: async (type, render) => {
const context = { inputPath: "index.md", outputPath: "index.html" };
await render.call(context, "<p>and and</p>");
},
};

global.console = MockedConsole;
index(eleventyConfig, {
textTransforms: ["retext-repeated-words"],
});
});
});

test.serial("reporter › vfile-reporter", async (assert) => {
await new Promise((resolve) => {
const MockedConsole = toMock(global.console);
Expand All @@ -134,3 +157,26 @@ test.serial("reporter › vfile-reporter", async (assert) => {
});
});
});

test.serial("reporter › disable reporter", async (assert) => {
const MockedConsole = toMock(global.console);
const RealConsole = global.console;
let consoleWasCalled = false;
MockedConsole.log = () => {
global.console = RealConsole;
consoleWasCalled = true;
};
const eleventyConfig = {
addTransform: async (type, render) => {
const context = { inputPath: "index.md", outputPath: "index.html" };
await render.call(context, "<p>and and</p>");
},
};

global.console = MockedConsole;
index(eleventyConfig, {
reporter: false,
textTransforms: ["retext-repeated-words"],
});
assert.false(consoleWasCalled);
});

0 comments on commit 499e3d7

Please sign in to comment.