Skip to content

Commit d974efa

Browse files
committed
perf: use env.updateFile API
1 parent 435cbf7 commit d974efa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lint-rules/validate-jsdoc-codeblocks.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export const validateJSDocCodeblocksRule = /** @type {const} */ ({
3838
const allComments = context.sourceCode.getAllComments();
3939

4040
const virtualFsMap = new Map();
41+
virtualFsMap.set(FILENAME, '// Can\'t be empty');
42+
4143
const system = createFSBackedSystem(virtualFsMap, context.cwd, ts);
44+
const env = createVirtualTypeScriptEnvironment(system, [FILENAME], ts, compilerOptions);
4245

4346
return {
4447
Program() {
@@ -64,8 +67,7 @@ export const validateJSDocCodeblocksRule = /** @type {const} */ ({
6467
const matchOffset = match.index + openingFence.length + 2; // Add `2` because `comment.value` doesn't include the starting `/*`
6568
const codeStartIndex = comment.range[0] + matchOffset;
6669

67-
virtualFsMap.set(FILENAME, code);
68-
const env = createVirtualTypeScriptEnvironment(system, [FILENAME], ts, compilerOptions);
70+
env.updateFile(FILENAME, code);
6971
const syntacticDiagnostics = env.languageService.getSyntacticDiagnostics(FILENAME);
7072
const semanticDiagnostics = env.languageService.getSemanticDiagnostics(FILENAME);
7173
const diagnostics = syntacticDiagnostics.length > 0 ? syntacticDiagnostics : semanticDiagnostics; // Show semantic errors only if there are no syntactic errors

0 commit comments

Comments
 (0)