Salesforcedx-vscode: Don't modify eslint path automatically, don't automatically change user settings

Created on 12 Jun 2019  路  15Comments  路  Source: forcedotcom/salesforcedx-vscode

Every time I open VSCode this extension automatically adds "eslint.nodePath": "/Users/myuser/.vscode/extensions/salesforce.salesforcedx-vscode-lwc-45.15.1/node_modules" to my settings.json file.

Please stop auto modifying config files, this affects any VSCode session I open regardless of it's a Salesforce project. It happens without prompting. Your extensions have already fully deleted my local config settings in the past from trying to do things like this. Now you're auto modifying them? Please don't add behavior like this to plugins!

This breaks any project with custom ESLint plugins, because it tries to use a randomly installed one in the sfdx plugin, not the correct locally installed on per project.

For anyone else who has their config mangled by these bad actor plugins and starts seeing errors like this because it's using a randomly installed eslint:

[Error - 11:43:40 AM] Cannot find module 'eslint-plugin-prettier' Referenced from: /Users/me/repo/.eslintrc.js

You can block the bad plugin by setting it manually:

  "eslint.nodePath": "./node_modules"
bug

Most helpful comment

yikes

this is a serious issue, please re-open

All 15 comments

Hi @AndrewRayCode, can you provide more info on how you are setting up the Salesforce extensions ? The issue you reference only happens when the Salesforce extensions get activated which is specific to the project being a Salesforce project. The settings.json that gets the eslint value is exclusively the one for the project.
We're working on modifying this behavior but would like to make sure we're not missing something else.

This issue has been automatically closed because there has been no response to our request for more information from the original author. Currently, there is not enough information provided for us to take action. Please reply and reopen this issue if you need additional assistance.

yikes

this is a serious issue, please re-open

Our developers are facing this same problem. Please address.

We are looking at how we can address this. The problem is there isn鈥檛 a user specific project config for VSCode. The way we can not write this setting is to add a package.json to projects that have LWC and require developers to use npm. This however means we have to require them to install node.

We are looking at how we can address this. The problem is there isn鈥檛 a user specific project config for VSCode. The way we can not write this setting is to add a package.json to projects that have LWC and require developers to use npm. This however means we have to require them to install node.

I imagine the nuances of LWCs can lead to inadvertent developer errors which a linter can help remedy. However, linters have always been an optional project add-on. The benefits of a linter in this day and age is pretty well known. Do you guys have a custom ESLint plugin for LWCs?

@bk-dev yes, we have a specific rule set for ESLint LWC. While you are right that lingers are normally optional, many of our developers have indicated they want as much out of the box functionality as possible so we try to find a balance.

@ntotten I see your dilemma. It would be nice to bake this into the project setup via terminal prompts for sfdx force:project:create like other prominent front-end framework CLIs do. But that doesn't side-step the node requirement. Is it possible to install node for the user if they agree to it as part of opting into the linter during SFDX project creation?

Hi,
I think there are three different solutions here :

  • Install all the "salesforce-dx" node packages globally, that way we don't need to modify the eslint.nodePath of each project

    • (pros) We don't have to reference any path (and don't have to update it on each version)

    • (pros) We don't have to modify the workspace settings

    • (pros) The other installed dependent packages are not installed twice

    • (cons) Might polute the globally installed packages

  • Make the installation of sfdx (and update script) to modify the NODE_PATH env variable

    • (pros) We don't have to modify the workspace settings

    • (cons) We need to modify NODE_PATH and update it on each release

  • Modify the current script to allow it to just add the missing conf and not override option

    • (pros) We don't change the current behaviour / we have small risk of breaking everything

    • (cons) I think this setup is not correct, we need to take option 1

I'm going to make a PR for option 3 as it's the easiest to make. It's also a minor change so we should have it merged quickly. I think a rework is necessary around that question for a future release, either take option 1 or 2. Option 1 is my favourite.

I'm happy to discuss it with anyone willing to give his opinion on it.

I am having the same issue with overwriting the configuration; force-app\main\default\lwc\.eslintrc.json.

I want to provide custom ESLint rules along with the Salesforce provided rules. I am not able to modify force-app\main\default\lwc\.eslintrc.json, because it gets rewritten when VSCode is reloaded.

I am able to include my additional rules by providing configuration with the command in the script in the package.json, but I should be able to update the .eslintrc.json file if I want without it be rewritten.

"scripts": {
  "lint:lwc": "eslint --plugin my-plugin --rule \"my-plugin/my-rule: 2\" **/lwc/**"
}

The ticket which was closed as a duplicate of this one actually raised a semi-separate issue, which is that someone is magically recreating and/or rewriting jsconfig.json. Why would you do that? Why would it be rewritten, as it is in my case, to include every single component in the paths object? This can cause odd merge conflicts. Or should jsconfig.json be considered an artifact not kept under version control? Or is this some VSCode extension thing, and if so triggered by what? Or am I missing something and our ages-old build system with random patches for LWCs doing something that I can't see which results in re-creating jsconfig.json?

@rtm I think you're right. These are two separate issues because the solutions are not the same.

For .vscode/settings.json the solution is probably one of which I purposed earlier. A new one can be to execute an npm or yarn command which install the salesforce package locally to the project folder as we do for any JS project (create a local node_modules folder with packages inside).

For force-app/main/default/lwc/.eslintrc.json or force-app/main/default/lwc/jsonconfig.json they must be initialized when project is initialized. If we want to handle the default value being updated, we should have a system which provide a diff between the default file and the current file and ask the user what he wants to do.

@ntotten I understand that people want stuff out of the box. If you look at what is necessary for using Dataloader or the recent sfdx diff command, they have dependencies that need to be installed by the user. Why do this will be different ? We can always implement a test which displays a message to the user asking him if he wants the extension to run and install the missing dependencies when not found.

I am not a happy camper at the moment because the build and deploy is failing due to conflicts caused by jsconfig.json being randomly rewritten. To follow up on my previous post:

  1. Who/what exactly is rewriting jsconfig.json?
  2. Why are they doing so?
  3. Why does jsconfig.json seem to require a paths property which points each LWC in the tree to itself, more or less?
  4. How can we turn off rewriting jsconfig.json?
  5. If we are able to turn off the rewriting and do so, what is the impact? Will we need to manually update it each time we add a new LWC to the tree?
  6. What is the purpose of jsconfig.json? Who is consuming it?

If for some reason there is a need to rewrite jsconfig.json, then a better approach would be to provide a script or SFDX command that creates a new one that people could use when, and only when, they want to.

Appreciate your help.

I am too confused by this topic. So I want to write down my solution. If something wrong, please someone tell me the problem.

For preventing modify .vscode/settings.json, most straight forward solution is to set own nodePath within .vscode/settings.json.
Like @AndrewRayCode said.

  "eslint.nodePath": "./node_modules"

And we may also have force-app/main/default/lwc/.eslintrc.json and it contains like below configuration, so I need to run npm i -D @salesforce/eslint-config-lwc.

{
  "extends": ["@salesforce/eslint-config-lwc/recommended"]
}

At this moment, this seems working in my eyes.

Resolved in today's release.

Was this page helpful?
0 / 5 - 0 ratings