Git Product home page Git Product logo

.net-analyzers's People

Contributors

0liver avatar aydine avatar barthamark avatar benedekfarkas avatar boros-csaba avatar demeszabolcs avatar dministro avatar domonkosgabor avatar i3undy avatar luko6 avatar mzole avatar piedone avatar porgabi avatar psichorex avatar sarahelsaig avatar wasnk avatar yevgeniyshunevych avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

.net-analyzers's Issues

IDE0055 false positive with LF line endings (OSOE-344)

This is our follow-up issue once dotnet/roslyn#55526 is fixed.

What's the problem?

In Git repositories, it's common to use LF (\n, "Unix-style") line endings for better cross-platform compatibility (see Lombiq/Open-Source-Orchard-Core-Extensions#65). The problem is that with .cs files, if we have LF line endings instead of CRLF (\r\n, "Windows-style") then roslyn will emit several false-positive IDE0055 warnings. There is a workaround of making only the .cs files CRLF as described in the above-linked issue. We have applied it to this repo and its submodules during OSOE-49.

What needs to be done?

Once the analyzer is fixed, the *.cs text eol=crlf rule should be removed from all .gitattributes files and then all .cs files should be renormalized to LF using the same steps described in the issue description of OSOE-91.

Jira issue

Static code analysis randomly crashes with "MSB6006: "csc.dll" exited with code 139." (OSOE-725)

This has happened a couple of times, but very rarely. Restarting the workflow fixes the problem.
An example is here, however it's not related to that issue (compilation failed in Lombiq.SetupExtensions.csproj which doesn't use nodejs) and I've seen it appear in other branches too, it's just the latest one at the time of writing. I've checked the attached binlog but didn't see anything significant in it.

Jira issue

Migrate to .editorconfig from ruleset files (OSOE-179)

This is only suitable once .editorconfig has everything ruleset files provide already:

  • IDE support, i.e. you don't have to manually add every rule but can just select what to do for each rule. This is now done with VS 2022. However, it only works for files under the solution, so you can't edit under the tools folder.
  • Ability to extend another .editorconfig file. This is only interesting for overriding our default rules though (as we explain here). It would also help to get rid of the editorconfig copy to the solution root. However, perhaps the <EditorConfigFiles> could help us, see this blog post. An alternative would be dotnet/roslyn#19028 (comment).
  • There's also .globalconfig, but that's only for analyzer configs, not edit configuration like charset or guidelines. See dotnet/roslyn#47707.

Tasks:

  • Migrate the config files, see the official docs.
  • Perhaps we need to have use case-specific packages, e.g. `Lombiq.Analyzers.OrchardCore"?
  • Update docs. Search for ".editorconfig" and "ruleset".
  • Add docs on migration, including converting ruleset files.
  • Check if we need <developmentDependency>true</developmentDependency> in the nuspec template. The analyzer packages we use do this. Check the generated <PackageReference> after a new install and change the docs, including release notes, and consuming projects if necessary.
  • Publish new NuGet package. This will need to be a major release. Add migration docs to the release.

Analysis rules are bing ignored

Been using Lombiq.Analyzers as a submodule for a while but recently every analysis error is being thrown including ones disabled in the rules file like as if they don't exist.

If I disable below it makes no difference.

<Project>
  <ItemGroup> 
      <Analyzer Remove="@(Analyzer)" /> 
  </ItemGroup>
</Project>

Or via the command line using /p:RunCodeAnalysis=false - no difference.

It still is fine in our build pipeline however if I bring down the source code into a new computer - same issue.

Typical error example are:
error CA1707: Remove the underscores from member name Kast.ConnectCard.Constants.FeatureIds.Kast_ConnectCard_OnUs

I copied Lombiq's open source project and copied the configuration from there but this made no difference.

Custom Orchard Core analyzers (OSOE-346)

Let's develop custom analyzers. This is not that easy, and we'd need to publish them on NuGet since analyzers can't be used directly from the source.

Some ideas:

  • Check if controller actions have authorization either with attributes (e.g. [Admin]) or with an explicit IAuthorizationService call.
  • Check for any unfiltered ISession queries. While not always, usually there should be some kind of filtering instead of a full table retrieval.
  • Check for IContentManager.GetAsync(string id) calls in a loop and suggest IContentManager.GetAsync(IEnumerable<string> contentItemIds, bool latest = false) instead.
  • Check for OrchardCore.ResourceManagenet project/package reference if resource management tag helpers are used. Similarly, check for a missing OrchardCore.DisplayManagement reference and others. See OrchardCMS/OrchardCore#6943.
  • Use IClock instead of DateTime.UtcNow.
  • Interesting not just for Orchard apps but any ASP.NET Core app, so should be under their own category:
    • Check for the injected localizer to have a proper type (not the field/property it's saved to): It must be IStringLocalizer<MyClass> or IHtmlLocalizer<MyClass>. The type parameter mustn't be omitted or have a different type than the current type. This would actually be generally interesting for ASP.NET Core MVC apps. Came up here too: OrchardCMS/OrchardCore#10987
    • Check for the Sdk attribute being Microsoft.NET.Sdk.Razor in the csproj's <Project> element if Razor templates are being used.
    • Private and protected fields should be named _prefixedWithUnderscoreCamelCased except for T and H. We can modify SX1309 for this. The alternative would be to put all localizers into properties instead and enable SX1309.

Jira issue

Now to use the NuGet package

The instructions cover adding this to your solution using a submodule method but do not cover how to utilise this from the NuGet package.

Could we have some clarification on this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.