Skip to content

Commit 2ec8313

Browse files
committed
feat: respect .remarkignore at the same time
close #502
1 parent 2672044 commit 2ec8313

File tree

2 files changed

+96
-2
lines changed

2 files changed

+96
-2
lines changed

Diff for: packages/eslint-mdx/src/worker.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import remarkStringify from 'remark-stringify'
3737
import { extractProperties, runAsWorker } from 'synckit'
3838
import { unified, type Processor } from 'unified'
3939
import type { ConfigResult } from 'unified-engine'
40-
import { Configuration } from 'unified-engine'
40+
import { Configuration, Ignore } from 'unified-engine'
4141
import type { Node } from 'unist'
4242
import { visit } from 'unist-util-visit'
4343
import { ok as assert } from 'uvu/assert'
@@ -73,12 +73,20 @@ export const processorCache = new Map<
7373
Processor<Root, undefined, undefined, Root, string>
7474
>()
7575

76+
let cwd: string
77+
7678
let configLoad: (filePath: string) => Promise<ConfigResult>
7779

80+
let ignoreCheck: (filePath: string) => Promise<boolean>
81+
7882
const getRemarkConfig = async (filePath: string) => {
83+
if (!cwd) {
84+
cwd = process.cwd()
85+
}
86+
7987
if (!configLoad) {
8088
const config = new Configuration({
81-
cwd: process.cwd(),
89+
cwd,
8290
packageField: 'remarkConfig',
8391
pluginPrefix: 'remark',
8492
rcName: '.remarkrc',
@@ -87,6 +95,15 @@ const getRemarkConfig = async (filePath: string) => {
8795
configLoad = promisify(config.load.bind(config))
8896
}
8997

98+
if (!ignoreCheck) {
99+
const ignore = new Ignore({
100+
cwd,
101+
ignoreName: '.remarkignore',
102+
detectIgnore: true,
103+
})
104+
ignoreCheck = promisify(ignore.check.bind(ignore))
105+
}
106+
90107
return configLoad(filePath)
91108
}
92109

@@ -216,6 +233,12 @@ runAsWorker(
216233
}
217234

218235
if (process) {
236+
if (await ignoreCheck(filePath)) {
237+
return {
238+
messages: [],
239+
}
240+
}
241+
219242
const file = new VFile(fileOptions)
220243
try {
221244
await processor.process(file)

Diff for: patches/unified-engine+11.2.2.patch

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
diff --git a/node_modules/unified-engine/index.d.ts b/node_modules/unified-engine/index.d.ts
2+
index 1f8706e..9f1cc30 100644
3+
--- a/node_modules/unified-engine/index.d.ts
4+
+++ b/node_modules/unified-engine/index.d.ts
5+
@@ -1,4 +1,5 @@
6+
export { Configuration } from "./lib/configuration.js";
7+
+export { Ignore } from "./lib/Ignore.js";
8+
export { engine } from "./lib/index.js";
9+
export type ConfigResult = import("./lib/configuration.js").ConfigResult;
10+
export type Completer = import("./lib/file-set.js").Completer;
11+
diff --git a/node_modules/unified-engine/index.js b/node_modules/unified-engine/index.js
12+
index 4c993a8..d96f4ce 100644
13+
--- a/node_modules/unified-engine/index.js
14+
+++ b/node_modules/unified-engine/index.js
15+
@@ -13,5 +13,6 @@
16+
17+
// it’s mostly private, but useful for tools like `eslint-mdx`.
18+
export {Configuration} from './lib/configuration.js'
19+
+export {Ignore} from './lib/ignore.js'
20+
21+
export {engine} from './lib/index.js'
22+
diff --git a/node_modules/unified-engine/lib/ignore.d.ts b/node_modules/unified-engine/lib/ignore.d.ts
23+
index b2329db..7d35ff1 100644
24+
--- a/node_modules/unified-engine/lib/ignore.d.ts
25+
+++ b/node_modules/unified-engine/lib/ignore.d.ts
26+
@@ -37,19 +37,19 @@ export type Options = {
27+
/**
28+
* Whether to detect ignore files.
29+
*/
30+
- detectIgnore: boolean | undefined;
31+
+ detectIgnore?: boolean | undefined;
32+
/**
33+
* Basename of ignore files.
34+
*/
35+
- ignoreName: string | undefined;
36+
+ ignoreName?: string | undefined;
37+
/**
38+
* Explicit path to an ignore file.
39+
*/
40+
- ignorePath: URL | string | undefined;
41+
+ ignorePath?: URL | string | undefined;
42+
/**
43+
* How to resolve.
44+
*/
45+
- ignorePathResolveFrom: ResolveFrom | undefined;
46+
+ ignorePathResolveFrom?: ResolveFrom | undefined;
47+
};
48+
/**
49+
* How to resolve.
50+
diff --git a/node_modules/unified-engine/lib/ignore.js b/node_modules/unified-engine/lib/ignore.js
51+
index be6d078..da877af 100644
52+
--- a/node_modules/unified-engine/lib/ignore.js
53+
+++ b/node_modules/unified-engine/lib/ignore.js
54+
@@ -16,13 +16,13 @@
55+
* Configuration.
56+
* @property {string} cwd
57+
* Base.
58+
- * @property {boolean | undefined} detectIgnore
59+
+ * @property {boolean | undefined} [detectIgnore]
60+
* Whether to detect ignore files.
61+
- * @property {string | undefined} ignoreName
62+
+ * @property {string | undefined} [ignoreName]
63+
* Basename of ignore files.
64+
- * @property {URL | string | undefined} ignorePath
65+
+ * @property {URL | string | undefined} [ignorePath]
66+
* Explicit path to an ignore file.
67+
- * @property {ResolveFrom | undefined} ignorePathResolveFrom
68+
+ * @property {ResolveFrom | undefined} [ignorePathResolveFrom]
69+
* How to resolve.
70+
*
71+
* @typedef {'cwd' | 'dir'} ResolveFrom

0 commit comments

Comments
 (0)