CodeFactor picks up automatically StyleCop configuration, in fact it's using its default, so we are already using it. If we could make StyleCop to adhere to editorconfig, then it'd be awesome.
What did you find?
StyleCop analyzers do not support editorconfig based configuration, but use their own stylecop.json with their own custom format, that end users can provide in their project for configuration of stylecop analyzers.
From https://github.com/MicrosoftDocs/visualstudio-docs/issues/2382
I see. Sad.
We have numerous rules specified in .editorconfig, but it can be only used by vs users and not vscode users, so only Windows devs benefit.
We unknowingly used StyleCop through CodeFactor so far with its default configuration. StyleCop however works for Linux and Windows users if they want to use it. Or they can leave it to the final CodeFactor check to fix their things.
.stylecop.json to the project..editorconfig..editorconfig.@molnard @jmacato @yahiheb @lontivero what do you think?
I have some updates, i think Linux and Omnisharp in extension can use most of the options in editorconfig by setting the ff in VSCode's JSON settings:
...
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.enableRoslynAnalyzers": true,
...
Though if StyleCop already works on linux vscode/omnisharp (I haven't tried because I'm not sure how) then perhaps we can simplify as @nopara73 outlined
Make editorconfig work for VSCode users (Linux included)
Solution 1:
VSCode users should edit their personal settings (settings.json):
https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations
Depending on your platform, the user settings file is located here:
- Windows %APPDATA%\Code\Usersettings.json
- macOS $HOME/Library/Application Support/Code/User/settings.json
- Linux $HOME/.config/Code/User/settings.json
Add the following settings:
...
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.enableRoslynAnalyzers": true,
"editor.formatOnSave": true
...
Solution 2:
Share the same settings with all for the devs.
We check in the .vscode/settings.json file and add the settings mentioned above (or any other settings)
Solution 2 is unacceptable. The settings.json file is not a project setting file, it is a file to configure the development environment according to the users' preferences. That includes font type and size, the level of zoom the user feels comfortable with, the configuration of all the vscode extensions, colors, windows disposition, custom behaviors and who knows what else. Basically, settings file allows you to configure absolutely every single aspect of vscode, in fact we can make if feel like emacs, vim or jetbrains editor modifying that file. We cannot override the user preferences every time a contributor performs a git pull.
I have suffered this before for many months and it is a nightmare because I had to replace that file with my own settings file after each pull.
Btw, this is my settings.json file. I am sure other devs will have absolutely different preferences.
{
"window.title": "${rootPath}${separator}${appName}",
"window.zoomLevel": 0,
"window.titleBarStyle": "custom",
"editor.trimAutoWhitespace": true,
"editor.lineNumbers": "on",
"editor.mouseWheelZoom": true,
"editor.fontLigatures": true,
"editor.fontSize": 14,
"editor.minimap.enabled": false,
"editor.wordWrap": "off",
"editor.wordWrapColumn": 120,
"editor.formatOnSave": true,
"editor.renderWhitespace": "all",
"editor.snippetSuggestions": "top",
"editor.formatOnPaste": true,
"files.exclude": {
"**/bin": true,
"**/obj": true
},
"telemetry.enableCrashReporter": false,
"telemetry.enableTelemetry": false,
"bookmarks.navigateThroughAllFiles": true,
"bookmarks.backgroundLineColor": "rgba(21, 126, 251, 0.1)",
"gitlens.menus": {
"editor": false,
"editorGroup": {
"blame": true,
"compare": true,
"history": false,
"remote": false
},
"editorTab": {
"compare": false,
"history": false,
"remote": true
},
"explorer": {
"compare": true,
"history": true,
"remote": true
}
},
"workbench.welcome.enabled": false,
"workbench.editor.tabSizing": "shrink",
"files.trimTrailingWhitespace": true,
"search.exclude": {
"**/bin": true,
"**/obj": true,
},
"omnisharp.enableRoslynAnalyzers": true,
"omnisharp.enableEditorConfigSupport": true,
}
Solution 2 is unacceptable.
I agree with that.
Then we should simply add a section in Contributing file that tells VSCode users to add those 3 settings in their local settings in order for editorconfig to work for them.
I would do the following:
Ok, it looks like we're in agreement. @jmacato, @molnard and me are suggesting that the best course of action could be to add StyleCop (not as a NuGet, but for just CodeFactor to check and everyone can install StyleCop locally if he wants, or leave the smell check for CodeFactor instead.) And then bring over many of the rules from .editorconfig, then remove it.
@yahiheb from your linked blog post it seems like you agree in this course of action, is that right?
I posted that blog because I thought it might be useful, and if you guys agree to add StyleCop I have no objection, just make sure that this is the right solution and it works for everyone. I still think .editorconfig is very useful.