wp-js-standards
Skill4 starsChanged 3 days agoMITView on GitHub
WordPress JavaScript Coding Standards reference — tabs and spacing, semicolons, braces, const and let over var, camelCase naming with acronym rules, strict equality, single quotes, type checks, switch statements, best practices, ESLint enforcement. Use when writing or reviewing theme/plugin JavaScript, ES modules, or when asked about WordPress JS conventions. Pairs with wp-css-standards and wp-html-standards.
In this repository44 other files it gives its agents.
- AGENTS.mdAGENTS.md
- diagnosing-bugsSkill
- domain-modelingSkill
- fixSkill
- frontend-designSkill
- grill-meSkill
- grill-with-docsSkill
- gsap-coreSkill
- gsap-performanceSkill
- gsap-pluginsSkill
- gsap-scrolltriggerSkill
- gsap-timelineSkill
- gsap-utilsSkill
- handoffSkill
- landing-page-conversion-auditSkill
- refactorSkill
- researchSkill
- reviewSkill
- share-learningSkill
- tddSkill
- threejs-animationSkill
- threejs-fundamentalsSkill
- threejs-geometrySkill
- threejs-interactionSkill
- threejs-lightingSkill
- threejs-loadersSkill
- threejs-materialsSkill
- threejs-postprocessingSkill
- threejs-shadersSkill
- threejs-texturesSkill
- to-specSkill
- to-ticketsSkill
- verifySkill
- wp-accessibilitySkill
- wp-accessibility-standardsSkill
- wp-css-standardsSkill
- wp-github-actions-standardsSkill
- wp-html-standardsSkill
- wp-i18nSkill
- wp-performanceSkill
- wp-php-standardsSkill
- wp-pluginSkill
- wp-security-auditSkill
- wp-themeSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Write and review JavaScript that follows the WordPress JS Coding Standards, knowing exactly what ESLint enforces vs what stays review-only.
- Very specific: line 38
No filler spaces in empty constructs: {}, [], fn()
- Distinctive: line 46
Always. Never rely on Automatic Semicolon Insertion
- Very specific: line 78
Before the code they refer to, preceded by a blank line.
- Very specific: line 122
Never introduce var or == in new code.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
WordPress JavaScript Coding Standards
Distilled from the official WordPress JavaScript Coding Standards (developer.wordpress.org),
which adapts the jQuery style guide. WP differs from jQuery: single quotes, indented
case statements, consistent function-body indentation, spaces after !.
Goal
Write and review JavaScript that follows the WordPress JS Coding Standards, knowing exactly what ESLint enforces vs what stays review-only.
When to use
- Writing or reviewing theme/plugin JS (ES modules, components, utilities)
- Answering "what does the WordPress JS standard say about X"
Code refactoring
- New or updated code must conform and pass lint; refactoring older files to the standard is not urgent — whitespace-only patches to working files are strongly discouraged
The standard
Spacing
- Tabs for indentation; no trailing whitespace; no whitespace on blank lines
- Lines usually ≤ 80 chars, never > 100 (tabs count as 4)
if/else/for/while/tryalways use braces and multiple lines- Unary operators (
++,--,!) no space next to operand — but!gets a following space (! condition);,and;no preceding space;:after a property name no preceding space; ternary?/:spaced both sides - No filler spaces in empty constructs:
{},[],fn() - Newline at end of file
- Extra spaces inside function-call parens and array/object brackets:
foo( arg ),arr[ 0 ],object[ property ]— mirroring the PHP standard - One property per line for multi-line objects/arrays, trailing comma
Semicolons
- Always. Never rely on Automatic Semicolon Insertion
Indentation and line breaks
- Braces on the same line as the statement, closing brace on its own line
- Multi-line statements break after operators, not before:
'...' +then the next chunk on the following line - Long conditionals: each operand on its own line, indented one level from the parens
- Chained method calls: one call per line, first call on its own line from the
receiver; extra indent when the context changes (
.children())
Variables
- ES2015+:
constunless reassigned, thenlet; declare at first use — novar - Globals used in a file documented at the top:
/* global passwordStrength:true */(:true= defined here, omitted = read-only) - jQuery via
( function ( $ ) { ... } )( jQuery );— never assume a global$ - Files that add to or modify the global
wpobject access it safely:window.wp = window.wp || {};at the top — never overwrite existing properties
Naming
- Variables/functions: camelCase, lowercase first letter, full words
(
userId,getContentHeight) - Acronyms all caps mid-name (
currentDOMDocument); abbreviations camelCase (userId— "Id" is an abbreviation); at name start respect camelCase casing (domDocument, classDOMDocument) - Classes/constructors: UpperCamelCase
- Constants never reassigned or mutated: SCREAMING_SNAKE_CASE, top-most scope
Comments
- Before the code they refer to, preceded by a blank line; capital first letter;
full stop on sentences; single space after
// - JSDoc via
/** */for documentation comments
Equality and type checks
- Strict equality always:
===/!==, never==/!= - Type checks:
typeof x === 'string' | 'number' | 'boolean' | 'object'; arrays viaArray.isArray; nullx === null; undefinedtypeof x === 'undefined'for globals,x === undefinedfor locals
Strings
- Single quotes for string literals; escape embedded single quotes
Switch
- Discouraged generally; when used:
breakper case (exceptdefault), explicit fall-through comments, case indented one tab inside switch, set values in cases and return after the switch — neverreturninside a case
Best practices
- Arrays via
[]literal; objects via{}literal (constructor only for prototypes); dot notation unless the key is dynamic - Cache loop maxes:
for ( i = 0, max = getCount(); i < max; i++ ) - Iterate jQuery collections only with
$collection.each(); raw data with native iteration — never jQuery for plain objects - Underscore collection functions (
_.each,_.map,_.reduce) for efficient readable transforms of large data sets; chain with_.chain( obj ).keys().map( fn ).value() - Type-check with Underscore's
_.isFunction/_.isArray/_.isUndefinedwhere Backbone/Underscore are already in use
Enforcement mapping
| Rule | Enforced by |
| Tabs, quotes, semicolons, trailing commas, line length | Prettier (useTabs: true, singleQuote, semi) |
no-var (const/let), ===, no-unused-vars, camelCase, no-shadow, no-nested-ternary, no-console (warn/error allowed) | ESLint @wordpress/eslint-plugin (flat config) |
document.activeElement → ownerDocument patterns | @wordpress/no-global-active-element |
| Globals documentation, loop-cache, type-check idioms, switch discipline | Review-only |
Rules
- Never introduce
varor==in new code; the lint gate is part offormat:all:check— never bypass it - Browser globals belong in
eslint.config.mjsglobals, noteslint-disable - Bitwise color math in rendering code is a documented deviation
(
no-bitwise: offwith a rationale comment)
Output contract
- Written JS: standards-compliant and lint-clean on first pass
- Review findings:
file:line+ rule + fix
References
- JavaScript Coding Standards — official
- Internal: front-end stack (component pattern, ESLint config) · wp-html-standards · wp-css-standards
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

