Skip to content

Commit

Permalink
Enable MediaWiki.Arrays.TrailingComma sniff
Browse files Browse the repository at this point in the history
Enforce trailing commas in multi-line arrays, and no trailing commas in
single-line arrays.

In one line in FullStatementRdfBuilderTest, the extra comma pushes the
line length over the hard limit (140 → 141 characters), so split the
array across multiple lines to keep it below the limit. The same thing
happens in one line in RdfBuilderTest, so split the DatabaseEntitySource
constructor call across multiple lines.

Bug: T325532
Change-Id: I184b019ba7ab8b435cd0774cac04011dac4585bd
  • Loading branch information
lucaswerkmeister authored and WMDE bot committed Mar 6, 2023
1 parent 924a00d commit 0f42b86
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private function newTestStatement() {

$statement->setQualifiers( new SnakList( [
new PropertyNoValueSnak( 1337 ),
new PropertyValueSnak( 23, new NumberValue( 42 ) )
new PropertyValueSnak( 23, new NumberValue( 42 ) ),
] ) );

$statement->setGuid( 'some guid be here' );
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/RealEntitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function getEntitySerializationsFromDir( $dir ) {
if ( $fileInfo->getExtension() === 'json' ) {
$argumentLists[] = [
$fileInfo->getFilename(),
json_decode( file_get_contents( $fileInfo->getPathname() ), true )
json_decode( file_get_contents( $fileInfo->getPathname() ), true ),
];
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Deserializers/EntityDeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testLegacySerializationWithoutId_exceptionIsThrown() {

private function getLegacyItemSerializationWithoutId() {
return [ 'aliases' => [
'en' => [ 'foo', 'bar' ]
'en' => [ 'foo', 'bar' ],
] ];
}

Expand All @@ -125,7 +125,7 @@ private function getCurrentItemSerializationWithoutId() {
'language' => 'en',
'value' => 'bar',
],
]
],
] ];
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Deserializers/LegacyEntityIdDeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public function legacyIdProvider() {
return [
[
new ItemId( 'Q42' ),
[ 'item', 42 ]
[ 'item', 42 ],
],

[
new NumericPropertyId( 'P1337' ),
[ 'property', 1337 ]
[ 'property', 1337 ],
],
];
}
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/Deserializers/LegacyFingerprintDeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function TermListProvider() {
return [
[
[],
new TermList( [] )
new TermList( [] ),
],

[
Expand All @@ -52,7 +52,7 @@ public function TermListProvider() {
new TermList( [
new Term( 'en', 'foo' ),
new Term( 'de', 'bar' ),
] )
] ),
],
];
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public function descriptionListProvider() {
return [
[
[],
new TermList( [] )
new TermList( [] ),
],

[
Expand All @@ -105,7 +105,7 @@ public function descriptionListProvider() {
new TermList( [
new Term( 'en', 'foo' ),
new Term( 'de', 'bar' ),
] )
] ),
],
];
}
Expand All @@ -131,7 +131,7 @@ public function aliasesListProvider() {
return [
[
[],
new AliasGroupList( [] )
new AliasGroupList( [] ),
],

[
Expand All @@ -145,7 +145,7 @@ public function aliasesListProvider() {
new AliasGroup( 'en', [ 'foo', 'bar' ] ),
new AliasGroup( 'de', [ 'foo', 'bar', 'baz' ] ),
new AliasGroup( 'nl', [ 'bah' ] ),
] )
] ),
],
];
}
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/Deserializers/LegacyItemDeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public function invalidSerializationProvider() {
[ null ],

[ [
'links' => [ null ]
'links' => [ null ],
] ],

[ [
'claims' => null
'claims' => null,
] ],

[ [
'claims' => [ null ]
'claims' => [ null ],
] ],

[ [
'entity' => 42
'entity' => 42,
] ],
];
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public function testGivenLinks_itemHasSiteLinks() {
'links' => [
'foo' => 'bar',
'baz' => 'bah',
]
],
],
$item
);
Expand Down Expand Up @@ -132,8 +132,8 @@ public function testGivenStatement_itemHasStatement() {
$this->assertDeserialization(
[
'claims' => [
$this->newStatementSerialization()
]
$this->newStatementSerialization(),
],
],
$item
);
Expand All @@ -151,7 +151,7 @@ private function newStatementSerialization() {
'q' => [],
'g' => 'foo',
'rank' => Statement::RANK_NORMAL,
'refs' => []
'refs' => [],
];
}

Expand All @@ -162,8 +162,8 @@ public function testGivenStatementWithLegacyKey_itemHasStatement() {
$this->assertDeserialization(
[
'statements' => [
$this->newStatementSerialization()
]
$this->newStatementSerialization(),
],
],
$item
);
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/Deserializers/LegacyPropertyDeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public function testGivenInvalidEntityId_exceptionIsThrown() {
$this->expectDeserializationException();
$this->deserializer->deserialize( [
'datatype' => 'foo',
'entity' => 'spam spam spam'
'entity' => 'spam spam spam',
] );
}

public function testGivenNonPropertyEntityId_exceptionIsThrown() {
$this->expectDeserializationException();
$this->deserializer->deserialize( [
'datatype' => 'foo',
'entity' => 'q42'
'entity' => 'q42',
] );
}

Expand All @@ -79,7 +79,7 @@ public function testGivenNoPropertyIdId_noPropertyIdIsSet() {
public function testGivenValidPropertyIdId_propertyIdIsSet() {
$property = $this->deserializer->deserialize( [
'datatype' => 'foo',
'entity' => 'p42'
'entity' => 'p42',
] );

$this->assertEquals( new NumericPropertyId( 'p42' ), $property->getId() );
Expand All @@ -92,7 +92,7 @@ public function testGivenLabels_getLabelsReturnsThem( array $labels ) {
/** @var Property $property */
$property = $this->deserializer->deserialize( [
'datatype' => 'foo',
'label' => $labels
'label' => $labels,
] );

$this->assertEquals( $labels, $property->getFingerprint()->getLabels()->toTextArray() );
Expand Down Expand Up @@ -121,7 +121,7 @@ public function testGivenDescriptions_getDescriptionsReturnsThem( array $descrip
/** @var Property $property */
$property = $this->deserializer->deserialize( [
'datatype' => 'foo',
'description' => $descriptions
'description' => $descriptions,
] );

$this->assertEquals( $descriptions, $property->getFingerprint()->getDescriptions()->toTextArray() );
Expand All @@ -139,7 +139,7 @@ public function testGivenAliases_getAliasesReturnsThem( array $aliases ) {
/** @var Property $property */
$property = $this->deserializer->deserialize( [
'datatype' => 'foo',
'aliases' => $aliases
'aliases' => $aliases,
] );

$this->assertEquals( $aliases, $property->getFingerprint()->getAliasGroups()->toTextArray() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public function serializationProvider() {
'baz' => [
'name' => 'bah',
'badges' => [],
]
],
] ],

[ [
'foo' => [
'name' => 'bar',
'badges' => [ 'Q42', 'Q1337' ],
]
],
] ],

[ [
Expand All @@ -105,7 +105,7 @@ public function testDeserialization() {
new SiteLinkList(
[
new SiteLink( 'foo', 'bar', [ new ItemId( 'Q42' ), new ItemId( 'Q1337' ) ] ),
new SiteLink( 'bar', 'baz' )
new SiteLink( 'bar', 'baz' ),
]
),
$this->deserializer->deserialize(
Expand All @@ -114,7 +114,7 @@ public function testDeserialization() {
'name' => 'bar',
'badges' => [ 'Q42', 'Q1337' ],
],
'bar' => 'baz'
'bar' => 'baz',
]
)
);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/Deserializers/LegacySnakDeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ public function testValueSnakDeserialization() {
'value',
42,
'string',
'foo'
'foo',
] )
);
}

public function testGivenInvalidDataValue_unDerializableValueIsConstructed() {
$dataValueDeserializer = new DataValueDeserializer( [
'string' => StringValue::class
'string' => StringValue::class,
] );

$deserializer = new LegacySnakDeserializer( $dataValueDeserializer );
Expand All @@ -105,7 +105,7 @@ public function testGivenInvalidDataValue_unDerializableValueIsConstructed() {
'value',
42,
'string',
1337
1337,
] );

$this->assertInstanceOf( PropertyValueSnak::class, $snak );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testGivenValidSerialization_deserializeReturnsCorrectSnakList()
[
'somevalue',
1337,
]
],
];

$this->assertEquals(
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/Deserializers/LegacyStatementDeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function invalidSerializationProvider() {
'q' => [],
'g' => 9001,
'refs' => [],
'rank' => Statement::RANK_PREFERRED
'rank' => Statement::RANK_PREFERRED,
] ],
[ [
'm' => [ 'novalue', 42 ],
Expand Down Expand Up @@ -77,7 +77,7 @@ public function testGivenValidSerialization_deserializeReturnsStatement() {
'q' => [],
'g' => null,
'rank' => Statement::RANK_NORMAL,
'refs' => []
'refs' => [],
];

$this->assertEquals(
Expand All @@ -101,11 +101,11 @@ public function testGivenValidSerialization_deserializeReturnsStatementWithQuali
'm' => [ 'novalue', 42 ],
'q' => [
[ 'novalue', 23 ],
[ 'novalue', 1337 ]
[ 'novalue', 1337 ],
],
'g' => 'foo bar baz',
'rank' => Statement::RANK_NORMAL,
'refs' => []
'refs' => [],
];

$this->assertEquals(
Expand All @@ -127,7 +127,7 @@ public function testGivenValidSerialization_deserializeReturnsStatementWithRefer
new PropertyNoValueSnak( 1 ),
new PropertyNoValueSnak( 2 ),
] )
)
),
] )
);

Expand All @@ -138,16 +138,16 @@ public function testGivenValidSerialization_deserializeReturnsStatementWithRefer
'm' => [ 'novalue', 42 ],
'q' => [
[ 'novalue', 23 ],
[ 'novalue', 1337 ]
[ 'novalue', 1337 ],
],
'g' => 'foo bar baz',
'rank' => Statement::RANK_PREFERRED,
'refs' => [
[
[ 'novalue', 1 ],
[ 'novalue', 2 ]
]
]
[ 'novalue', 2 ],
],
],
];

$deserialized = $this->deserializer->deserialize( $serialization );
Expand Down

0 comments on commit 0f42b86

Please sign in to comment.