Skip to content

Commit a40711d

Browse files
authored
feat(AlphabeticallySortedUses): Add sniff to check and fix use statement order (#3310013)
1 parent 5a1779e commit a40711d

File tree

8 files changed

+16
-15
lines changed

8 files changed

+16
-15
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
10+
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1']
1111
phpstan: ['0']
1212
# We only need to run PHPStan once on the latest PHP version.
1313
include:

coder_sniffer/Drupal/ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<rule ref="PSR2.Namespaces.UseDeclaration" />
122122

123123
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" />
124+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" />
124125
<rule ref="SlevomatCodingStandard.PHP.ShortList" />
125126

126127
<rule ref="Squiz.Arrays.ArrayDeclaration" />

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
],
1515
"license": "GPL-2.0-or-later",
1616
"require": {
17-
"php": ">=7.1",
17+
"php": ">=7.2",
1818
"ext-mbstring": "*",
1919
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1 || ^1.0.0",
2020
"sirbrillig/phpcs-variable-analysis": "^2.11.7",
21-
"slevomat/coding-standard": "^7.0 || ^8.0",
21+
"slevomat/coding-standard": "^8.11",
2222
"squizlabs/php_codesniffer": "^3.7.1",
2323
"symfony/yaml": ">=3.4.0"
2424
},

tests/Drupal/Classes/ClassCreateInstanceUnitTest.inc.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3-
use Vendor\DateTools\DateInterval;
43
use Vendor\DateTools;
4+
use Vendor\DateTools\DateInterval;
55

66
$x = array(new Foo(), array());
77
$y = new Foo();

tests/Drupal/Classes/FullyQualifiedNamespaceUnitTest.inc.fixed

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* Example.
66
*/
77

8-
use Test\MultiLineSecond;
9-
use Test\Foo;
10-
use Test\NotUsed;
11-
use Test\Bar;
128
use Test\Alias as TestAlias;
9+
use Test\Bar;
10+
use Test\Foo;
1311
use Test\MultiLine as MultiLineAlias;
12+
use Test\MultiLineSecond;
13+
use Test\NotUsed;
1414

1515
/**
1616
* Example.

tests/Drupal/Classes/UnusedUseStatementUnitTest.inc.fixed

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace MyNamespace\Depth;
44

5-
use Thing\NotUsed;
6-
use Thing\Fail\ActuallyUsed;
7-
use Test\TraitTest;
8-
use Thing\DifferentName as UsedOtherName;
95
use Example\MyUrlHelper;
106
use MyNamespace\Depth\SomeClass as CoreSomeClass;
7+
use Test\TraitTest;
8+
use Thing\DifferentName as UsedOtherName;
9+
use Thing\Fail\ActuallyUsed;
10+
use Thing\NotUsed;
1111

1212
/**
1313
* Bla.

tests/Drupal/Classes/UseGlobalClassUnitTest.inc.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Example.
66
*/
77

8+
use Namespaced\MultiLine2 as MultiLineAlias2;
89
use Namespaced\TestClass;
910
use Namespaced\TestClassSecond as NamespacedAlias;
10-
use Namespaced\MultiLine2 as MultiLineAlias2;
1111
use function count;
1212

1313
/**

tests/Drupal/good/good.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
declare(strict_types=1);
2222

23-
use Drupal\very_long_module_name_i_am_inventing_here_trololololo\SuperManager;
24-
use Drupal\some_module\ExampleClass as AliasedExampleClass;
2523
use Drupal\mymodule\TestReturnType;
24+
use Drupal\some_module\ExampleClass as AliasedExampleClass;
25+
use Drupal\very_long_module_name_i_am_inventing_here_trololololo\SuperManager;
2626

2727
// Singleline comment before a code line.
2828
$foo = 'bar';

0 commit comments

Comments
 (0)