-
Notifications
You must be signed in to change notification settings - Fork 52
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
[BUG][code-analyzer] ESLint Plugin Conflict in Salesforce Code Analyzer 5.0 Beta 2 #1753
Comments
Hello @TimPaulaskasDS , In our attempt to serve both types of users
Regarding
We wish not to guess at what the user wants in these circumstances. The only way to resolve automatically would be to either remove one of our recommended configurations in favor of the users configuration or remove the users configuration in favor of our recommended configuration. But different users will want different things, which is why we point users to the ability to make these decisions within their code-analyzer.yml file.
Alternatively, you could just look at the configuration we set by looking at the log file that we produce during a call to any code-analyzer command and just apply those settings as the basis of your own custom configuration and then disable our configuration in favor of your own with:
You can see how we build the configuration over at: https://github.com/forcedotcom/code-analyzer-core/blob/dev/packages/code-analyzer-eslint-engine/src/base-config.ts
This suggests that we shouldn't attempt to add in our own recommended rules, but instead just choose the user's .eslintrc.json file if it exists instead. This is a valid option, but most of the time, ESLint can resolve our configuration along side the user's configuration without issue... so we chose to allow ESLint to attempt to resolve all the configurations together. We understand that the initial setup with an existing .estlintrc.json configuration file can be a pain point, but we do believe that giving the user the choice on how to resolve the conflict is a one time pain at first setup only and gives our users the ability to have more control over how code analyzer is configured. OK, now to help you resolve your issue... I see you have the following .eslintrc.json configuration:
which gets set in the overall eslint config internally with:
And the conflict says:
My guess is that this happening because you are specifying
in your config and it sees that you have locally installed the plugin over at
which conflicts with the one already provided by the Salesforce Code Analyzer. ESLint has an outstanding issue where it doesn't know how to choose the correct node_module's package if a base config and an override config both point to the same plugin but in different node_module directories because there could be version conflicts. Keeping in mind that Salesforce Code Analyzer doesn't just take your eslint configuration file as the list of rules to run, but instead as the additional eslint rules that can be made available for rule selection, the easiest thing to do is just to remove
from your .eslintrc.json file. If you don't want to do this globally for your other tools (like VSCode etc) then just make a separate salesforce code analyzer specific eslint configuration file (maybe called .eslintrc_sfca.json) that allows you to bring in your yaml based rules still for selection which will be added to the existing base config's rules. For example create a
and then have your code-analyzer.yml file look like this:
and then look at the output of
to see if it has everything you want. If you want to override a specific rule that code analyzer already brings in, then simply add in a 'rules' section with the overrides that you want. For example: https://github.com/forcedotcom/code-analyzer-core/blob/dev/packages/code-analyzer-eslint-engine/test/test-data/legacyConfigCases/workspace_HasCustomConfigModifyingExistingRules/.eslintrc.json Please let us know if this explains/resolves your issue. Thanks. |
Have you tried to resolve this issue yourself first?
Yes
Bug Description
Bug Report: ESLint Plugin Conflict in Salesforce Code Analyzer 5.0 Beta 2
Description
When attempting to run Salesforce Code Analyzer 5.0 Beta 2 with an existing
.eslintrc.json
configuration, the analyzer encounters a conflict between a plugin supplied by a user-defined ESLint configuration file and a plugin supplied by the base configuration.Error Message:
Steps to Reproduce
.eslintrc.json
file.Expected Behavior
The analyzer should respect the existing ESLint configuration or provide a seamless way to disable conflicting base configurations without requiring manual intervention.
Output / Logs
sfca-2025_03_11_08_58_25_821.log
Steps To Reproduce
sf code-analyzer run --rule-selector pmd --rule-selector retire-js --rule-selector regex --workspace "./force-app//*.cls" --workspace "./force-app//.trigger" --workspace "./force-app/**/.js" --workspace "./force-app//*.ts" --workspace "./force-app//*.apex" --output-file ./code-analyzer-logs/results.html --output-file ./code-analyzer-logs/results.csv
Expected Behavior
Expected Behavior
Salesforce Code Analyzer should correctly handle ESLint configurations without conflicting with user-defined
.eslintrc.json
settings. The expected behavior includes:.eslintrc.json
file is present, respecting user configurations while ensuring compatibility with Salesforce best practices.Operating System
MacOS Sonoma 15.3.1
Salesforce CLI Version
@salesforce/cli/2.78.3 darwin-arm64 node-v22.14.0
Code Analyzer Plugin (code-analyzer) Version
code-analyzer 5.0.0-beta.2 (5.0.0-beta.2)
Node Version
v22.14.0
Java Version
openjdk version "17.0.14" 2025-01-21 OpenJDK Runtime Environment Homebrew (build 17.0.14+0) OpenJDK 64-Bit Server VM Homebrew (build 17.0.14+0, mixed mode, sharing)
Python Version
Python 3.13.2
Additional Context (Screenshots, Files, etc)
.eslintrc.json
.eslintignore
Workaround
Workaround
I cannot use the auto discover or the specified eslint configuration or ignore files.
To avoid the plugin conflict, I have to configure
code-analyzer.yml
as follows:Urgency
Low
The text was updated successfully, but these errors were encountered: