@@ -746,59 +746,65 @@ public static function dataDisableSelected()
746
746
{
747
747
return [
748
748
// Single sniff.
749
- 'disable: single sniff ' => [
749
+ 'disable: single sniff ' => [
750
750
'before ' => '// phpcs:disable Generic.Commenting.Todo ' ,
751
751
'expectedErrors ' => 1 ,
752
752
],
753
- 'disable: single sniff with reason ' => [
753
+ 'disable: single sniff with reason ' => [
754
754
'before ' => '# phpcs:disable Generic.Commenting.Todo -- for reasons ' ,
755
755
'expectedErrors ' => 1 ,
756
756
],
757
- 'disable: single sniff, docblock ' => [
757
+ 'disable: single sniff, docblock ' => [
758
758
'before ' => "/** \n * phpcs:disable Generic.Commenting.Todo \n */ " ,
759
759
'expectedErrors ' => 1 ,
760
760
],
761
- 'disable: single sniff, docblock, with @ ' => [
761
+ 'disable: single sniff, docblock, with @ ' => [
762
762
'before ' => "/** \n * @phpcs:disable Generic.Commenting.Todo \n */ " ,
763
763
'expectedErrors ' => 1 ,
764
764
],
765
765
766
766
// Multiple sniffs.
767
- 'disable: multiple sniffs in one comment ' => [
767
+ 'disable: multiple sniffs in one comment ' => [
768
768
'before ' => '// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant ' ,
769
769
],
770
- 'disable: multiple sniff in multiple comments ' => [
770
+ 'disable: multiple sniffs in one comment with superfluous space after comma ' => [
771
+ 'before ' => '// phpcs:disable Generic.Commenting.Todo, Generic.PHP.LowerCaseConstant ' ,
772
+ ],
773
+ 'disable: multiple sniff in multiple comments ' => [
771
774
'before ' => "// phpcs:disable Generic.Commenting.Todo \n// phpcs:disable Generic.PHP.LowerCaseConstant " ,
772
775
],
773
776
774
777
// Selectiveness variations.
775
- 'disable: complete category ' => [
778
+ 'disable: complete category ' => [
776
779
'before ' => '// phpcs:disable Generic.Commenting ' ,
777
780
'expectedErrors ' => 1 ,
778
781
],
779
- 'disable: whole standard ' => [
782
+ 'disable: whole standard ' => [
780
783
'before ' => '// phpcs:disable Generic ' ,
781
784
],
782
- 'disable: single errorcode ' => [
785
+ 'disable: single errorcode ' => [
783
786
'before ' => '# @phpcs:disable Generic.Commenting.Todo.TaskFound ' ,
784
787
'expectedErrors ' => 1 ,
785
788
],
786
- 'disable: single errorcode and a category ' => [
789
+ 'disable: single errorcode and a category ' => [
787
790
'before ' => '// phpcs:disable Generic.PHP.LowerCaseConstant.Found,Generic.Commenting ' ,
788
791
],
792
+ 'disable: single errorcode and a category with superfluous space after comma ' => [
793
+ 'before ' => '// phpcs:disable Generic.PHP.LowerCaseConstant.Found, Generic.Commenting ' ,
794
+ ],
789
795
790
796
// Wrong category/sniff/code.
791
- 'disable: wrong error code and category ' => [
797
+ 'disable: wrong error code and category ' => [
792
798
'before ' => "/** \n * phpcs:disable Generic.PHP.LowerCaseConstant.Upper,Generic.Comments \n */ " ,
793
799
'expectedErrors ' => 1 ,
794
800
'expectedWarnings ' => 1 ,
795
801
],
796
- 'disable: wrong category, docblock ' => [
802
+ 'disable: wrong category, docblock ' => [
797
803
'before ' => "/** \n * phpcs:disable Generic.Files \n */ " ,
798
804
'expectedErrors ' => 1 ,
799
805
'expectedWarnings ' => 1 ,
800
806
],
801
- 'disable: wrong category, docblock, with @ ' => [
807
+ 'disable: wrong category, docblock, with @ ' => [
802
808
'before ' => "/** \n * @phpcs:disable Generic.Files \n */ " ,
803
809
'expectedErrors ' => 1 ,
804
810
'expectedWarnings ' => 1 ,
@@ -876,6 +882,17 @@ public static function dataEnableSelected()
876
882
'expectedErrors ' => 1 ,
877
883
'expectedWarnings ' => 1 ,
878
884
],
885
+ 'disable/enable: multiple sniffs with superfluous space after comma ' => [
886
+ 'code ' => '
887
+ // phpcs:disable Generic.Commenting.Todo, Generic.PHP.LowerCaseConstant
888
+ $var = FALSE;
889
+ //TODO: write some code
890
+ // phpcs:enable Generic.Commenting.Todo, Generic.PHP.LowerCaseConstant
891
+ //TODO: write some code
892
+ $var = FALSE; ' ,
893
+ 'expectedErrors ' => 1 ,
894
+ 'expectedWarnings ' => 1 ,
895
+ ],
879
896
'disable: multiple sniffs; enable: one ' => [
880
897
'code ' => '
881
898
# phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant
@@ -1028,6 +1045,54 @@ public static function dataEnableSelected()
1028
1045
'expectedErrors ' => 0 ,
1029
1046
'expectedWarnings ' => 0 ,
1030
1047
],
1048
+ 'disable: two sniffs in one go; enable: both sniffs; ignore: one of those sniffs ' => [
1049
+ 'code ' => '
1050
+ // phpcs:disable Generic.PHP.LowerCaseConstant,Generic.Commenting.Todo
1051
+ //TODO: write some code
1052
+ $var = TRUE;
1053
+ // phpcs:enable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant
1054
+
1055
+ $var = FALSE; // phpcs:ignore Generic.PHP.LowerCaseConstant
1056
+ ' ,
1057
+ 'expectedErrors ' => 0 ,
1058
+ 'expectedWarnings ' => 0 ,
1059
+ ],
1060
+ 'disable: two sniffs in one go; enable: one sniff; ignore: enabled sniff ' => [
1061
+ 'code ' => '
1062
+ // phpcs:disable Generic.PHP.LowerCaseConstant, Generic.Commenting.Todo
1063
+ //TODO: write some code
1064
+ $var = TRUE;
1065
+ // phpcs:enable Generic.PHP.LowerCaseConstant
1066
+
1067
+ $var = FALSE; // phpcs:ignore Generic.PHP.LowerCaseConstant
1068
+ ' ,
1069
+ 'expectedErrors ' => 0 ,
1070
+ 'expectedWarnings ' => 0 ,
1071
+ ],
1072
+ 'disable: two sniffs in one go; enable: one sniff; ignore: category ' => [
1073
+ 'code ' => '
1074
+ // phpcs:disable Generic.PHP.LowerCaseConstant,Generic.Commenting.Todo
1075
+ //TODO: write some code
1076
+ $var = TRUE;
1077
+ // phpcs:enable Generic.PHP.LowerCaseConstant
1078
+
1079
+ $var = FALSE; // phpcs:ignore Generic.PHP
1080
+ ' ,
1081
+ 'expectedErrors ' => 0 ,
1082
+ 'expectedWarnings ' => 0 ,
1083
+ ],
1084
+ 'disable: two sniffs in one go; enable: category; ignore: sniff in category ' => [
1085
+ 'code ' => '
1086
+ // phpcs:disable Generic.PHP.LowerCaseConstant, Generic.Commenting.Todo
1087
+ //TODO: write some code
1088
+ $var = TRUE;
1089
+ // phpcs:enable Generic.PHP
1090
+
1091
+ $var = FALSE; // phpcs:ignore Generic.PHP.LowerCaseConstant
1092
+ ' ,
1093
+ 'expectedErrors ' => 0 ,
1094
+ 'expectedWarnings ' => 0 ,
1095
+ ],
1031
1096
'disable: standard; enable: category in standard; disable: sniff in category ' => [
1032
1097
'code ' => '
1033
1098
// phpcs:disable Generic
@@ -1106,34 +1171,49 @@ public function testIgnoreSelected($before, $expectedErrors, $expectedWarnings)
1106
1171
public static function dataIgnoreSelected ()
1107
1172
{
1108
1173
return [
1109
- 'no suppression ' => [
1174
+ 'no suppression ' => [
1110
1175
'before ' => '' ,
1111
1176
'expectedErrors ' => 2 ,
1112
1177
'expectedWarnings ' => 2 ,
1113
1178
],
1114
1179
1115
1180
// With suppression.
1116
- 'ignore: single sniff ' => [
1181
+ 'ignore: single sniff ' => [
1117
1182
'before ' => '// phpcs:ignore Generic.Commenting.Todo ' ,
1118
1183
'expectedErrors ' => 2 ,
1119
1184
'expectedWarnings ' => 1 ,
1120
1185
],
1121
- 'ignore: multiple sniffs ' => [
1186
+ 'ignore: multiple sniffs ' => [
1122
1187
'before ' => '// phpcs:ignore Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant ' ,
1123
1188
'expectedErrors ' => 1 ,
1124
1189
'expectedWarnings ' => 1 ,
1125
1190
],
1126
- 'disable: single sniff; ignore: single sniff ' => [
1191
+ 'ignore: multiple sniffs with superfluous space after comma ' => [
1192
+ 'before ' => '// phpcs:ignore Generic.Commenting.Todo , Generic.PHP.LowerCaseConstant ' ,
1193
+ 'expectedErrors ' => 1 ,
1194
+ 'expectedWarnings ' => 1 ,
1195
+ ],
1196
+ 'ignore: one sniff, one category with superfluous space after comma ' => [
1197
+ 'before ' => '// phpcs:ignore Generic.Commenting.Todo, Generic.PHP ' ,
1198
+ 'expectedErrors ' => 1 ,
1199
+ 'expectedWarnings ' => 1 ,
1200
+ ],
1201
+ 'ignore: one category, one error code with superfluous space after comma ' => [
1202
+ 'before ' => '// phpcs:ignore Generic.Commenting, Generic.PHP.LowerCaseConstant.Found ' ,
1203
+ 'expectedErrors ' => 1 ,
1204
+ 'expectedWarnings ' => 1 ,
1205
+ ],
1206
+ 'disable: single sniff; ignore: single sniff ' => [
1127
1207
'before ' => "// phpcs:disable Generic.Commenting.Todo \n// phpcs:ignore Generic.PHP.LowerCaseConstant " ,
1128
1208
'expectedErrors ' => 1 ,
1129
1209
'expectedWarnings ' => 0 ,
1130
1210
],
1131
- 'ignore: category of sniffs ' => [
1211
+ 'ignore: category of sniffs ' => [
1132
1212
'before ' => '# phpcs:ignore Generic.Commenting ' ,
1133
1213
'expectedErrors ' => 2 ,
1134
1214
'expectedWarnings ' => 1 ,
1135
1215
],
1136
- 'ignore: whole standard ' => [
1216
+ 'ignore: whole standard ' => [
1137
1217
'before ' => '// phpcs:ignore Generic ' ,
1138
1218
'expectedErrors ' => 1 ,
1139
1219
'expectedWarnings ' => 1 ,
@@ -1228,6 +1308,16 @@ public static function dataCommenting()
1228
1308
'expectedErrors ' => 2 ,
1229
1309
'expectedWarnings ' => 1 ,
1230
1310
],
1311
+ 'ignore: multi sniff, line above and trailing - with comment and superfluous whitespace ' => [
1312
+ 'code ' => '
1313
+ // phpcs:ignore Generic.Commenting.Todo , Generic.PHP.LowerCaseConstant.Found -- Because reasons
1314
+ $var = FALSE; //TODO: write some code
1315
+ $var = FALSE; // phpcs:ignore Generic.Commenting.Todo , Generic.PHP.LowerCaseConstant.Found --Because reasons
1316
+ //TODO: write some code
1317
+ $var = FALSE; ' ,
1318
+ 'expectedErrors ' => 1 ,
1319
+ 'expectedWarnings ' => 1 ,
1320
+ ],
1231
1321
'enable before disable, sniff not in standard ' => [
1232
1322
'code ' => '
1233
1323
// phpcs:enable Generic.PHP.NoSilencedErrors -- Because reasons
0 commit comments