Skip to content

NEW @W-20485780@ - Add Fixes and Suggestions support in eslint#441

Open
nikhil-mittal-165 wants to merge 20 commits intodevfrom
feature/eslint-fixes-suggestions
Open

NEW @W-20485780@ - Add Fixes and Suggestions support in eslint#441
nikhil-mittal-165 wants to merge 20 commits intodevfrom
feature/eslint-fixes-suggestions

Conversation

@nikhil-mittal-165
Copy link
Copy Markdown
Contributor

No description provided.

Define Fix and Suggestion types in engine-api, add core interfaces
and implementations, update JSON/SARIF/XML output formats, and pass
includeFixes/includeSuggestions flags through RunOptions to all engines.
Convert ESLint native Rule.Fix and Linter.LintSuggestion into the
engine-agnostic Fix and Suggestion types. Add byte-offset to
line/column conversion, file content caching, and Fixable tag on
rule descriptions.
Define Fix and Suggestion types in engine-api, add core interfaces
and implementations, update JSON/SARIF/XML output formats, and pass
includeFixes/includeSuggestions flags through RunOptions to all engines.
@aruntyagiTutu
Copy link
Copy Markdown
Contributor

implementation treats byte offsets as character indices, which will produce incorrect results for files with multi-byte characters

do you agree ?

@aruntyagiTutu
Copy link
Copy Markdown
Contributor

Assumes UTF-8 encoding. ESLint may analyze files with different encodings?

@nikhil-mittal-165
Copy link
Copy Markdown
Contributor Author

implementation treats byte offsets as character indices, which will produce incorrect results for files with multi-byte characters

do you agree ?

we always read the sourxce file in utf-8 encoding see this (

const packageJson: {version: string} = JSON.parse(await fs.readFile(pathToPackageJson, 'utf-8'));
)

this gets internally converted to javascript strings and the ranges are calculated based on character indices which will be uniform no matter the source encoding, i have added a test case now for multibyte files as well

please check the commit titled "multibyte test case"

@nikhil-mittal-165 nikhil-mittal-165 force-pushed the feature/fixes-suggestion-data-modelling branch 5 times, most recently from 39bfe73 to d2be5ab Compare March 20, 2026 04:54
@nikhil-mittal-165 nikhil-mittal-165 changed the base branch from feature/fixes-suggestion-data-modelling to dev March 20, 2026 06:24

function getFileContent(filePath: string, cache: Map<string, string>): string {
if (!cache.has(filePath)) {
cache.set(filePath, fsSync.readFileSync(filePath, 'utf8'));
Copy link
Copy Markdown
Contributor

@stephen-carter-at-sf stephen-carter-at-sf Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a big no-no... you will kill the performance and responsiveness of Code Analyzer if you add in sync based operations. Why are you not using promises?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it will now consume it directly from lintResult

if (!cache.has(filePath)) {
cache.set(filePath, fsSync.readFileSync(filePath, 'utf8'));
}
return cache.get(filePath)!;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are a lot of files, your cache is going to get very very large I'm guessing.

All this code is sensitive... so please find the best approach and test on very large projects with lots of violations and measure performance before and after.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not using cache anymore , did a comparison of before and after post your review comment fix ,

the repo i used was this contains 12k tarket file. (https://github.com/SalesforceFoundation/NPSP)

took 23- 24 seconds to run all engines (without sfge) in both cases with fixes and without fixes.

Screenshot 2026-03-24 at 12 45 13 PM Screenshot 2026-03-24 at 12 49 05 PM

i have also attached the evidences of the fixes here testing all the scenarios

https://docs.google.com/document/d/1dTAXfDjgbx2nLrytjGV2PkjCDUpUZGh8TwubaxbOEtk

Comment on lines +299 to +302
if (lineStartOffsets) {
if (includeFixes && resultMsg.fix) {
violation.fixes = [convertEslintFix(file, resultMsg.fix, lineStartOffsets)];
}
Copy link
Copy Markdown
Contributor

@namrata111f namrata111f Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Nested if increases code complexity we can simply return violations if lineStartOffsets is null/empty. Something like this:

if (!lineStartOffsets) {
    return violation;
}
 if (includeFixes && resultMsg.fix) {
            violation.fixes = [convertEslintFix(file, resultMsg.fix, lineStartOffsets)];
 }
if (includeSuggestions && resultMsg.suggestions?.length) {
            violation.suggestions = resultMsg.suggestions.map(s =>
                convertEslintSuggestion(file, s, lineStartOffsets));
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants