Add eslint.codeActionsOnSave.options#1945
Conversation
|
@microsoft-github-policy-service agree [company="Vanta"] |
|
@microsoft-github-policy-service agree company="Vanta" |
|
@dbaeumer I think I've followed your instructions correctly in #1938 (comment). Is there a way I can build and install this extension locally so I can test whether the setting works? |
|
You can run from source
To build and install locally do the following:
Let me know how it goes. |
|
I did a first quick look and one thing I noticed is: do we want to support to only provide options without any rule modifications. That would have an impact on the code here: https://github.com/microsoft/vscode-eslint/blob/main/server/src/eslint.ts#L515 |
|
I was thinking if |
I think we should still allow this. If users already customized this and he simply wants to add some basic options I would still prefer to allow this. |
|
@dbaeumer sorry for the late update. This is ready for a review now. |
|
@dbaeumer is there something blocking this PR from being merged? If so (and if @JavaScriptBach is no longer interested) I'm more than happy to continue the remaining work. |
|
@MariaSolOs mostly time. I see if a can spare some time next week to catch up with the PR. |
Thank you! I would really appreciate that. |
| "scope": "resource", | ||
| "type": "object", | ||
| "default": {}, | ||
| "markdownDescription": "The eslint options object to use on save. (see https://eslint.org/docs/developer-guide/nodejs-api#eslint-class). eslint.codeActionsOnSave.rules, if specified, will take priority over any rule options here." |
There was a problem hiding this comment.
Nit:
| "markdownDescription": "The eslint options object to use on save. (see https://eslint.org/docs/developer-guide/nodejs-api#eslint-class). eslint.codeActionsOnSave.rules, if specified, will take priority over any rule options here." | |
| "markdownDescription": "The ESLint options object to use on save (see https://eslint.org/docs/developer-guide/nodejs-api#eslint-class). `eslint.codeActionsOnSave.rules`, if specified, will take priority over any rule options here." |
| let eslintOptions: ESLintClassOptions = {fix: true}; | ||
| if (offRules !== undefined || overrideOptions !== undefined) { | ||
| if (overrideOptions !== undefined) { | ||
| eslintOptions = {...overrideOptions, ...eslintOptions}; |
There was a problem hiding this comment.
We probably want to swap the order of the options here for the save options to override the other ones right?
| eslintOptions = {...overrideOptions, ...eslintOptions}; | |
| eslintOptions = {...eslintOptions, ...overrideOptions}; | |
| } | ||
| return result; | ||
| }, settings, overrideConfig !== undefined ? { fix: true, overrideConfig } : { fix: true }); | ||
| }, settings, eslintOptions ); |
There was a problem hiding this comment.
Nit:
| }, settings, eslintOptions ); | |
| }, settings, eslintOptions); | |
|
@dbaeumer friendly ping about this PR 🙃 Once you review it, I'm happy to make the required changes. |
| eslintOptions = {...overrideOptions, ...eslintOptions}; | ||
| } | ||
| if (offRules !== undefined && offRules.size > 0) { | ||
| const overrideConfig = {rules: Object.create(null)}; |
There was a problem hiding this comment.
We should keep the spaces here
| } | ||
| return result; | ||
| }, settings, overrideConfig !== undefined ? { fix: true, overrideConfig } : { fix: true }); | ||
| }, settings, eslintOptions ); |
| } | ||
| } | ||
| return offRules.size > 0 ? { offRules, onRules } : undefined; | ||
| return (offRules.size > 0 || options) ? { offRules, onRules, options } : undefined; |
There was a problem hiding this comment.
Until now we had undefined when we didn't have any rule changes. If we now had options we will end up with to empty sets if no options are specified. Might not be too big of a problem. But may be e can avoid this.
|
I will close this PR then. |
Overview
Add an
eslint.codeActionsOnSave.optionsthat allows users to customize the options that ESLint runs with on save. This allows passing in a different set of options to ESLint on save.If
eslint.codeActionsOnSave.rulesis specified, they will take priority over any rules specified ineslint.codeActionsOnSave.options. However, my use case for adding this is to specify a completely different config to provide faster on-save performance; more details in the test plan below.See motivation in #1938 (comment).
Testing
Tested manually on my codebase with the following settings:
Verified that saving respected the precommit config and was faster than using the full config.