Skip to content

Commit 9370efd

Browse files
authored
Merge pull request #16 from dwyl/v3
[PR] Migrate to `v3`
2 parents 322f93e + 4f05979 commit 9370efd

File tree

146 files changed

+9145
-18453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+9145
-18453
lines changed

.github/workflows/ci.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ jobs:
2323
- name: Install dependencies
2424
run: pnpm install --no-frozen-lockfile
2525

26-
# Run `markdownlint-cli2` to lint markdown files
26+
# Run `markdownlint-cli2` to lint markdown files (checks dead links with `remark-lint-no-dead-urls`)
2727
- name: Running `markdownlint-cli2`
2828
run: pnpm run lint:check-markdown
2929

30-
# Run script to check for dead links
31-
- name: Checking for dead links
32-
run: pnpm run lint:check-external-links
33-
3430
# Run build
3531
- name: Build Next.js app
3632
run: pnpm run build

.remarkignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# `_app.mdx` and `index.mdx` files are essentially `.js` files that don't need linting.
2+
src/**/_app.mdx
3+
src/**/index.mdx
4+
5+
# Parked/archived directories won't be linted
6+
src/**/**/_*
7+
8+
9+
# Linting rules don't need to apply to `README.md`, only for documentation
10+
README.md

contentlayer.config.js

-29
This file was deleted.

jest.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const config: Config = {
1515
setupFiles: ["./jest.polyfills.js"],
1616

1717
collectCoverage: true,
18-
collectCoverageFrom: ["src/**/*.{js,jsx,ts,tsx}", "scripts/*.{mjs,js,jsx,ts,tsx}", "!<rootDir>/node_modules/"],
18+
collectCoverageFrom: ["src/**/*.{js,jsx,ts,tsx}", "scripts/*.{mjs,js,jsx,ts,tsx}", "!<rootDir>/node_modules/", "!src/generatePrivateRoutes.ts"],
1919
coverageDirectory: "coverage",
2020
coveragePathIgnorePatterns: ["/node_modules/"],
2121
coverageProvider: "v8",
@@ -44,7 +44,7 @@ const config: Config = {
4444
},
4545

4646
testEnvironment: "jsdom",
47-
testPathIgnorePatterns: ["tests/e2e"],
47+
testPathIgnorePatterns: ["tests/e2e", "tests/unit/link-check.test.ts"],
4848
};
4949

5050
export default createJestConfig(config);

lint/lint.mjs

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import yargs from "yargs";
4+
import ignore from "ignore";
5+
import { glob } from "glob";
6+
import { remark } from "remark";
7+
import { reporter } from "vfile-reporter";
8+
import { hideBin } from "yargs/helpers";
9+
import {read} from 'to-vfile'
10+
11+
// Counter to keep track of total warnings
12+
let totalWarnings = 0;
13+
14+
/**
15+
* Load and parse the .remarkignore file.
16+
* @param {string} path path to the ignore file.
17+
* @returns {Promise<ignore>} A promise that resolves with the ignore instance.
18+
*/
19+
async function loadIgnoreFile(path) {
20+
try {
21+
const ignoreFileContent = fs.readFileSync(path, "utf-8");
22+
const ig = ignore().add(ignoreFileContent);
23+
return ig;
24+
} catch (err) {
25+
console.warn("No .remarkignore file found, proceeding without ignoring files.");
26+
return ignore();
27+
}
28+
}
29+
30+
/**
31+
* Process a single file with the given preset and formatting flag.
32+
* @param {string} filePath The path to the file
33+
* @param {string} preset The preset object to use for linting with array of remark plugins
34+
* @param {boolean} shouldFormat Flag to indicate whether formatting (changing markdown files) should be applied
35+
*/
36+
async function formatSingleFile(filePath, preset, shouldFormat) {
37+
try {
38+
// Create a virtual file with metadata like `stem`.
39+
// This is needed for rules related to files.
40+
const vfile = await read(filePath);
41+
42+
// Process the file with the given preset
43+
const file = await remark().use(preset).process(vfile);
44+
45+
// Check if there are any issues
46+
const issues = file.messages.length;
47+
48+
// Print the issues
49+
if (issues === 0) {
50+
console.log(`${filePath}: no issues found`);
51+
} else {
52+
totalWarnings += file.messages.length;
53+
console.error(reporter(file));
54+
}
55+
56+
// Write the file back if formatting is enabled
57+
if (shouldFormat) {
58+
fs.writeFileSync(filePath, file.value.toString());
59+
}
60+
} catch (err) {
61+
console.error(`Error processing file ${filePath}:`, err);
62+
}
63+
}
64+
65+
// Main function to handle glob pattern and process files
66+
/**
67+
* Process files based on the given pattern, preset, and formatting flag.
68+
* @param {string} pattern The glob pattern to match files.
69+
* @param {string} pattern The path to the ignore file.
70+
* @param {string} preset The path to the preset object to use for linting with array of remark plugins.
71+
* @param {boolean} shouldFormat Flag to indicate whether formatting (changing markdown files) should be applied.
72+
* @param {boolean} failOnError Flag to indicate whether to fail command if any error is found.
73+
* @returns {Promise<void>} A promise that resolves when all files are processed.
74+
*/
75+
export async function processFiles(pattern, ignoreFile, preset, shouldFormat, failOnError) {
76+
try {
77+
// Load the ignore file and get the list of files
78+
const ig = await loadIgnoreFile(ignoreFile);
79+
const files = await glob(pattern);
80+
81+
if (files.length === 0) {
82+
console.log("No files matched the given pattern.");
83+
return;
84+
}
85+
86+
// Filter out files that are ignored
87+
const filteredFiles = files.filter((file) => !ig.ignores(file));
88+
89+
if (filteredFiles.length === 0) {
90+
console.log("All matched files are ignored.");
91+
return;
92+
}
93+
94+
// Process each file
95+
for (const file of filteredFiles) {
96+
await formatSingleFile(file, preset, shouldFormat);
97+
}
98+
99+
// Print total warnings and fail command if needed
100+
if (totalWarnings > 0) {
101+
console.log(`⚠️ Total ${totalWarnings} warning(s)`);
102+
if (failOnError) {
103+
process.exit(1);
104+
}
105+
}
106+
} catch (err) {
107+
console.error("Error during file processing:", err);
108+
}
109+
}
110+
111+
// Use yargs to handle command-line arguments
112+
const argv = yargs(hideBin(process.argv))
113+
.option("pattern", {
114+
alias: "p",
115+
type: "string",
116+
description: "Glob pattern to match files",
117+
demandOption: true,
118+
})
119+
.option("preset", {
120+
alias: "r",
121+
type: "string",
122+
description: "Path to the preset file",
123+
demandOption: true,
124+
})
125+
.option("ignoreFile", {
126+
alias: "i",
127+
type: "string",
128+
description: "Path to the ignore file",
129+
demandOption: false,
130+
})
131+
.option("format", {
132+
alias: "f",
133+
type: "boolean",
134+
description: "Flag to indicate whether formatting should be applied",
135+
default: false,
136+
})
137+
.option("failOnError", {
138+
alias: "e",
139+
type: "boolean",
140+
description: "Flag to indicate whether to fail command if any error is found",
141+
default: false,
142+
}).argv;
143+
144+
// Dynamically import the preset file
145+
const presetPath = path.resolve(argv.preset);
146+
import(presetPath)
147+
.then((preset) =>
148+
// Start processing files
149+
processFiles(argv.pattern, argv.ignoreFile, preset.default, argv.format, argv.failOnError)
150+
);
151+

lint/remark-preset.mjs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import remarkMdx from "remark-mdx";
2+
import remarkGfm from "remark-gfm";
3+
import remarkLint from "remark-lint";
4+
import remarkValidateLinks from "remark-validate-links";
5+
import remarkLintNoDeadUrls from "remark-lint-no-dead-urls"
6+
7+
// This configuration file is meant to be used in `remark CLI` to check for warnings.
8+
// This means that if any of these fail, the command still succeeds.
9+
// See https://github.com/unifiedjs/unified-engine#options for the options.
10+
const remarkPreset = {
11+
plugins: [
12+
// Support `mdx` and GFM
13+
remarkMdx, // https://mdxjs.com/packages/remark-mdx/
14+
remarkGfm, // https://github.com/remarkjs/remark-gfm
15+
16+
// Introduce remark linting rules
17+
remarkLint,
18+
19+
// Validating URLs
20+
remarkValidateLinks, // https://github.com/remarkjs/remark-validate-links
21+
remarkLintNoDeadUrls // https://github.com/remarkjs/remark-lint-no-dead-urls
22+
],
23+
// Override `remark-stringify` rules when serializing text.
24+
// See https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options for options.
25+
settings: {
26+
emphasis: "_",
27+
strong: "*",
28+
bullet: "-",
29+
},
30+
};
31+
32+
export default remarkPreset;

next-env.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
/// <reference types="next/navigation-types/compat/navigation" />
44

55
// NOTE: This file should not be edited
6-
// see https://nextjs.org/docs/basic-features/typescript for more information.
6+
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.

next.config.js

-10
This file was deleted.

next.config.mjs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import withPlugins from 'next-compose-plugins';
3+
import nextra from 'nextra'
4+
5+
const withNextra = nextra({
6+
theme: "./theme/src/index.tsx",
7+
themeConfig: "./theme.config.tsx",
8+
defaultShowCopyCode: true,
9+
})
10+
11+
12+
export default withPlugins([withNextra]);

0 commit comments

Comments
 (0)