-
Notifications
You must be signed in to change notification settings - Fork 336
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
Changes from all commits
63e3556
492858e
786bf9d
0527347
00c1f75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -553,44 +553,44 @@ function isOff(ruleId: string, matchers: string[]): boolean { | |
return true; | ||
} | ||
|
||
async function getSaveRuleConfig(filePath: string, settings: TextDocumentSettings & { library: ESLintModule }): Promise<SaveRuleConfigItem | undefined> { | ||
let result = saveRuleConfigCache.get(filePath); | ||
if (result === null) { | ||
async function getSaveRuleConfig(uri: string, settings: TextDocumentSettings & { library: ESLintModule }): Promise<SaveRuleConfigItem | undefined> { | ||
const filePath = getFilePath(uri); | ||
let result = saveRuleConfigCache.get(uri); | ||
if (filePath === undefined || result === null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return undefined; | ||
} | ||
if (result !== undefined) { | ||
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); | ||
saveRuleConfigCache.set(uri, null); | ||
return undefined; | ||
} else { | ||
saveRuleConfigCache.set(filePath, result); | ||
saveRuleConfigCache.set(uri, result); | ||
return result; | ||
} | ||
} | ||
|
@@ -2283,7 +2283,7 @@ async function computeAllFixes(identifier: VersionedTextDocumentIdentifier, mode | |
connection.tracer.log(`Computing all fixes took: ${Date.now() - start} ms.`); | ||
return result; | ||
} else { | ||
const saveConfig = filePath !== undefined && mode === AllFixesMode.onSave ? await getSaveRuleConfig(filePath, settings) : undefined; | ||
const saveConfig = filePath !== undefined && mode === AllFixesMode.onSave ? await getSaveRuleConfig(uri, settings) : undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only call to |
||
const offRules = saveConfig?.offRules; | ||
const onRules = saveConfig?.onRules; | ||
let overrideConfig: Required<ConfigData> | undefined; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced
filePath
argument by theuri
, as it is need here toget
andset
items onsaveRuleConfigCache
. Preferred this way instead of adding theuri
to the arguments list to keep the function signature concise.