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

Change Request: Return successfully passing rules count from lint methods of Node API #18013

Open
1 task done
brettz9 opened this issue Jan 19, 2024 · 14 comments
Open
1 task done
Labels
core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint needs design Important details about this change need to be discussed Stale

Comments

@brettz9
Copy link
Contributor

brettz9 commented Jan 19, 2024

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:

cli-no-failures

or:

cli-1-failing-suggestion-medium-percentage-threshold-plural

(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, and builtinRules 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 other LintResult values such as fixableErrorCount returned from the likes of ESLint#lintFiles and ESLint#lintText.

Participation

  • I am willing to submit a pull request for this change.

Additional comments

I think I should be able to the PR myself, but no guarantees.

@brettz9 brettz9 added core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint labels Jan 19, 2024
@nzakas
Copy link
Member

nzakas commented Jan 22, 2024

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.

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.

@brettz9
Copy link
Contributor Author

brettz9 commented Jan 22, 2024

Yes, just a count of distinct rules that were run.

@nzakas
Copy link
Member

nzakas commented Jan 23, 2024

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?)

@brettz9
Copy link
Contributor Author

brettz9 commented Jan 23, 2024

Right, all the rules that were executed in a single run, across all files.

@nzakas
Copy link
Member

nzakas commented Jan 24, 2024

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.

@snitin315
Copy link
Contributor

snitin315 commented Jan 27, 2024

I'm fine with this enhancement, should be easy.

@nzakas
Copy link
Member

nzakas commented Jan 29, 2024

@snitin315 famous last words. :)

Copy link

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.

@github-actions github-actions bot added the Stale label Feb 28, 2024
@Rec0iL99
Copy link
Member

ping @eslint/eslint-team

@Rec0iL99 Rec0iL99 removed the Stale label Feb 29, 2024
@JoshuaKGoldberg
Copy link
Contributor

👍 I'm in favor

@mdjermanovic
Copy link
Member

I think we can consider adding this. However, this doesn't look like a trivial change, so I think it needs an RFC.

@mdjermanovic mdjermanovic added the needs design Important details about this change need to be discussed label Mar 5, 2024
@coderaiser
Copy link
Contributor

coderaiser commented Mar 25, 2024

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}`);

@nzakas
Copy link
Member

nzakas commented Mar 25, 2024

@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.

Copy link

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.

@github-actions github-actions bot added the Stale label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint needs design Important details about this change need to be discussed Stale
Projects
Status: Waiting for RFC
Development

No branches or pull requests

7 participants