Skip to content

Commit 9718a97

Browse files
authored
refactor: remove unnecessary code in flat-eslint.js (#17308)
1 parent 1866e1d commit 9718a97

File tree

1 file changed

+2
-104
lines changed

1 file changed

+2
-104
lines changed

lib/eslint/flat-eslint.js

Lines changed: 2 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -132,33 +132,6 @@ function calculateStatsPerFile(messages) {
132132
return stat;
133133
}
134134

135-
/**
136-
* It will calculate the error and warning count for collection of results from all files
137-
* @param {LintResult[]} results Collection of messages from all the files
138-
* @returns {Object} Contains the stats
139-
* @private
140-
*/
141-
function calculateStatsPerRun(results) {
142-
const stat = {
143-
errorCount: 0,
144-
fatalErrorCount: 0,
145-
warningCount: 0,
146-
fixableErrorCount: 0,
147-
fixableWarningCount: 0
148-
};
149-
150-
for (let i = 0; i < results.length; i++) {
151-
const result = results[i];
152-
153-
stat.errorCount += result.errorCount;
154-
stat.fatalErrorCount += result.fatalErrorCount;
155-
stat.warningCount += result.warningCount;
156-
stat.fixableErrorCount += result.fixableErrorCount;
157-
stat.fixableWarningCount += result.fixableWarningCount;
158-
}
159-
return stat;
160-
}
161-
162135
/**
163136
* Create rulesMeta object.
164137
* @param {Map<string,Rule>} rules a map of rules from which to generate the object.
@@ -558,43 +531,6 @@ function shouldMessageBeFixed(message, config, fixTypes) {
558531
return Boolean(rule && rule.meta && fixTypes.has(rule.meta.type));
559532
}
560533

561-
/**
562-
* Collect used deprecated rules.
563-
* @param {Array<FlatConfig>} configs The configs to evaluate.
564-
* @returns {IterableIterator<DeprecatedRuleInfo>} Used deprecated rules.
565-
*/
566-
function *iterateRuleDeprecationWarnings(configs) {
567-
const processedRuleIds = new Set();
568-
569-
for (const config of configs) {
570-
for (const [ruleId, ruleConfig] of Object.entries(config.rules)) {
571-
572-
// Skip if it was processed.
573-
if (processedRuleIds.has(ruleId)) {
574-
continue;
575-
}
576-
processedRuleIds.add(ruleId);
577-
578-
// Skip if it's not used.
579-
if (!getRuleSeverity(ruleConfig)) {
580-
continue;
581-
}
582-
const rule = getRuleFromConfig(ruleId, config);
583-
584-
// Skip if it's not deprecated.
585-
if (!(rule && rule.meta && rule.meta.deprecated)) {
586-
continue;
587-
}
588-
589-
// This rule was used and deprecated.
590-
yield {
591-
ruleId,
592-
replacedBy: rule.meta.replacedBy || []
593-
};
594-
}
595-
}
596-
}
597-
598534
/**
599535
* Creates an error to be thrown when an array of results passed to `getRulesMetaForResults` was not created by the current engine.
600536
* @returns {TypeError} An error object.
@@ -819,7 +755,6 @@ class FlatESLint {
819755
errorOnUnmatchedPattern
820756
} = eslintOptions;
821757
const startTime = Date.now();
822-
const usedConfigs = [];
823758
const fixTypesSet = fixTypes ? new Set(fixTypes) : null;
824759

825760
// Delete cache file; should this be done here?
@@ -877,15 +812,6 @@ class FlatESLint {
877812
return void 0;
878813
}
879814

880-
/*
881-
* Store used configs for:
882-
* - this method uses to collect used deprecated rules.
883-
* - `--fix-type` option uses to get the loaded rule's meta data.
884-
*/
885-
if (!usedConfigs.includes(config)) {
886-
usedConfigs.push(config);
887-
}
888-
889815
// Skip if there is cached result.
890816
if (lintResultCache) {
891817
const cachedResult =
@@ -954,22 +880,10 @@ class FlatESLint {
954880
lintResultCache.reconcile();
955881
}
956882

957-
let usedDeprecatedRules;
958883
const finalResults = results.filter(result => !!result);
959884

960885
return processLintReport(this, {
961-
results: finalResults,
962-
...calculateStatsPerRun(finalResults),
963-
964-
// Initialize it lazily because CLI and `ESLint` API don't use it.
965-
get usedDeprecatedRules() {
966-
if (!usedDeprecatedRules) {
967-
usedDeprecatedRules = Array.from(
968-
iterateRuleDeprecationWarnings(usedConfigs)
969-
);
970-
}
971-
return usedDeprecatedRules;
972-
}
886+
results: finalResults
973887
});
974888
}
975889

@@ -1031,7 +945,6 @@ class FlatESLint {
1031945
const results = [];
1032946
const startTime = Date.now();
1033947
const resolvedFilename = path.resolve(cwd, filePath || "__placeholder__.js");
1034-
let config;
1035948

1036949
// Clear the last used config arrays.
1037950
if (resolvedFilename && await this.isPathIgnored(resolvedFilename)) {
@@ -1040,9 +953,6 @@ class FlatESLint {
1040953
}
1041954
} else {
1042955

1043-
// TODO: Needed?
1044-
config = configs.getConfig(resolvedFilename);
1045-
1046956
// Do lint.
1047957
results.push(verifyText({
1048958
text: code,
@@ -1057,21 +967,9 @@ class FlatESLint {
1057967
}
1058968

1059969
debug(`Linting complete in: ${Date.now() - startTime}ms`);
1060-
let usedDeprecatedRules;
1061970

1062971
return processLintReport(this, {
1063-
results,
1064-
...calculateStatsPerRun(results),
1065-
1066-
// Initialize it lazily because CLI and `ESLint` API don't use it.
1067-
get usedDeprecatedRules() {
1068-
if (!usedDeprecatedRules) {
1069-
usedDeprecatedRules = Array.from(
1070-
iterateRuleDeprecationWarnings(config)
1071-
);
1072-
}
1073-
return usedDeprecatedRules;
1074-
}
972+
results
1075973
});
1076974

1077975
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy