WordPress / WordPress/WordPress-Coding-Standards

Verify method of detecting WordPress.Files.FileName.InvalidTemplateTagFileName

Open
#1,620 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Core Status: Needs investigation Type: Question
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

Bug Description

The WordPress.Files.FileName.InvalidTemplateTagFileName sniff incorrectly throws an error on src/wp-includes/template.php. This file is part of the Template subpackage, but doesn't contain template tags.

https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/e73a10e1c12ce07a12c3a8756efc54701458d23b/WordPress/Sniffs/Files/FileNameSniff.php#L213-L242

Minimal Code Snippet

$ vendor/bin/phpcs --sniffs=WordPress.Files.FileName src/wp-includes/template.php
E 1 / 1 (100%)



FILE: src/wp-includes/template.php
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 1 | ERROR | Files containing template tags should have "-template" appended to the end of the file name. Expected template-template.php, but found template.php.
   |       | (WordPress.Files.FileName.InvalidTemplateTagFileName)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

For bugs with fixers: How was the code fixed? How did you expect the code to be fixed?

Error Code

WordPress.Files.FileName.InvalidTemplateTagFileName

Environment

Question Answer
PHP version 7.1.23
PHP_CodeSniffer version 3.3.1
WPCS version 1.0.0
WPCS install type Composer project local

Tested Against develop branch?

  • I have verified the issue still exists in the develop branch of WPCS.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with vendor/bin/phpcs --sniffs=WordPress.Files.FileName src/wp-includes/template.php, then inspect WordPress/Sniffs/Files/FileNameSniff.php around lines 213-242. Done means this file no longer triggers InvalidTemplateTagFileName while files that actually contain template tags retain the expected filename check.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.