Skip to content

Commit

Permalink
Fixes #1745: There are some issues with the rules @stylistic/arrow-pa…
Browse files Browse the repository at this point in the history
…rens and @stylistic/space-before-function-paren when running in the ESLint plugin for VSCode (#1748)
  • Loading branch information
dbaeumer authored Dec 11, 2023
1 parent 8c2c4c4 commit ffecaee
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions server/src/eslintServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,6 @@ async function computeAllFixes(identifier: VersionedTextDocumentIdentifier, mode
} else {
const saveConfig = filePath !== undefined && mode === AllFixesMode.onSave ? await SaveRuleConfigs.get(uri, settings) : undefined;
const offRules = saveConfig?.offRules;
const onRules = saveConfig?.onRules;
let overrideConfig: Required<ConfigData> | undefined;
if (offRules !== undefined) {
overrideConfig = { rules: Object.create(null) };
Expand All @@ -979,26 +978,10 @@ async function computeAllFixes(identifier: VersionedTextDocumentIdentifier, mode
}
}
return ESLint.withClass(async (eslintClass) => {
// Don't use any precomputed fixes since neighbour fixes can produce incorrect results.
// See https://github.com/microsoft/vscode-eslint/issues/1745
const result: TextEdit[] = [];
let fixes: TextEdit[] | undefined;
if (problems !== undefined && problems.size > 0) {
// We have override rules that turn rules off. Filter the fixes for these rules.
if (offRules !== undefined) {
const filtered: typeof problems = new Map();
for (const [key, problem] of problems) {
if (onRules?.has(problem.ruleId)) {
filtered.set(key, problem);
}
}
fixes = filtered.size > 0 ? new Fixes(filtered).getApplicable().map(fix => FixableProblem.createTextEdit(textDocument, fix)) : undefined;
} else {
fixes = new Fixes(problems).getApplicable().map(fix => FixableProblem.createTextEdit(textDocument, fix));
}
}
const content = fixes !== undefined
? TextDocument.applyEdits(textDocument, fixes)
: originalContent;
const reportResults = await eslintClass.lintText(content, { filePath });
const reportResults = await eslintClass.lintText(originalContent, { filePath });
connection.tracer.log(`Computing all fixes took: ${Date.now() - start} ms.`);
if (Array.isArray(reportResults) && reportResults.length === 1 && reportResults[0].output !== undefined) {
const fixedContent = reportResults[0].output;
Expand All @@ -1014,8 +997,6 @@ async function computeAllFixes(identifier: VersionedTextDocumentIdentifier, mode
newText: fixedContent.substr(diff.modifiedStart, diff.modifiedLength)
});
}
} else if (fixes !== undefined) {
result.push(...fixes);
}
return result;
}, settings, overrideConfig !== undefined ? { fix: true, overrideConfig } : { fix: true });
Expand Down

0 comments on commit ffecaee

Please sign in to comment.