Skip to content

Commit c37b4dd

Browse files
Merge pull request #973 from WordPress/add-prefixing-check
Add prefixing check
2 parents db4c3bb + 0741df0 commit c37b4dd

28 files changed

Lines changed: 7196 additions & 60 deletions

.typos.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[default]
22
extend-ignore-re = [
3+
"avail_post_stati",
34
"ba",
5+
"MAGPIE_INITALIZED",
6+
"setted_site_transient",
7+
"setted_transient",
48
]
59

610
[files]

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"automattic/vipwpcs": "^3.0.0",
1010
"composer/installers": "^2.2",
1111
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
12+
"nikic/php-parser": "^4",
1213
"plugin-check/phpcs-sniffs": "@dev",
1314
"wp-coding-standards/wpcs": "^3.2.0"
1415
},
@@ -58,7 +59,8 @@
5859
},
5960
"platform": {
6061
"php": "7.4"
61-
}
62+
},
63+
"sort-packages": true
6264
},
6365
"scripts": {
6466
"behat": "BEHAT_FEATURES_FOLDER=tests/behat/features run-behat-tests",

composer.lock

Lines changed: 57 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Class Prefixing_Check.
4+
*
5+
* @package plugin-check
6+
*/
7+
8+
namespace WordPress\Plugin_Check\Checker\Checks\Plugin_Repo;
9+
10+
use WordPress\Plugin_Check\Checker\Check_Categories;
11+
use WordPress\Plugin_Check\Checker\Check_Result;
12+
use WordPress\Plugin_Check\Checker\Checks\Abstract_PHP_CodeSniffer_Check;
13+
use WordPress\Plugin_Check\Traits\Amend_Check_Result;
14+
use WordPress\Plugin_Check\Traits\Prefix_Utils;
15+
use WordPress\Plugin_Check\Traits\Stable_Check;
16+
17+
/**
18+
* Check for prefixing.
19+
*
20+
* @since 1.7.0
21+
*/
22+
class Prefixing_Check extends Abstract_PHP_CodeSniffer_Check {
23+
24+
use Amend_Check_Result;
25+
use Prefix_Utils;
26+
use Stable_Check;
27+
28+
/**
29+
* Gets the categories for the check.
30+
*
31+
* Every check must have at least one category.
32+
*
33+
* @since 1.7.0
34+
*
35+
* @return array The categories for the check.
36+
*/
37+
public function get_categories() {
38+
return array( Check_Categories::CATEGORY_PLUGIN_REPO );
39+
}
40+
41+
/**
42+
* Returns an associative array of arguments to pass to PHPCS.
43+
*
44+
* @since 1.7.0
45+
*
46+
* @param Check_Result $result The check result to amend, including the plugin context to check.
47+
* @return array An associative array of PHPCS CLI arguments.
48+
*/
49+
protected function get_args( Check_Result $result ) {
50+
$args = array(
51+
'extensions' => 'php',
52+
'standard' => 'WordPress',
53+
'sniffs' => 'WordPress.NamingConventions.PrefixAllGlobals',
54+
);
55+
56+
$prefixes = $this->get_potential_prefixes( $result );
57+
58+
if ( ! empty( $prefixes ) ) {
59+
$args['runtime-set'] = array(
60+
'prefixes' => implode( ',', $prefixes ),
61+
);
62+
}
63+
64+
return $args;
65+
}
66+
67+
/**
68+
* Gets the description for the check.
69+
*
70+
* Every check must have a short description explaining what the check does.
71+
*
72+
* @since 1.7.0
73+
*
74+
* @return string Description.
75+
*/
76+
public function get_description(): string {
77+
return __( 'Checks plugin for unique prefixing for everything the plugin defines in the public namespace.', 'plugin-check' );
78+
}
79+
80+
/**
81+
* Gets the documentation URL for the check.
82+
*
83+
* Every check must have a URL with further information about the check.
84+
*
85+
* @since 1.7.0
86+
*
87+
* @return string The documentation URL.
88+
*/
89+
public function get_documentation_url(): string {
90+
return __( 'https://make.wordpress.org/plugins/handbook/performing-reviews/review-checklist/#code', 'plugin-check' );
91+
}
92+
}

includes/Checker/Default_Check_Repository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private function register_default_checks() {
9696
'non_blocking_scripts' => new Checks\Performance\Non_Blocking_Scripts_Check(),
9797
'offloading_files' => new Checks\Plugin_Repo\Offloading_Files_Check(),
9898
'setting_sanitization' => new Checks\Plugin_Repo\Setting_Sanitization_Check(),
99+
'prefixing' => new Checks\Plugin_Repo\Prefixing_Check(),
99100
)
100101
);
101102

0 commit comments

Comments
 (0)