Skip to content

Commit bee17e8

Browse files
committed
fix(prettier): Apply the PHP parser only to PHP files
The top-level parser option forced the PHP parser onto every file in the repository. Non-PHP files were parsed as inline HTML and written back unchanged, so Prettier silently did nothing for TypeScript, JSON, YAML and Markdown, and the overrides block only ever adjusted options that the PHP parser ignored. Move the PHP parser into an override on **/*.php with the plugin defaults it was already producing, and let Prettier infer the parser for everything else, which restores the shared options used by the Ruby and Python SDKs. Disable embedded formatting in Markdown so the PHP examples in the README keep the style of the generated source. The codegen changes are the result of running the formatter over TypeScript for the first time. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RFK47311nWtbd3gHmjdknR
1 parent 9bea996 commit bee17e8

4 files changed

Lines changed: 47 additions & 25 deletions

File tree

.prettierrc.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
{
22
"plugins": ["@prettier/plugin-php"],
3-
"parser": "php",
4-
3+
"semi": false,
4+
"singleQuote": true,
5+
"jsxSingleQuote": true,
6+
"endOfLine": "lf",
57
"overrides": [
68
{
7-
"files": "**/*.{js,ts,json,yml,md}",
9+
"files": "**/*.php",
810
"options": {
9-
"semi": false,
10-
"singleQuote": true,
11-
"jsxSingleQuote": true,
12-
"endOfLine": "lf"
11+
"parser": "php",
12+
"semi": true,
13+
"singleQuote": false
14+
}
15+
},
16+
{
17+
"files": "**/*.md",
18+
"options": {
19+
"embeddedLanguageFormatting": "off"
1320
}
1421
}
1522
]

codegen/lib/handlebars-helpers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ const createPhpDoc = (
5252
.split(/\r?\n/)
5353
.map(sanitizePhpDocLine)
5454
const populatedDescription = description.trim() === '' ? [] : descriptionLines
55-
const populatedTags = tags.filter((tag) => tag.trim() !== '').map(sanitizePhpDocLine)
55+
const populatedTags = tags
56+
.filter((tag) => tag.trim() !== '')
57+
.map(sanitizePhpDocLine)
5658
const lines = [
5759
...populatedDescription,
58-
...(populatedDescription.length > 0 && populatedTags.length > 0 ? [''] : []),
60+
...(populatedDescription.length > 0 && populatedTags.length > 0
61+
? ['']
62+
: []),
5963
...populatedTags,
6064
]
6165

codegen/lib/resource-model.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ import { getPhpType } from './map-php-type.js'
1616

1717
export type ResourceClassProperty =
1818
| ({ kind: 'value'; phpType: string } & ResourceClassPropertyMetadata)
19-
| ({ kind: 'objectReference'; referenceName: string } & ResourceClassPropertyMetadata)
20-
| ({ kind: 'listReference'; referenceName: string } & ResourceClassPropertyMetadata)
19+
| ({
20+
kind: 'objectReference'
21+
referenceName: string
22+
} & ResourceClassPropertyMetadata)
23+
| ({
24+
kind: 'listReference'
25+
referenceName: string
26+
} & ResourceClassPropertyMetadata)
2127

2228
interface ResourceClassPropertyMetadata {
2329
name: string
@@ -109,8 +115,12 @@ export const createResourceModel = (blueprint: Blueprint): ResourceModel => {
109115
currentResourceName = name
110116
localClassNames.set(name, [])
111117
const sourceResource =
112-
blueprint.resources.find((resource) => resource.resourceType === resourceType) ??
113-
(resourceType === 'event' ? blueprint.events[0] : blueprint.actionAttempts[0])
118+
blueprint.resources.find(
119+
(resource) => resource.resourceType === resourceType,
120+
) ??
121+
(resourceType === 'event'
122+
? blueprint.events[0]
123+
: blueprint.actionAttempts[0])
114124
addClass(
115125
name,
116126
baseResources.get(resourceType) ?? [],

codegen/lib/routes.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ export const routes = (
102102
const createClientMethod = (endpoint: Endpoint): PhpClientMethod => {
103103
const { response } = endpoint
104104

105-
const responseKey = response.responseType === 'void' ? '' : response.responseKey
105+
const responseKey =
106+
response.responseType === 'void' ? '' : response.responseKey
106107

107108
// Batch responses have no single resource type; they deserialize into the
108109
// Batch resource. A response whose resource type the blueprint cannot
@@ -126,17 +127,17 @@ const createClientMethod = (endpoint: Endpoint): PhpClientMethod => {
126127
isDeprecated: endpoint.isDeprecated,
127128
deprecationMessage: endpoint.deprecationMessage,
128129
parameters: endpoint.request.parameters.map((parameter) => ({
129-
name: parameter.name,
130-
type: getPhpType(parameter),
131-
description: parameter.description,
132-
required: parameter.isRequired,
133-
// The primary identifier of a get endpoint always sorts first in the
134-
// method signature.
135-
position:
136-
endpoint.name === 'get' && parameter.name === `${responseKey}_id`
137-
? 0
138-
: undefined,
139-
})),
130+
name: parameter.name,
131+
type: getPhpType(parameter),
132+
description: parameter.description,
133+
required: parameter.isRequired,
134+
// The primary identifier of a get endpoint always sorts first in the
135+
// method signature.
136+
position:
137+
endpoint.name === 'get' && parameter.name === `${responseKey}_id`
138+
? 0
139+
: undefined,
140+
})),
140141
returnPath: responseKey,
141142
returnResource: resourceType === '' ? '' : pascalCase(resourceType),
142143
isArrayResponse:

0 commit comments

Comments
 (0)