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
Change Request: Return successfully passing rules count from lint methods of Node API #18013
Comments
Can you explain what you mean by "reflect"? It seems like the request is just for a count of rules that were run, but I'm not 100% sure based on this sentence. |
Yes, just a count of distinct rules that were run. |
And you're looking for all the rules that were executed in a single run, across all files? (As opposed to all of the rules run on a single file?) |
Right, all the rules that were executed in a single run, across all files. |
Got it. This seems like it would be easy to add, but would like @eslint/eslint-team to weigh in with other opinions before marking as accepted. |
I'm fine with this enhancement, should be easy. |
@snitin315 famous last words. :) |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
ping @eslint/eslint-team |
👍 I'm in favor |
I think we can consider adding this. However, this doesn't look like a trivial change, so I think it needs an RFC. |
If I understand correctly it is already possible with help o Node API methods: The only thing to remember is count of passed rules can vary according to overrides applied to file groups so it can be different for each file. Here is possible code example: const {readFile} = require('fs/promises');
const {ESLint} = require('eslint');
const eslint = new ESLint();
const {keys} = Object;
const files = ['/index.js', '/client.js'];
let allExecutedCount = 0;
let sallScceededRules = 0;
for (const file of files) {
const code = await readFile(file);
const config = await eslint.calculateConfigForFile(file);
const rules = keys(config.rules);
const executedRules = new Set(rules);
const succeededRules = new Set(rules);
const results = await eslint.lintText(file, config);
for (const {messages} of results) {
for (const {ruleId} of messages) {
succeededRules.delete(ruleId);
}
}
console.log(`Executed Rules Count for file '${file}': ${executedRules.size}`);
console.log(`Succeeded Rules Count for file '${file}': ${successededRules.size}`);
if (allExecutedCount < executedRules.size)
allExecutedCount = executedRules.size;
}
console.log(`All executed rules count: ${allExecutedCount}`); |
@coderaiser yes, it's possible to get that information if you're using the API directly. In this case, the request is to expose that information inside of formatters. |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
ESLint version
8.56.0
What problem do you want to solve?
Hi,
I have a formatter (at https://github.com/brettz9/eslint-formatter-badger ) which intends to print a badge indicating the number of rules failing out of how many rules are applied, but it is currently unable to get the latter (i.e., the total number of rules in effect).
The results might look like:
or:
(While it may not seem so important to have a badge to communicate linting results compared to say testing results, it does convey a sense of how much consideration went into checking the best practices (including for say security) of the code.)
The
getRulesMetaForResults
method results only indicate the failing tests, andbuiltinRules
only indicates the total rules available, not the total rules in effect.What do you think is the correct solution?
I would like a way to reflect on the successfully passing rules supplied to the ESLint constructor (e.g., with
overrideConfigFile
) so that the badge can display how many rules are passing as well as how many may be failing.I would think the value (say
totalApplicableRules
) could be returned along with otherLintResult
values such asfixableErrorCount
returned from the likes ofESLint#lintFiles
andESLint#lintText
.Participation
Additional comments
I think I should be able to the PR myself, but no guarantees.
The text was updated successfully, but these errors were encountered: