Skip to content

Commit bf094ef

Browse files
committed
fix: Apply prettier formatting to README and validation.ts
1 parent 50722d5 commit bf094ef

File tree

2 files changed

+69
-69
lines changed

2 files changed

+69
-69
lines changed

packages/client/README.md

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Client library for the WordPress Abilities API, providing a standardized way to
44

55
## Table of Contents
66

7-
- [Installation](#installation)
8-
- [Usage](#usage)
9-
- [API Reference](#api-reference)
10-
- [Development](#development)
11-
- [Testing](#testing)
7+
- [Installation](#installation)
8+
- [Usage](#usage)
9+
- [API Reference](#api-reference)
10+
- [Development](#development)
11+
- [Testing](#testing)
1212

1313
## Installation
1414

@@ -67,13 +67,13 @@ const { listAbilities, getAbility, executeAbility } = wp.abilities;
6767
const abilities = await listAbilities();
6868

6969
// Get a specific ability
70-
const ability = await getAbility( 'my-plugin/my-ability' );
70+
const ability = await getAbility('my-plugin/my-ability');
7171

7272
// Execute an ability
73-
const result = await executeAbility( 'my-plugin/my-ability', {
74-
param1: 'value1',
75-
param2: 'value2'
76-
} );
73+
const result = await executeAbility('my-plugin/my-ability', {
74+
param1: 'value1',
75+
param2: 'value2',
76+
});
7777
```
7878

7979
### Using with React and WordPress Data
@@ -85,28 +85,28 @@ import { useSelect } from '@wordpress/data';
8585
import { store as abilitiesStore } from '@wordpress/abilities';
8686

8787
function MyComponent() {
88-
const abilities = useSelect(
89-
( select ) => select( abilitiesStore ).getAbilities(),
90-
[]
91-
);
92-
93-
const specificAbility = useSelect(
94-
( select ) => select( abilitiesStore ).getAbility( 'my-plugin/my-ability' ),
95-
[]
96-
);
97-
98-
return (
99-
<div>
100-
<h2>All Abilities</h2>
101-
<ul>
102-
{ abilities.map( ( ability ) => (
103-
<li key={ ability.name }>
104-
<strong>{ ability.label }</strong>: { ability.description }
105-
</li>
106-
) ) }
107-
</ul>
108-
</div>
109-
);
88+
const abilities = useSelect(
89+
(select) => select(abilitiesStore).getAbilities(),
90+
[]
91+
);
92+
93+
const specificAbility = useSelect(
94+
(select) => select(abilitiesStore).getAbility('my-plugin/my-ability'),
95+
[]
96+
);
97+
98+
return (
99+
<div>
100+
<h2>All Abilities</h2>
101+
<ul>
102+
{abilities.map((ability) => (
103+
<li key={ability.name}>
104+
<strong>{ability.label}</strong>: {ability.description}
105+
</li>
106+
))}
107+
</ul>
108+
</div>
109+
);
110110
}
111111
```
112112

@@ -120,46 +120,46 @@ Returns all registered abilities. Automatically handles pagination to fetch all
120120

121121
```javascript
122122
const abilities = await listAbilities();
123-
console.log( `Found ${abilities.length} abilities` );
123+
console.log(`Found ${abilities.length} abilities`);
124124
```
125125

126126
#### `getAbility(name: string): Promise<Ability | null>`
127127

128128
Returns a specific ability by name, or null if not found.
129129

130130
```javascript
131-
const ability = await getAbility( 'my-plugin/create-post' );
132-
if ( ability ) {
133-
console.log( `Found ability: ${ability.label}` );
131+
const ability = await getAbility('my-plugin/create-post');
132+
if (ability) {
133+
console.log(`Found ability: ${ability.label}`);
134134
}
135135
```
136136

137137
#### `executeAbility(name: string, input?: Record<string, any>): Promise<any>`
138138

139139
Executes an ability with optional input parameters. The HTTP method is automatically determined based on the ability's type:
140140

141-
- `resource` type abilities use GET (read-only operations)
142-
- `tool` type abilities use POST (write operations)
141+
- `resource` type abilities use GET (read-only operations)
142+
- `tool` type abilities use POST (write operations)
143143

144144
```javascript
145145
// Execute a resource ability (GET)
146-
const data = await executeAbility( 'my-plugin/get-data', {
147-
id: 123
148-
} );
146+
const data = await executeAbility('my-plugin/get-data', {
147+
id: 123,
148+
});
149149

150150
// Execute a tool ability (POST)
151-
const result = await executeAbility( 'my-plugin/create-item', {
152-
title: 'New Item',
153-
content: 'Item content'
154-
} );
151+
const result = await executeAbility('my-plugin/create-item', {
152+
title: 'New Item',
153+
content: 'Item content',
154+
});
155155
```
156156

157157
### Store Selectors
158158

159159
When using with `@wordpress/data`:
160160

161-
- `getAbilities()` - Returns all abilities from the store
162-
- `getAbility(name)` - Returns a specific ability from the store
161+
- `getAbilities()` - Returns all abilities from the store
162+
- `getAbility(name)` - Returns a specific ability from the store
163163

164164
## Development
165165

@@ -201,7 +201,7 @@ npm run test:unit:debug
201201

202202
Tests are organized following WordPress conventions:
203203

204-
- Unit tests are located in `src/__tests__/`
205-
- Store tests are located in `src/store/__tests__/`
206-
- Test files use `.test.ts` or `.test.js` extension
207-
- Tests use Jest with `@wordpress/jest-preset-default` configuration
204+
- Unit tests are located in `src/__tests__/`
205+
- Store tests are located in `src/store/__tests__/`
206+
- Test files use `.test.ts` or `.test.js` extension
207+
- Tests use Jest with `@wordpress/jest-preset-default` configuration

packages/client/src/validation.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,37 +92,37 @@ function formatAjvError(ajvError: any, param: string): string {
9292
return `${fullParam} is invalid (failed ${ajvError.keyword} validation).`;
9393

9494
case 'minLength':
95-
return `${fullParam} must be at least ${ajvError.params.limit} character${
96-
ajvError.params.limit === 1 ? '' : 's'
97-
} long.`;
95+
return `${fullParam} must be at least ${
96+
ajvError.params.limit
97+
} character${ajvError.params.limit === 1 ? '' : 's'} long.`;
9898

9999
case 'maxLength':
100-
return `${fullParam} must be at most ${ajvError.params.limit} character${
101-
ajvError.params.limit === 1 ? '' : 's'
102-
} long.`;
100+
return `${fullParam} must be at most ${
101+
ajvError.params.limit
102+
} character${ajvError.params.limit === 1 ? '' : 's'} long.`;
103103

104104
case 'minItems':
105-
return `${fullParam} must contain at least ${ajvError.params.limit} item${
106-
ajvError.params.limit === 1 ? '' : 's'
107-
}.`;
105+
return `${fullParam} must contain at least ${
106+
ajvError.params.limit
107+
} item${ajvError.params.limit === 1 ? '' : 's'}.`;
108108

109109
case 'maxItems':
110-
return `${fullParam} must contain at most ${ajvError.params.limit} item${
111-
ajvError.params.limit === 1 ? '' : 's'
112-
}.`;
110+
return `${fullParam} must contain at most ${
111+
ajvError.params.limit
112+
} item${ajvError.params.limit === 1 ? '' : 's'}.`;
113113

114114
case 'uniqueItems':
115115
return `${fullParam} has duplicate items.`;
116116

117117
case 'minProperties':
118-
return `${fullParam} must contain at least ${ajvError.params.limit} propert${
119-
ajvError.params.limit === 1 ? 'y' : 'ies'
120-
}.`;
118+
return `${fullParam} must contain at least ${
119+
ajvError.params.limit
120+
} propert${ajvError.params.limit === 1 ? 'y' : 'ies'}.`;
121121

122122
case 'maxProperties':
123-
return `${fullParam} must contain at most ${ajvError.params.limit} propert${
124-
ajvError.params.limit === 1 ? 'y' : 'ies'
125-
}.`;
123+
return `${fullParam} must contain at most ${
124+
ajvError.params.limit
125+
} propert${ajvError.params.limit === 1 ? 'y' : 'ies'}.`;
126126

127127
default:
128128
// Fallback for any unhandled validation keywords

0 commit comments

Comments
 (0)