Skip to content

Types generated from .razor files are reported as missing #993

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

Open
gavar opened this issue Feb 23, 2021 · 8 comments
Open

Types generated from .razor files are reported as missing #993

gavar opened this issue Feb 23, 2021 · 8 comments
Labels
Bug This issue describes behavior that is not working as expected

Comments

@gavar
Copy link

gavar commented Feb 23, 2021

Hello and thank you for an amazing tool!
We're trying to enforce code conventions during commit hooks and dotnet-format helps perfectly.

We've got troubles using new rules from Roslynator v3.1.0 introduced a new rule RCS0053 enforcing consistent indentation for lists which is the only rule I found doing so far.

By running dotnet format -wsa warn the following errors appears:

  Unable to fix RCS0053. Code fix FixFormattingOfListCodeFixProvider didn't return a Fix All action.
  Unable to fix SA1306. Code fix RenameToLowerCaseCodeFixProvider didn't return a Fix All action.

Rules are working perfectly in VSCode / Intellij Rider, except of running via dotnet format. We could live with that by manually going though the code invoking the refactoring snippets, but I see that dotnet format -wsa warn --check bypass checks if there is no fix available assuming the code is fine.

Is there any options to return non-zero code if dotnet-format unable see error but unable to fix so that lint-staged would fail?

Thanks!

@JoeRobich
Copy link
Member

Hi @gavar, Thanks for using dotnet-format and giving us this feedback. As you have discovered, dotnet-format isn't able to fix all the issues it finds. This includes the built-in naming style analyzer as well as some third-party analyzers. We rely on the CodeFix providing a FixAll with Solution support. In the future we hope to enhance dotnet-format wiuth support for all CodeFixes.

Is there any options to return non-zero code if dotnet-format unable see error but unable to fix so that lint-staged would fail?

The current behavior of dotnet-format is that it should return a non-zero exit code when any analyzer reports issues of the specified severity or higher. If you are seeing a different behavior, could you share a project that repros what you are seeing?

@JoeRobich JoeRobich added the Question This issue is requesting information about dotnet-format label Feb 23, 2021
@gavar
Copy link
Author

gavar commented Feb 23, 2021

Hi @JoeRobich, thank you for the quick reply.

I've made a simple project describing the issue, hope you will find it helpful.
https://github.com/gavar/dotnet-format-issue-993

@JoeRobich
Copy link
Member

@gavar Thanks for the excellent repro repo! =)

I found the answer reading this blog post . The file globbing library that dotnet-format uses has problems with fully rooted paths. Passing the --relative flag to lint-staged in order to generate relative file paths resolves your issue.

@gavar
Copy link
Author

gavar commented Feb 23, 2021

Thank you, I totally missed that, now it works great!

BTW, whenever the Program.cs is modified, the following error appear bailing out commit:
Program.cs(14,40): The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?) (CS0246)

I found same rule violation in #848 but it seems different
Is there anything can be done for fixing that?

@JoeRobich
Copy link
Member

@gavar In your case we have performed the restore prior to running dotnet-format. I see that the App class is generated from the App.razor file. It is likely that we are not invoking the proper MSBuild task when loading the workspace to add this class to our compilation. I am going to update this issue title to track this bug.

@JoeRobich JoeRobich added Bug This issue describes behavior that is not working as expected and removed Question This issue is requesting information about dotnet-format labels Feb 23, 2021
@JoeRobich JoeRobich changed the title Roslynator: RCS0053 / SA1306 Types generated from .razor files are reported as missing Feb 23, 2021
@gavar
Copy link
Author

gavar commented Jul 1, 2021

Hi @JoeRobich, is there any updates on that? Can I help you with that?

@JoeRobich
Copy link
Member

@gavar We recently merged #1128, which in hindsight may be the fix. Can you please try out the 6.0.235101 build of dotnet-format and let me know if it resolves your issue?

You may need to add a NuGet.config file, since we haven't published a build to nuget.org yet.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <disabledPackageSources />
</configuration>

@gavar
Copy link
Author

gavar commented Jul 5, 2021

Hi @JoeRobich

I did update to 6.0.235101 but the same problem still exists

dotnet format --version
6.0.235101+e4200c6b9671ba9081631ef389856a25a04a53e4
dotnet format -wsa warn --check
Program.cs(14,40): error CS0246: The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?) [dotnet-format-issue-993\dotnet-format-issue-993.csproj]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This issue describes behavior that is not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants