Skip to content

Commit

Permalink
Set up linting of snippets in MarkDown
Browse files Browse the repository at this point in the history
Add `@eslint/markdown` as a dependency to be able to lint snippets in
MarkDown files using ESLint. Add it as a plugin to the ESlint config
along with some configuration based on current violations. Also, update
the snippets of the project according to the (applicable) violations.
  • Loading branch information
ericcornelissen committed Dec 19, 2024
1 parent 248fe8f commit 1f7f84d
Show file tree
Hide file tree
Showing 7 changed files with 1,077 additions and 45 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ Parameterized tests in this project are written by looping over a list and
running a test (or multiple tests) in each iteration of the loop. For example:

```javascript
for (const case of cases) {
test(`parameterized test, ${case.name}`, (t) => {
t.is(functionUnderTest(case.input), case.expected);
for (const { name, input, expected } of cases) {
test(`parameterized test, ${name}`, (t) => {
t.is(functionUnderTest(input), expected);
});
}
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ opening [an issue].
3. Initialize `Shescape`.

```javascript
const shescape = new Shescape(/* options */);
const shescape = new Shescape(/* Options */);
```

4. Use `shescape`.
Expand Down
22 changes: 22 additions & 0 deletions config/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ava from "eslint-plugin-ava";
import depend from "eslint-plugin-depend";
import jsdoc from "eslint-plugin-jsdoc";
import json from "@eslint/json";
import markdown from "@eslint/markdown";
import regexp from "eslint-plugin-regexp";
import top from "@ericcornelissen/eslint-plugin-top";
import unicorn from "eslint-plugin-unicorn";
Expand Down Expand Up @@ -1086,6 +1087,26 @@ export default [
"yml/vue-custom-block/no-parsing-error": ["off"],
},
},
{
name: "Documentation Snippets",
files: ["**/*.md/*.js"],
rules: {
"id-length": ["off"],
"no-console": ["off"],
"no-magic-numbers": ["off"],

// https://github.com/gajus/eslint-plugin-jsdoc#readme
"jsdoc/require-description-complete-sentence": ["off"],
"jsdoc/require-returns-check": ["off"],
"jsdoc/require-file-overview": ["off"],
"jsdoc/require-jsdoc": ["off"],
"jsdoc/valid-types": ["off"],

// https://github.com/sindresorhus/eslint-plugin-unicorn#readme
"unicorn/filename-case": ["off"],
"unicorn/switch-case-braces": ["off"],
},
},
{
ignores: [
"_reports/",
Expand All @@ -1097,5 +1118,6 @@ export default [
],
},

...markdown.configs.processor,
...yml.configs["flat/base"],
];
16 changes: 8 additions & 8 deletions docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const shescape = new Shescape({
});

/* 2. Collect user input */
const userInput = "\x00world";
const userInput = "\u0000world";

/* 3. Execute shell command */
execFile(
Expand Down Expand Up @@ -277,7 +277,7 @@ const shescape = new Shescape({
});

/* 2. Collect user input */
const userInput = "\x00world";
const userInput = "\u0000world";

/* 3. Execute shell command */
try {
Expand Down Expand Up @@ -347,7 +347,7 @@ When using `child_process.fork` without the `options` argument, use
`Shescape#escapeAll` to escape all `args`.

```javascript
// echo.js
// File: echo.js

import { fork } from "node:child_process";
import { argv } from "node:process";
Expand All @@ -363,7 +363,7 @@ if (argv[2] === "Hello") {
});

/* 2. Collect user input */
const userInput = "\x00world";
const userInput = "\u0000world";

/* 3. Execute a Node.js module */
const echo = fork("echo.js", shescape.escapeAll(["Hello", userInput, "!"]));
Expand All @@ -379,7 +379,7 @@ When using `child_process.fork` with the `options` argument, use
`Shescape#escapeAll` to escape all `args`.

```javascript
// echo.js
// File: echo.js

import { fork } from "node:child_process";
import { argv } from "node:process";
Expand All @@ -400,7 +400,7 @@ if (argv[2] === "Hello") {
});

/* 2. Collect user input */
const userInput = "\x00world";
const userInput = "\u0000world";

/* 3. Execute a Node.js module */
const echo = fork(
Expand Down Expand Up @@ -431,7 +431,7 @@ const shescape = new Shescape({
});

/* 2. Collect user input */
const userInput = "\x00world";
const userInput = "\u0000world";

/* 3. Execute shell command */
const echo = spawn("echo", shescape.escapeAll(["Hello", userInput, "!"]));
Expand Down Expand Up @@ -503,7 +503,7 @@ const shescape = new Shescape({
});

/* 2. Collect user input */
const userInput = "\x00world";
const userInput = "\u0000world";

/* 3. Execute shell command */
const echo = spawnSync("echo", shescape.escapeAll(["Hello", userInput, "!"]));
Expand Down
2 changes: 1 addition & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ usage may lead to a false belief that Shescape is being used effectively.
In contrast to stubs, these values should be used in tests that invoke Shescape.

```javascript
// my-module.test.js
// File: my-module.test.js

import assert from "node:assert";
import { injectionStrings } from "shescape/testing";
Expand Down
Loading

0 comments on commit 1f7f84d

Please sign in to comment.