Skip to content

Commit ba0bbce

Browse files
MC-19366: Adds a tokenizer for GraphQL schema files
1 parent 24607be commit ba0bbce

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

Magento2/ruleset.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<description>Magento Coding Standard</description>
44

55
<!-- File extensions to be checked. -->
6-
<arg name="extensions" value="php,phtml"/>
6+
<arg name="extensions" value="php,phtml,graphqls/GraphQL"/>
77

88
<!-- Severity 10 errors: Critical code issues. -->
99
<rule ref="Generic.Functions.CallTimePassByReference">
@@ -522,6 +522,10 @@
522522
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
523523
<severity>0</severity>
524524
</rule>
525+
<rule ref="Magento2.GraphQL.ValidTypeName">
526+
<severity>6</severity>
527+
<type>warning</type>
528+
</rule>
525529

526530
<!-- Severity 5 warnings: PHPDoc formatting and commenting issues. -->
527531
<rule ref="Magento2.Commenting.ClassAndInterfacePHPDocFormatting">
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace PHP_CodeSniffer\Tokenizers;
8+
9+
use PHP_CodeSniffer\Config;
10+
11+
/**
12+
* Implements a tokenizer for GraphQL files.
13+
*/
14+
class GraphQL extends JS
15+
{
16+
17+
protected $additionalTokenValues = [
18+
'type' => 'T_CLASS',
19+
'interface' => 'T_CLASS',
20+
'enum' => 'T_CLASS',
21+
'#' => 'T_COMMENT',
22+
];
23+
24+
/**
25+
* Constructor.
26+
*
27+
* @param string $content
28+
* @param Config $config
29+
* @param string $eolChar
30+
* @throws \PHP_CodeSniffer\Exceptions\TokenizerException
31+
*/
32+
public function __construct($content, Config $config, $eolChar = '\n')
33+
{
34+
//add our token values
35+
$this->tokenValues = array_merge(
36+
$this->tokenValues,
37+
$this->additionalTokenValues
38+
);
39+
40+
//let parent do its job (which will start tokenizing)
41+
parent::__construct($content, $config, $eolChar);
42+
}
43+
44+
/**
45+
* @inheritDoc
46+
*/
47+
public function processAdditional()
48+
{
49+
//NOP Does nothing intentionally
50+
}
51+
52+
}

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"require-dev": {
1515
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
1616
},
17+
"autoload": {
18+
"classmap": [
19+
"PHP_CodeSniffer/Tokenizers/"
20+
]
21+
},
1722
"scripts": {
1823
"post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..",
1924
"post-update-cmd": "vendor/bin/phpcs --config-set installed_paths ../../.."

0 commit comments

Comments
 (0)