megalinter icon indicating copy to clipboard operation
megalinter copied to clipboard

Upgrade dotnet to v6 + list_of_files for dotnet-format

Open nvuillam opened this issue 1 year ago • 17 comments

Fixes https://github.com/oxsecurity/megalinter/issues/1642

nvuillam avatar Jul 24 '22 19:07 nvuillam

MegaLinter status: :warning: WARNING

Descriptor Linter Files Fixed Errors Elapsed time
✅ BASH bash-exec 7 0 0.02s
✅ BASH shellcheck 7 0 0.25s
✅ BASH shfmt 7 0 0 0.27s
✅ COPYPASTE jscpd yes no 1.91s
✅ DOCKERFILE hadolint 103 0 18.35s
✅ JSON eslint-plugin-jsonc 20 0 0 2.08s
✅ JSON jsonlint 18 0 3.68s
✅ JSON v8r 20 0 10.72s
:warning: MARKDOWN markdownlint 280 0 5 4.25s
✅ MARKDOWN markdown-link-check 280 0 4.82s
✅ MARKDOWN markdown-table-formatter 280 0 0 6.48s
✅ OPENAPI spectral 1 0 0.77s
:warning: PYTHON bandit 164 50 2.01s
✅ PYTHON black 164 0 0 3.19s
✅ PYTHON flake8 164 0 1.79s
✅ PYTHON isort 164 0 0 0.57s
✅ PYTHON mypy 164 0 88.76s
✅ PYTHON pylint 164 0 14.29s
✅ REPOSITORY git_diff yes no 0.27s
✅ REPOSITORY secretlint yes no 11.27s
✅ REPOSITORY trivy yes no 20.87s
✅ SPELL cspell 660 0 18.74s
✅ SPELL misspell 491 0 0 0.61s
✅ XML xmllint 3 0 0.0s
✅ YAML prettier 80 0 0 2.24s
✅ YAML v8r 23 0 25.45s
✅ YAML yamllint 81 0 1.05s

See errors details in artifact MegaLinter reports on CI Job page

nvuillam avatar Jul 24 '22 19:07 nvuillam

@lextatic thanks for the tips , I made the updates :)

nvuillam avatar Jul 25 '22 06:07 nvuillam

Updates done :)

nvuillam avatar Jul 25 '22 17:07 nvuillam

@lextatic why this "whitespace" ? Aren't there other types of formatting than just whitespaces ? ^^

nvuillam avatar Jul 30 '22 21:07 nvuillam

@lextatic why this "whitespace" ? Aren't there other types of formatting than just whitespaces ? ^^

Yes, dotnet-format can formate styling too, but it won't work without a .csproj or .sln file. So if you want to lint only .cs files exactly as it used to in dotnet 5.0 you have to link whitespaces only with the --folder argument. --folder is option exclusive for linting with whitespace.

Here's the doc I found about it: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-format

I also left some comments in this issue trying to explain a possible solution to solve this.

lextatic avatar Jul 30 '22 21:07 lextatic

@lextatic why this "whitespace" ? Aren't there other types of formatting than just whitespaces ? ^^

On a second thought, someone linting .NET should probably have a .sln or .proj file anyway, and you already have a DEFAULT_WORKSPACE var that could point megalinter in that direction.

So you could just add a .sln or proj file to your csharp and vb automated tests and go on with without changing anything, dropping the whitespace and --folder args altogether and having all of dotnet-format's functionality.

dotnet format --verify-no-changes --exclude / --include myfile.cs myfile2.cs would work nicely as it is now.

Thinking about it, that seems the most plausible solution, I was worried about making the new code pass your previous tests but in this case we should adapt the tests as the system changed. And this would be just add the project files.

lextatic avatar Jul 31 '22 11:07 lextatic

@lextatic do you have an example of .sln file that would work ?

nvuillam avatar Jul 31 '22 11:07 nvuillam

@lextatic do you have an example of .sln file that would work ?

Created a PR with such project files.

lextatic avatar Jul 31 '22 12:07 lextatic

It looks like DevSkim has not been upgraded to dotnet 6.0 yet.

https://github.com/microsoft/DevSkim https://github.com/microsoft/DevSkim/pulls

lextatic avatar Aug 01 '22 16:08 lextatic

:/ Do you know if it is possible to make dotnet 5 & dotnet 6 live together ? ( I never developed in dotnet)

nvuillam avatar Aug 01 '22 18:08 nvuillam

There may be other ways as well, but I know the dotnet-core asdf plugin is capable of this.

Kurt-von-Laven avatar Aug 01 '22 21:08 Kurt-von-Laven

:/ Do you know if it is possible to make dotnet 5 & dotnet 6 live together ? ( I never developed in dotnet)

Yes, I have both SDKs on my machine and they're interchangeable. You can have a global.json file on a folder and when dotnet is executed from this location it uses the SDK configured in the file.

Reference: https://www.markheath.net/post/switching-between-netcore-sdk-versions

lextatic avatar Aug 01 '22 21:08 lextatic

Is there a command like dotnet switch-to-v5 and dotnet switch-to-v6 that I could easily use ?

nvuillam avatar Aug 01 '22 22:08 nvuillam

Is there a command like dotnet switch-to-v5 and dotnet switch-to-v6 that I could easily use ?

Hmm, I guess dotnet new globaljson --sdk-version <version> --force does exactly that, you just have to check if both versions are installed under .NET SDKs installed upon using dotnet --info

For example:

dotnet new globaljson --sdk-version 5.0.408 --force to use dotnet 5.0 and dotnet new globaljson --sdk-version 6.0.302 --force to use dotnet 6.0

https://docs.microsoft.com/en-us/dotnet/core/tools/global-json

Better yet: dotnet new globaljson --sdk-version 5.0.0 --roll-forward latestMinor --force and dotnet new globaljson --sdk-version 6.0.0 --roll-forward latestMinor --force

lextatic avatar Aug 01 '22 23:08 lextatic

@lextatic Just asked DevSkim if they planned an upgrade, it would ease our task here ^^

https://github.com/microsoft/DevSkim/issues/391

nvuillam avatar Aug 05 '22 16:08 nvuillam

@lextatic FYI :) https://github.com/microsoft/DevSkim/issues/391#issuecomment-1215828197

nvuillam avatar Aug 15 '22 21:08 nvuillam

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

If you think this pull request should stay open, please remove the O: stale 🤖 label or comment on the pull request.

github-actions[bot] avatar Sep 15 '22 01:09 github-actions[bot]