Skip to content

Latest commit

 

History

History
100 lines (82 loc) · 6.07 KB

README.md

File metadata and controls

100 lines (82 loc) · 6.07 KB

Dogma Solutions Roslyn Analyzers

DogmaSolutions.Analyzers on NuGet

A set of Roslyn Analyzer aimed to enforce some design good practices and code quality (QA) rules.

Rules structure

This section describes the rules included into this package.

Every rule is accompanied by the following information and clues:

  • Category → identify the area of interest of the rule, and can have one of the following values: Design / Naming / Style / Usage / Performance / Security
  • Severity → state the default severity level of the rule. The severity level can be changed by editing the .editorconfig file used by the project/solution. Possible values are enumerated by the DiagnosticSeverity enum
  • Description → a short description about the rule aim.
  • Motivation and fix → a detailed explanation of the detected issue, and a brief description on how to change your code in order to solve it.
  • See also → a list of similar/related rules.

Rules list

Id Category Description Severity Is enabled Code fix
DSA001 Design WebApi controller methods should not contain data-manipulation business logics through a LINQ query expression.
DSA002 Design WebApi controller methods should not contain data-manipulation business logics through a LINQ fluent query.

DSA001

Code sample

public class MyEntitiesController : ControllerBase
{
 protected MyDbContext DbContext { get; }

 public MyEntitiesController(MyDbContext dbContext)
 {
     DbContext = dbContext;
 }

 [HttpGet]
 public IEnumerable<MyEntity> GetAll0()
 {
     // this WILL trigger an error
     var query = from entities in DbContext.MyEntities where entities.Id > 0 select entities;
     return query.ToList(); 
 }

 [HttpPost]
 public IEnumerable<long> GetAll1()
 {
     // this WILL NOT trigger an error
     var query = DbContext.MyEntities.Where(entities => entities.Id > 0).Select(entities=>entities.Id);
     return query.ToList(); 
 }
}

DSA002

Code sample

public class MyEntitiesController : Microsoft.AspNetCore.Mvc.ControllerBase
{
 protected MyDbContext DbContext { get; }

 public MyEntitiesController(MyDbContext dbContext)
 {
     this.DbContext = dbContext;
 }

 [HttpGet]
 public IEnumerable<MyEntity> GetAll0()
 {
     // this WILL NOT trigger an error
     var query = from entities in DbContext.MyEntities where entities.Id > 0 select entities;
     return query.ToList(); 
 }

 [HttpPost]
 public IEnumerable<long> GetAll1()
 {
     // this WILL trigger an error
     var query = DbContext.MyEntities.Where(entities => entities.Id > 0).Select(entities=>entities.Id);
     return query.ToList(); 
 }
}

Installation