Skip to content

Commit a6dc873

Browse files
authored
feat: load textlint config automatically (#90)
1 parent 2a999ec commit a6dc873

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.changeset/fuzzy-lemons-camp.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-text": patch
3+
---
4+
5+
feat: load textlint config automatically

packages/text/src/worker.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import type { TextlintResult, TextlintFixResult } from '@textlint/kernel'
55
import { cosmiconfig } from 'cosmiconfig'
66
import type { CosmiconfigResult } from 'cosmiconfig/dist/types'
77
import { extractProperties, runAsWorker } from 'synckit'
8-
import { textlint } from 'textlint'
8+
import { TextLintCore } from 'textlint'
9+
import { Config } from 'textlint/lib/src/config/config'
910
import type { FrozenProcessor, Plugin } from 'unified'
1011
import type { VFileMessage } from 'vfile-message'
1112

@@ -93,6 +94,8 @@ export const isTextlintFixResult = (
9394
result: TextlintResult,
9495
): result is TextlintFixResult => 'output' in result
9596

97+
const textlintCache = new Map<string, TextLintCore>()
98+
9699
runAsWorker(
97100
async ({
98101
text,
@@ -124,6 +127,19 @@ runAsWorker(
124127
}
125128
}
126129
case 'textlint': {
130+
let textlint: TextLintCore
131+
132+
if (textlintCache.has(filename)) {
133+
textlint = textlintCache.get(filename)!
134+
} else {
135+
const textlintConfig = Config.initWithAutoLoading({
136+
cwd: path.dirname(filename),
137+
})
138+
139+
textlint = new TextLintCore(textlintConfig)
140+
textlintCache.set(filename, textlint)
141+
}
142+
127143
const result: TextlintFixResult | TextlintResult = await textlint[
128144
fix ? 'fixText' : 'lintText'
129145
](text, path.extname(filename))

0 commit comments

Comments
 (0)