Skip to content

Commit dbad586

Browse files
authored
Fix Coding Style using Wp Eslint Configuration
fix #34
1 parent b80bb6c commit dbad586

File tree

61 files changed

+1905
-1732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1905
-1732
lines changed

.eslintignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
vendor
2+
node_modules
3+
build
4+
5+
.psalm
6+
.github
7+
8+
./coverage
9+
./sources/server

.eslintrc.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
const baseConfiguration = require('@wordpress/scripts/config/.eslintrc.js');
2-
31
module.exports = {
4-
...baseConfiguration,
5-
ignorePatterns: [
6-
...(baseConfiguration.ignorePatterns ?? []),
7-
'**/sources/server/**/*.js',
8-
],
2+
extends: [ 'plugin:@wordpress/eslint-plugin/recommended' ],
3+
ignorePatterns: [ '**/sources/server/**/*.js' ],
94
rules: {
10-
...baseConfiguration.rules,
11-
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
5+
'@wordpress/dependency-group': 'error',
6+
'@wordpress/i18n-text-domain': [
7+
'error',
8+
{
9+
allowedTextDomain: 'wp-entities-search',
10+
},
11+
],
12+
'@typescript-eslint/array-type': [ 'error', { default: 'generic' } ],
1213
},
1314
settings: {
1415
'import/resolver': {

.github/workflows/js-qa.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ jobs:
3131
- name: Install
3232
run: yarn install
3333

34-
- name: Coding Style
35-
run: yarn cs
36-
3734
- name: Linting JavaScript
3835
run: yarn lint:js
3936

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
./vendor
66
./node_modules
77
./build
8+
./sources/server

.prettierrc.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
clearMocks: true,
44
preset: 'ts-jest',
55
testEnvironment: 'jsdom',
6-
moduleDirectories: ['node_modules'],
7-
setupFilesAfterEnv: ['<rootDir>/tests/client/setup-tests.ts'],
6+
moduleDirectories: [ 'node_modules' ],
7+
setupFilesAfterEnv: [ '<rootDir>/tests/client/setup-tests.ts' ],
88
maxWorkers: 8,
99
};

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
"@testing-library/react": "^14.0.0",
1616
"@testing-library/user-event": "^14.5.1",
1717
"@total-typescript/shoehorn": "^0.1.0",
18-
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
1918
"@wordpress/dependency-extraction-webpack-plugin": "^4.8.0",
2019
"@wordpress/env": "^5.9.0",
21-
"@wordpress/eslint-plugin": "^14.8.0",
2220
"@wordpress/scripts": "^26.0.0",
2321
"eslint-import-resolver-typescript": "^3.5.5",
2422
"jest": "^29.4.3",
2523
"jest-environment-jsdom": "^29.5.0",
26-
"prettier": "^2.8.1",
2724
"ts-jest": "^29.0.5",
2825
"ts-loader": "^9.4.2",
2926
"ts-node": "^10.9.1",
@@ -46,10 +43,9 @@
4643
"wp-env": "wp-env",
4744
"build": "wp-scripts build --webpack-src-dir=./sources/client/src",
4845
"build:dev": "wp-scripts start --webpack--devtool=inline-source-map --webpack-src-dir=./sources/client/src",
49-
"cs": "yarn prettier --check ./sources/client",
5046
"cs:fix": "wp-scripts format ./sources/client",
51-
"lint:js": "wp-scripts lint-js",
52-
"lint:js:fix": "wp-scripts lint-js --fix",
47+
"lint:js": "wp-scripts lint-js ./sources/client",
48+
"lint:js:fix": "wp-scripts lint-js --fix ./sources/client",
5349
"test": "jest",
5450
"test:update-snapshots": "yarn test -u"
5551
}

sources/client/src/api/fetch.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* WordPress dependencies
3+
*/
14
import apiFetch from '@wordpress/api-fetch';
25

36
/**
Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
1+
/**
2+
* External dependencies
3+
*/
14
import EntitiesSearch from '@types';
25

6+
/**
7+
* WordPress dependencies
8+
*/
39
import { doAction } from '@wordpress/hooks';
410

11+
/**
12+
* Internal dependencies
13+
*/
514
import { abortControllers } from '../services/abort-controllers';
615
import { ContextualAbortController } from '../services/contextual-abort-controller';
716
import { Set } from '../vo/set';
817
import { fetch } from './fetch';
918

10-
export async function searchEntities<E>(
19+
export async function searchEntities< E >(
1120
type: string,
12-
subtype: Set<string>,
21+
subtype: Set< string >,
1322
phrase: string,
14-
queryArguments?: EntitiesSearch.QueryArguments<string>
15-
): Promise<Set<E>> {
23+
queryArguments?: EntitiesSearch.QueryArguments< string >
24+
): Promise< Set< E > > {
1625
const {
1726
exclude,
1827
include,
19-
fields = ['title', 'id'],
28+
fields = [ 'title', 'id' ],
2029
...restArguments
2130
} = queryArguments ?? {};
2231

2332
// @ts-ignore we need to pass string[] to the URLSearchParams
24-
const params = new URLSearchParams({
33+
const params = new URLSearchParams( {
2534
per_page: '10',
2635
order: 'DESC',
2736
orderBy: 'title',
@@ -33,30 +42,30 @@ export async function searchEntities<E>(
3342
type,
3443
search: phrase,
3544
subtype: subtype.toArray(),
36-
_fields: serializeFields(fields),
37-
}).toString();
45+
_fields: serializeFields( fields ),
46+
} ).toString();
3847

3948
const controller = abortControllers.add(
4049
new ContextualAbortController(
4150
params,
42-
`Request aborted with parameters: ${params}`
51+
`Request aborted with parameters: ${ params }`
4352
)
4453
);
4554

46-
const entities = await fetch<ReadonlyArray<E>>({
47-
path: `?rest_route=/wp/v2/search&${params}`,
55+
const entities = await fetch< ReadonlyArray< E > >( {
56+
path: `?rest_route=/wp/v2/search&${ params }`,
4857
signal: controller?.signal() ?? null,
49-
}).catch((error) => {
50-
if (error instanceof DOMException && error.name === 'AbortError') {
51-
doAction('wp-entities-search.on-search.abort', error);
58+
} ).catch( ( error ) => {
59+
if ( error instanceof DOMException && error.name === 'AbortError' ) {
60+
doAction( 'wp-entities-search.on-search.abort', error );
5261
}
5362

5463
throw error;
55-
});
64+
} );
5665

57-
return new Set(entities);
66+
return new Set( entities );
5867
}
5968

60-
function serializeFields(fields: EntitiesSearch.SearchQueryFields): string {
61-
return fields.join(',');
69+
function serializeFields( fields: EntitiesSearch.SearchQueryFields ): string {
70+
return fields.join( ',' );
6271
}
Lines changed: 62 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
/**
2+
* External dependencies
3+
*/
14
import type EntitiesSearch from '@types';
25
import React, { JSX } from 'react';
36

7+
/**
8+
* WordPress dependencies
9+
*/
410
import { doAction } from '@wordpress/hooks';
511

12+
/**
13+
* Internal dependencies
14+
*/
615
import { useEntitiesOptionsStorage } from '../hooks/use-entities-options-storage';
716
import { useSearch } from '../hooks/use-search';
817
import { orderSelectedOptionsAtTheTop } from '../utils/order-selected-options-at-the-top';
@@ -15,99 +24,102 @@ import { Set } from '../vo/set';
1524
* @public
1625
* @param props The component props.
1726
*/
18-
export function CompositeEntitiesByKind<E, K>(
19-
props: EntitiesSearch.CompositeEntitiesKinds<E, K>
27+
export function CompositeEntitiesByKind< E, K >(
28+
props: EntitiesSearch.CompositeEntitiesKinds< E, K >
2029
): JSX.Element {
21-
const [state, dispatch] = useEntitiesOptionsStorage<E, K>(
30+
const [ state, dispatch ] = useEntitiesOptionsStorage< E, K >(
2231
{
2332
entities: props.entities.value,
2433
kind: props.kind.value,
2534
},
2635
props.searchEntities
2736
);
28-
const search = useSearch<E, K>(
37+
const search = useSearch< E, K >(
2938
props.searchEntities,
3039
state.kind,
3140
state.entities,
3241
dispatch
3342
);
3443

35-
const onChangeEntities = (entities: EntitiesSearch.Entities<E>) => {
36-
props.entities.onChange(entities);
44+
const onChangeEntities = ( entities: EntitiesSearch.Entities< E > ) => {
45+
props.entities.onChange( entities );
3746

38-
if (entities.length() <= 0) {
39-
dispatch({
47+
if ( entities.length() <= 0 ) {
48+
dispatch( {
4049
type: 'UPDATE_SELECTED_ENTITIES_OPTIONS',
4150
selectedEntitiesOptions: new Set(),
42-
});
51+
} );
4352
return;
4453
}
4554

46-
Promise.all([
47-
props.searchEntities(state.searchPhrase, state.kind, {
55+
Promise.all( [
56+
props.searchEntities( state.searchPhrase, state.kind, {
4857
exclude: entities,
49-
}),
50-
props.searchEntities('', state.kind, {
58+
} ),
59+
props.searchEntities( '', state.kind, {
5160
include: entities,
5261
per_page: '-1',
53-
}),
54-
])
55-
.then((result) => {
56-
const currentEntitiesOptions = result[0] ?? new Set();
57-
const selectedEntitiesOptions = result[1] ?? new Set();
62+
} ),
63+
] )
64+
.then( ( result ) => {
65+
const currentEntitiesOptions = result[ 0 ] ?? new Set();
66+
const selectedEntitiesOptions = result[ 1 ] ?? new Set();
5867

59-
dispatch({
68+
dispatch( {
6069
type: 'UPDATE_SELECTED_ENTITIES_OPTIONS',
6170
selectedEntitiesOptions,
62-
});
63-
dispatch({
71+
} );
72+
dispatch( {
6473
type: 'UPDATE_CURRENT_ENTITIES_OPTIONS',
6574
currentEntitiesOptions,
66-
});
67-
})
68-
.catch((error) => {
69-
doAction('wp-entities-search.on-change-entities.error', error);
70-
});
75+
} );
76+
} )
77+
.catch( ( error ) => {
78+
doAction(
79+
'wp-entities-search.on-change-entities.error',
80+
error
81+
);
82+
} );
7183
};
7284

73-
const onChangeKind = (kind: EntitiesSearch.Kind<K>) => {
74-
const _kind = kind instanceof Set ? kind : new Set([kind]);
75-
const emptySet = new Set<any>();
85+
const onChangeKind = ( kind: EntitiesSearch.Kind< K > ) => {
86+
const _kind = kind instanceof Set ? kind : new Set( [ kind ] );
87+
const emptySet = new Set< any >();
7688

77-
props.kind.onChange(_kind);
78-
props.entities.onChange(emptySet);
89+
props.kind.onChange( _kind );
90+
props.entities.onChange( emptySet );
7991

80-
if (_kind.length() <= 0) {
81-
dispatch({
92+
if ( _kind.length() <= 0 ) {
93+
dispatch( {
8294
type: 'CLEAN_ENTITIES_OPTIONS',
83-
});
84-
dispatch({ type: 'UPDATE_KIND', kind: _kind });
95+
} );
96+
dispatch( { type: 'UPDATE_KIND', kind: _kind } );
8597
return;
8698
}
8799

88100
props
89-
.searchEntities(state.searchPhrase, _kind, {
101+
.searchEntities( state.searchPhrase, _kind, {
90102
exclude: state.entities,
91-
})
92-
.then((entitiesOptions) => {
93-
dispatch({
103+
} )
104+
.then( ( entitiesOptions ) => {
105+
dispatch( {
94106
type: 'UPDATE_ENTITIES_OPTIONS_FOR_NEW_KIND',
95107
entitiesOptions,
96108
kind: _kind,
97-
});
98-
})
99-
.catch((error) => {
100-
dispatch({
109+
} );
110+
} )
111+
.catch( ( error ) => {
112+
dispatch( {
101113
type: 'CLEAN_ENTITIES_OPTIONS',
102-
});
103-
doAction('wp-entities-search.on-change-kind.error', error);
104-
});
114+
} );
115+
doAction( 'wp-entities-search.on-change-kind.error', error );
116+
} );
105117
};
106118

107-
const entities: EntitiesSearch.BaseControl<E> = {
119+
const entities: EntitiesSearch.BaseControl< E > = {
108120
...props.entities,
109121
value: state.entities,
110-
options: orderSelectedOptionsAtTheTop<E>(
122+
options: orderSelectedOptionsAtTheTop< E >(
111123
uniqueControlOptions(
112124
state.selectedEntitiesOptions.concat(
113125
state.currentEntitiesOptions
@@ -118,11 +130,11 @@ export function CompositeEntitiesByKind<E, K>(
118130
onChange: onChangeEntities,
119131
};
120132

121-
const kind: EntitiesSearch.BaseControl<K> = {
133+
const kind: EntitiesSearch.BaseControl< K > = {
122134
...props.kind,
123135
value: state.kind,
124136
onChange: onChangeKind,
125137
};
126138

127-
return <>{props.children(entities, kind, search)}</>;
139+
return <>{ props.children( entities, kind, search ) }</>;
128140
}

0 commit comments

Comments
 (0)