Skip to content

Bug fixes #60

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

Merged
merged 5 commits into from
Jun 10, 2025
Merged

Bug fixes #60

merged 5 commits into from
Jun 10, 2025

Conversation

khawkins
Copy link
Contributor

@khawkins khawkins commented Jun 6, 2025

What does this PR do?

This fixes a couple of issues seen in the wild.

  1. I didn't realize that in ESLint, if/when you change the name of the incoming file in your custom processor's preprocess() method, it recursively runs that "new" file through the processor again. This was causing weird inconsistencies and infinite loops, because the preprocess() flow was not expecting these files to come in. There's now a guard to fall through for these files.
  2. The filtering of Komaci reports was missing a filter check for the diagnostics applying to the current file coming through for analysis. In the case of an LWC bundle, this could result in e.g. diagnostics violations for the HTML file in the bundle being reported for the JS file that was going through analysis. I added the additional filename filter criteria for the eslintReports.

khawkins added 3 commits June 5, 2025 22:25
Changing filenames in the return value of `preprocess()` automatically triggers the processor again for those "new files". This adds a guard to bail in processing if those temporary files come in for new processing.
@khawkins khawkins requested review from dbreese, sfdctaka, maliroteh-sf and a team as code owners June 6, 2025 16:20
{
files: ['**/*.html']
}
]

Choose a reason for hiding this comment

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

When html overrides is removed, will any rule be applied to html files?

}
overrides: [
{
files: ['*.html', '**/*.html', '*.js', '**/*.js'],

Choose a reason for hiding this comment

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

Ok, I see the html extension here.

const bundleKey = extractBundleKey(filename);
if (bundleStateManager.hasBundleWithKey(bundleKey)) {
// Skip processing for files we generated
return [{ text, filename }];
Copy link

@haifeng-li-at-salesforce haifeng-li-at-salesforce Jun 10, 2025

Choose a reason for hiding this comment

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

Does this fix recursive processing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The renaming we do at the bottom of the method causes ESLint to (re-)process this "new" file that we created. Conversely, when you return what you got in the processor, ESLint continues on with the rest of the process (i.e. considers that file pre-processed).

/**
* Concrete implementation of StaticAnalyzerInterface that uses the actual static analyzer
*/
class StaticAnalyzerProvider extends StaticAnalyzerInterface {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pulled this out into its own interface implementation so we could test the outputs coming from the static analysis.

// Only include diagnostics that match both the rule and target the primary file
return (
reportDiagnosticValue === diagnosticValue &&
reportDiagnostic.code.target.path === lwcBundle.primaryFile.filename

Choose a reason for hiding this comment

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

Nice catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I started seeing a random squiggly line for an HTML violation, in the middle of my JS file. 😂

/**
* Interface for static analysis functionality
*/
class StaticAnalyzerInterface {

Choose a reason for hiding this comment

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

Is this a mirror from Komaci library?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not per se. It was just a way to abstract the Komaci analysis functions we use, so that I could create a mock provider in test, to test how the analysis output impacted different parts of the reporting. You can see some of the mocked analysis tests below.

// Set the primary file before getting the bundle key
bundle.setPrimaryFileByContent(jsContent);
const bundleKey = bundle.getBundleKey();
bundleStateManager.addBundleState(bundle);

Choose a reason for hiding this comment

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

Is this line necessary since bundleAnalyzer.preprocess can handle that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could in theory, i.e. if you called bundleAnalyzer.preprocess() once with the given bundle, then called it again below. This is just meant to simulate that process by staging the bundle in the state manager, the gating factor for whether it has been processed already. One way or another you'd have to call something, since this test is meant to cover what happens when the same file goes through preprocessing again.

Copy link

@haifeng-li-at-salesforce haifeng-li-at-salesforce left a comment

Choose a reason for hiding this comment

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

The improvement looks great! I do have a few questions, but they’re not blockers for approval.

@khawkins khawkins merged commit b7a0dde into salesforce:main Jun 10, 2025
7 checks passed
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.

2 participants