Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes for eslint.codeActionsOnSave.rules mechanism #1364

Merged
merged 5 commits into from
Nov 18, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 25 additions & 23 deletions server/src/eslintServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,30 +562,29 @@ async function getSaveRuleConfig(filePath: string, settings: TextDocumentSetting
return result;
}
const rules = settings.codeActionOnSave.rules;
if (rules === undefined || !ESLintModule.hasESLintClass(settings.library) || !settings.useESLintClass) {
result = undefined;
} else {
result = await withESLintClass(async (eslint) => {
const config = await eslint.calculateConfigForFile(filePath);
if (config === undefined || config.rules === undefined || config.rules.length === 0) {
return undefined;
}
const offRules: Set<string> = new Set();
const onRules: Set<string> = new Set();
if (rules.length === 0) {
Object.keys(config.rules).forEach(ruleId => offRules.add(ruleId));
} else {
for (const ruleId of Object.keys(config.rules)) {
if (isOff(ruleId, rules)) {
offRules.add(ruleId);
} else {
onRules.add(ruleId);
}
result = await withESLintClass(async (eslint) => {
if (rules === undefined || eslint.isCLIEngine) {
return undefined;
}
const config = await eslint.calculateConfigForFile(filePath);
if (config === undefined || config.rules === undefined || config.rules.length === 0) {
return undefined;
}
const offRules: Set<string> = new Set();
const onRules: Set<string> = new Set();
if (rules.length === 0) {
Object.keys(config.rules).forEach(ruleId => offRules.add(ruleId));
} else {
for (const ruleId of Object.keys(config.rules)) {
if (isOff(ruleId, rules)) {
offRules.add(ruleId);
} else {
onRules.add(ruleId);
}
}
return offRules.size > 0 ? { offRules, onRules } : undefined;
}, settings);
}
}
return offRules.size > 0 ? { offRules, onRules } : undefined;
}, settings);
if (result === undefined || result === null) {
saveRuleConfigCache.set(filePath, null);
return undefined;
Expand Down Expand Up @@ -1447,7 +1446,10 @@ function setupDocumentsListeners() {
void resolveSettings(event.document).then((settings) => {
const uri = event.document.uri;
document2Settings.delete(uri);
saveRuleConfigCache.delete(uri);
const filePath = getFilePath(uri);
if (filePath) {
saveRuleConfigCache.delete(filePath);
}
codeActions.delete(uri);
const unregister = formatterRegistrations.get(event.document.uri);
if (unregister !== undefined) {
Expand Down