Skip to content

Commit

Permalink
Merge pull request #42 from alleyinteractive/feature/dom-attributes
Browse files Browse the repository at this point in the history
Adding DOMDocument property names to the ruleset
  • Loading branch information
srtfisher authored Jul 19, 2024
2 parents 6d3ed6b + d0e26be commit c024f52
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Alley-Interactive/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,24 @@
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>tests/*Test.php</exclude-pattern>
</rule>

<!-- Allow snakeCase for DOMDocument/DOMElement properties -->
<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="allowed_custom_properties" type="array">
<element value="className"/>
<element value="childNodes"/>
<element value="firstChild"/>
<element value="formatOutput"/>
<element value="lastChild"/>
<element value="nodeName"/>
<element value="nodeType"/>
<element value="nodeValue"/>
<element value="parentNode"/>
<element value="preserveWhiteSpace"/>
<element value="tagName"/>
<element value="textContent"/>
</property>
</properties>
</rule>
</ruleset>
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Keep a CHANGELOG](https://keepachangelog.com/en/1.0.0/)
### Unreleased

- Allow PSR-4 style `ClassName.php` file names to support our migration to PSR-4 for test files.
- Allow camelCase'd DOMDocument/DOMElement/etc. property names to not be flagged by `WordPress.NamingConventions.ValidVariableName`.

### 2.0.2

Expand Down
28 changes: 28 additions & 0 deletions tests/fixtures/pass/dom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* DOM Attributes test file.
*
* Ensure that DOMDocument/DOMElement/DOMNode attributes that are camelCase'd
* are not flagged by PHPCS.
*
* @package Alley\WP\Coding_Standards
*/

$ai_document = new DOMDocument();

// Ensure that DOMDocument properties are allowed.
$ai_document->preserveWhiteSpace = false;
$ai_document->formatOutput = true;

$ai_document->loadHTML(
file_get_contents( 'https://www.alley.com' ) // phpcs:ignore
);

// Interact with the DOM document.
$ai_element = $ai_document->getElementById( 'element-id' );

// Ensure that DOMElement properties are allowed.
$ai_element->textContent = 'Hello, world!';
$ai_element->className = 'element-class';

$ai_tag = $ai_element->tagName;

0 comments on commit c024f52

Please sign in to comment.