magento-coding-standard icon indicating copy to clipboard operation
magento-coding-standard copied to clipboard

Allow graphql pretty formatted files

Open p-makowski opened this issue 9 months ago • 12 comments

Currently checks for GraphQL ValidTypeName assumes that type definitions are always one-liners. For a better readability it is much better to format GraphQL files so that they are multiline.

type CartCampaign
    @doc(
        description: "CartCampaign returns the discount amount set in the quote"
    ) {
    full_discount_amount: Float
}

instead of

type CartCampaign @doc(description: "CartCampaign returns the discount amount set in the quote") {
    full_discount_amount: Float
}

There can many other tags like @doc and in current implementation all of them have to be in one line together with type to satisfy sniff. Changes in this PR will make pretty version to pass checks.

\PHP_CodeSniffer\Tokenizers\GRAPHQL::tokenize adds \n to token content anyway (see vendor/magento/magento-coding-standard/PHP_CodeSniffer/Tokenizers/GRAPHQL.php:134) to not screw up with line numbers.

This PR Closes #465

p-makowski avatar Sep 13 '23 20:09 p-makowski