Skip to content

Commit 5a8dad1

Browse files
committed
Add linting and code snippet validation for docs
1 parent 99fcdf4 commit 5a8dad1

File tree

7 files changed

+17434
-23
lines changed

7 files changed

+17434
-23
lines changed

Diff for: .eslintrc.cjs

+29-20
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
/* eslint-env node */
22

3-
const CODE_EXT = "js,jsx,cjs,mjs,ts,tsx,cts,mts"
4-
5-
const MARKDOWN_EXT = "md,mdx"
3+
const CODE_EXT = "js,jsx,cjs,mjs,ts,tsx,cts,mts";
4+
const MARKDOWN_EXT = "md,mdx";
65

76
module.exports = {
87
root: true,
8+
plugins: ["@graphql-eslint", "mdx", "@typescript-eslint", "tailwindcss"],
99
overrides: [
1010
{
1111
files: [`**/*.{${CODE_EXT}}`],
12-
// TODO: extract graphql documents from code files
13-
// to lint graphql documents marked with /* GraphQL */ comments inside js/ts codeblocks in markdown
14-
// processor: '@graphql-eslint/graphql',
15-
// plugins: ['@graphql-eslint'],
1612
extends: [
1713
"eslint:recommended",
1814
"plugin:@typescript-eslint/recommended",
@@ -34,7 +30,6 @@ module.exports = {
3430
},
3531
],
3632
"prefer-const": ["error", { destructuring: "all" }],
37-
// TODO: fix below
3833
"prefer-rest-params": "off",
3934
"@typescript-eslint/no-explicit-any": "off",
4035
"@typescript-eslint/no-unused-vars": "off",
@@ -51,27 +46,45 @@ module.exports = {
5146
{
5247
files: [`**/*.{${MARKDOWN_EXT}}`],
5348
parser: "eslint-mdx",
49+
extends: ["plugin:mdx/recommended"],
5450
processor: "mdx/remark",
55-
plugins: ["mdx"],
5651
parserOptions: {
5752
ecmaVersion: 13,
5853
sourceType: "module",
5954
},
6055
settings: {
6156
"mdx/code-blocks": true,
57+
"mdx/language-mapper": {
58+
js: "espree",
59+
graphql: "@graphql-eslint/parser",
60+
ts: "@typescript-eslint/parser",
61+
typescript: "@typescript-eslint/parser",
62+
},
6263
},
6364
rules: {
6465
"mdx/remark": "error",
6566
},
6667
},
6768
{
68-
files: [`**/*.{${MARKDOWN_EXT}}/*.{${CODE_EXT}}`],
69+
files: ["**/*.graphql"],
70+
parser: "@graphql-eslint/parser",
6971
rules: {
70-
"no-unused-labels": "off",
71-
"no-undef": "off",
72-
"no-redeclare": "off",
73-
"no-import-assign": "off",
74-
"no-prototype-builtins": "off",
72+
"@graphql-eslint/no-syntax-errors": "error",
73+
"@graphql-eslint/unique-operation-name": "error",
74+
"@graphql-eslint/unique-fragment-name": "error",
75+
"@graphql-eslint/no-anonymous-operations": "warn",
76+
"@graphql-eslint/lone-anonymous-operation": "error",
77+
"@graphql-eslint/no-duplicate-fields": "error",
78+
"@graphql-eslint/no-unused-fragments": "warn",
79+
"@graphql-eslint/no-duplicate-fragment-names": "error",
80+
"@graphql-eslint/no-undefined-variables": "error",
81+
"@graphql-eslint/unique-variable-names": "error"
82+
},
83+
},
84+
{
85+
files: [`**/*.{${CODE_EXT}}`, `**/*.{${MARKDOWN_EXT}}`],
86+
parserOptions: {
87+
plugins: ["graphql"],
7588
},
7689
},
7790
{
@@ -84,9 +97,5 @@ module.exports = {
8497
"mdx/remark": "off",
8598
},
8699
},
87-
{
88-
files: ["**/*.graphql"],
89-
parser: "@graphql-eslint/eslint-plugin",
90-
},
91100
],
92-
}
101+
};

Diff for: .github/workflows/docs-validation.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Docs validation workflow runs on each PR on main w/ broken link checker
2+
# and code snippet validation
3+
4+
name: Docs validation
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- main
10+
push:
11+
branches:
12+
- main
13+
14+
jobs:
15+
link-check:
16+
name: Broken link checker
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Rust
24+
uses: actions-rs/toolchain@v1
25+
with:
26+
toolchain: stable
27+
28+
- name: Install lychee
29+
run: cargo install lychee
30+
31+
- name: Check links
32+
run: lychee --verbose --no-progress './src/pages/learn/**/*.mdx' --base https://graphql.org
33+
34+
code-validate:
35+
name: Code snippet and GraphQL validation
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- uses: actions/setup-node@v4
41+
with:
42+
node-version: "20"
43+
44+
- name: Install dependencies
45+
run: npm ci
46+
47+
- name: Run validation w/ annotations
48+
run: npm run lint:docs:ci
49+
50+
- name: Validate code snippets
51+
run: npm run validate:snippets

0 commit comments

Comments
 (0)