Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding DOMDocument property names to the ruleset #42

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;