Skip to content

Allow csharpier to ignore attribute blocks #992

Open

Description

@sander1095

Situation

I'm trying to implement the ignore formatting documentation for the following code:

[HttpDelete("{id:int:min(1)}/something")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(ProblemDetails), Description = "Will be returned validation fails in this API")]
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(HttpValidationProblemDetails), Description = "Will be returned validation fails in a downstream API")]
[ProducesDefaultResponseType]
public async Task<ActionResult> SomeMethodNameGoesHere(
    int id,
    ALongModelNameThatIsReallyLong requestModel
)
{
    await Task.CompletedTask;
    return NoContent();
}

Problem

I would like to forbid csharpier from formatting the SwaggerResponse attributes because it ends up being very unreadable in the context of an API action:

[HttpDelete("{id:int:min(1)}/something")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[SwaggerResponse(
    StatusCodes.Status400BadRequest,
    typeof(ProblemDetails),
    Description = "Will be returned validation fails in this API"
)]
[SwaggerResponse(
    StatusCodes.Status400BadRequest,
    typeof(HttpValidationProblemDetails),
    Description = "Will be returned validation fails in a downstream API"
)]
[ProducesDefaultResponseType]
public async Task<ActionResult> SomeMethodNameGoesHere(
    int id,
    ALongModelNameThatIsReallyLong requestModel
)
{
    await Task.CompletedTask;
    return NoContent();
}

It's just way too many lines of metadata until you get to the meat and potatoes of the API action. My thoughts are that if someone wants to read the SwaggerResponseType description, they can simply scroll a bit.

Current solution

It is already possible to ignore the formatting by doing this:

// csharpier-ignore - Csharpier ends up formatting this into multiple lines which causes too much noise
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(ProblemDetails), Description = "Will be returned validation fails in this API")]
// csharpier-ignore - Csharpier ends up formatting this into multiple lines which causes too much noise
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(HttpValidationProblemDetails), Description = "Will be returned validation fails in a downstream API")]

However, I am not satisfied with having to copy multiple lines:

// csharpier-ignore - Csharpier ends up formatting this into multiple lines which causes too much noise

because it still causes too much noise.

Ideal solution

The docs mention that you can use // csharpier-ignore-start and //csharpier-ignore-end.

I would love to be able to do this:

// csharpier-ignore-start - Csharpier ends up formatting this into multiple lines which causes too much noise
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(ProblemDetails), Description = "Will be returned validation fails in this API")]
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(HttpValidationProblemDetails), Description = "Will be returned validation fails in a downstream API")]
// csharpier-ignore-end

I would like to be able to place the // csharpier-ignore-start at the start or 2nd/3rd/etc.. attribute, and // csharpier-ignore-end after the next (few) attributes or the final one, like the way my example works.

I'd like to submit this proposal and know your thoughts! :)

Activity

  1. belav commented on Nov 9, 2023

    @belav
    Owner

    @sander1095 I'll have to dig into to see how feasible this is. The ranged ignore can be problematic sometimes. In this case I believe the // csharpier-ignore-start is leading trivia on an attribute, and the corresponding // csharpier-ignore-end could be leading trivia on the modifiers, or on another attribute.

  2. added
    type:enhancement
    on Nov 9, 2023
  3. added this to the 0.27.0 milestone on Nov 9, 2023
  4. modified the milestones: 0.27.0, Planned on Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions