Skip to content

Commit fac7c36

Browse files
Boshenclaude
andauthored
Add formatting check to CI and fix format script (#434)
- Update format script to target TypeScript files instead of JavaScript - Remove deprecated --plugin-search-dir option - Add "Check formatting" step to CI workflow - Apply Prettier formatting to all source and test files Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c8d0d0c commit fac7c36

13 files changed

Lines changed: 187 additions & 55 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141
- name: Install dependencies
4242
run: npm install --force
4343

44+
- name: Check formatting
45+
run: npm run format -- --check
46+
4447
- name: Build Prettier Plugin
4548
run: |
4649
npm run build

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"pretest": "node scripts/install-fixture-deps.js",
2929
"test": "vitest",
3030
"prepublishOnly": "npm run build && node scripts/copy-licenses.js",
31-
"format": "prettier \"src/**/*.js\" \"scripts/**/*.js\" \"tests/test.js\" --write --print-width 100 --single-quote --no-semi --plugin-search-dir ./tests",
31+
"format": "prettier \"src/**/*.ts\" \"scripts/**/*.js\" \"tests/*.ts\" --write --print-width 100 --single-quote --no-semi",
3232
"release-channel": "node ./scripts/release-channel.js",
3333
"release-notes": "node ./scripts/release-notes.js"
3434
},

scripts/install-fixture-deps.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import glob from 'fast-glob'
77
const __dirname = path.dirname(fileURLToPath(import.meta.url))
88

99
const fixtures = glob.sync(
10-
['tests/fixtures/*/package.json', 'tests/fixtures/v4/*/package.json', 'tests/fixtures/monorepo/*/package.json'],
10+
[
11+
'tests/fixtures/*/package.json',
12+
'tests/fixtures/v4/*/package.json',
13+
'tests/fixtures/monorepo/*/package.json',
14+
],
1115
{
1216
cwd: path.resolve(__dirname, '..'),
1317
},

scripts/release-notes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const pkg = JSON.parse(await fs.readFile(path.resolve(__dirname, '../package.jso
1212
let version = process.argv[2] || process.env.npm_package_version || pkg.version
1313

1414
let changelog = await fs.readFile(path.resolve(__dirname, '..', 'CHANGELOG.md'), 'utf8')
15-
let match = new RegExp(`## \\[${version}\\] - (.*)\\n\\n([\\s\\S]*?)\\n(?:(?:##\\s)|(?:\\[))`, 'g').exec(changelog)
15+
let match = new RegExp(
16+
`## \\[${version}\\] - (.*)\\n\\n([\\s\\S]*?)\\n(?:(?:##\\s)|(?:\\[))`,
17+
'g',
18+
).exec(changelog)
1619

1720
if (match) {
1821
let [, , notes] = match

src/config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ async function resolvePrettierConfigPath(filePath: string): Promise<[string, str
138138

139139
let resolvedModCache = expiringMap<string, Promise<[any | null, string | null]>>(10_000)
140140

141-
async function resolveTailwindPath(options: ParserOptions, baseDir: string): Promise<[any | null, string | null]> {
141+
async function resolveTailwindPath(
142+
options: ParserOptions,
143+
baseDir: string,
144+
): Promise<[any | null, string | null]> {
142145
let pkgName = options.tailwindPackageName ?? 'tailwindcss'
143146

144147
return await resolvedModCache.remember(`${pkgName}:${baseDir}`, async () => {
@@ -187,7 +190,11 @@ function findClosestJsConfig(inputDir: string): string | null {
187190
return configPath
188191
}
189192

190-
function resolveStylesheet(options: ParserOptions, baseDir: string, configPath: string | null): string | null {
193+
function resolveStylesheet(
194+
options: ParserOptions,
195+
baseDir: string,
196+
configPath: string | null,
197+
): string | null {
191198
if (options.tailwindStylesheet) {
192199
if (
193200
options.tailwindStylesheet.endsWith('.js') ||

src/index.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// @ts-ignore
2-
import type { AttrDoubleQuoted, AttrSingleQuoted } from '@shopify/prettier-plugin-liquid/dist/types.js'
2+
import type {
3+
AttrDoubleQuoted,
4+
AttrSingleQuoted,
5+
} from '@shopify/prettier-plugin-liquid/dist/types.js'
36
import * as astTypes from 'ast-types'
47
// @ts-ignore
58
import jsesc from 'jsesc'
@@ -14,7 +17,13 @@ import { getTailwindConfig } from './config.js'
1417
import { createMatcher, type Matcher } from './options.js'
1518
import { loadPlugins } from './plugins.js'
1619
import { sortClasses, sortClassList } from './sorting.js'
17-
import type { Customizations, StringChange, TransformerContext, TransformerEnv, TransformerMetadata } from './types'
20+
import type {
21+
Customizations,
22+
StringChange,
23+
TransformerContext,
24+
TransformerEnv,
25+
TransformerMetadata,
26+
} from './types'
1827
import { spliceChangesIntoString, visit, type Path } from './utils.js'
1928

2029
let base = await loadPlugins()
@@ -339,7 +348,11 @@ function transformGlimmer(ast: any, { env }: TransformerContext) {
339348
}
340349

341350
let concat = path.find((entry) => {
342-
return entry.parent && entry.parent.type === 'SubExpression' && entry.parent.path.original === 'concat'
351+
return (
352+
entry.parent &&
353+
entry.parent.type === 'SubExpression' &&
354+
entry.parent.path.original === 'concat'
355+
)
343356
})
344357

345358
node.value = sortClasses(node.value, {
@@ -507,7 +520,9 @@ function sortStringLiteral(
507520
}
508521

509522
function isStringLiteral(node: any) {
510-
return node.type === 'StringLiteral' || (node.type === 'Literal' && typeof node.value === 'string')
523+
return (
524+
node.type === 'StringLiteral' || (node.type === 'Literal' && typeof node.value === 'string')
525+
)
511526
}
512527

513528
function sortTemplateLiteral(
@@ -568,7 +583,9 @@ function sortTemplateLiteral(
568583
}
569584

570585
function isSortableTemplateExpression(
571-
node: import('@babel/types').TaggedTemplateExpression | import('ast-types').namedTypes.TaggedTemplateExpression,
586+
node:
587+
| import('@babel/types').TaggedTemplateExpression
588+
| import('ast-types').namedTypes.TaggedTemplateExpression,
572589
matcher: Matcher,
573590
): boolean {
574591
return isSortableExpression(node.tag, matcher)
@@ -910,7 +927,8 @@ function transformTwig(ast: any, { env, changes }: TransformerContext) {
910927
const concat = path.find((entry) => {
911928
return (
912929
entry.parent &&
913-
(entry.parent.type === 'BinaryConcatExpression' || entry.parent.type === 'BinaryAddExpression')
930+
(entry.parent.type === 'BinaryConcatExpression' ||
931+
entry.parent.type === 'BinaryAddExpression')
914932
)
915933
})
916934

@@ -938,7 +956,11 @@ function transformPug(ast: any, { env }: TransformerContext) {
938956
// First sort the classes in attributes
939957
for (const token of ast.tokens) {
940958
if (token.type === 'attribute' && matcher.hasStaticAttr(token.name)) {
941-
token.val = [token.val.slice(0, 1), sortClasses(token.val.slice(1, -1), { env }), token.val.slice(-1)].join('')
959+
token.val = [
960+
token.val.slice(0, 1),
961+
sortClasses(token.val.slice(1, -1), { env }),
962+
token.val.slice(-1),
963+
].join('')
942964
}
943965
}
944966

src/options.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ export interface Matcher {
6767
hasFunction(name: string): boolean
6868
}
6969

70-
export function createMatcher(options: RequiredOptions, parser: string, defaults: Customizations): Matcher {
70+
export function createMatcher(
71+
options: RequiredOptions,
72+
parser: string,
73+
defaults: Customizations,
74+
): Matcher {
7175
let staticAttrs = new Set<string>(defaults.staticAttrs)
7276
let dynamicAttrs = new Set<string>(defaults.dynamicAttrs)
7377
let functions = new Set<string>(defaults.functions)

src/utils.bench.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ describe('spliceChangesIntoString', () => {
1212

1313
function buildFixture(repeatCount: number, changeCount: number) {
1414
// A large set of changes across random places in the string
15-
let indxes = new Set(Array.from({ length: changeCount }, (_, i) => Math.ceil(Math.random() * repeatCount)))
15+
let indxes = new Set(
16+
Array.from({ length: changeCount }, (_, i) => Math.ceil(Math.random() * repeatCount)),
17+
)
1618

1719
let changes: StringChange[] = Array.from(indxes).flatMap((idx) => {
1820
return changesTemplate.map((change) => ({

src/utils.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ describe('spliceChangesIntoString', () => {
1010
{ start: 10, end: 15, before: 'brown', after: 'purple' },
1111
]
1212

13-
expect(spliceChangesIntoString(str, changes)).toBe('the quick purple fox jumps over the lazy dog')
13+
expect(spliceChangesIntoString(str, changes)).toBe(
14+
'the quick purple fox jumps over the lazy dog',
15+
)
1416
})
1517

1618
test('changes are applied in order', ({ expect }) => {
@@ -21,6 +23,8 @@ describe('spliceChangesIntoString', () => {
2123
{ start: 4, end: 9, before: 'quick', after: 'slow' },
2224
]
2325

24-
expect(spliceChangesIntoString(str, changes)).toBe('the slow purple fox jumps over the lazy dog')
26+
expect(spliceChangesIntoString(str, changes)).toBe(
27+
'the slow purple fox jumps over the lazy dog',
28+
)
2529
})
2630
})

src/versions/v3.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ export async function loadV3(pkgDir: string | null, jsConfig: string | null): Pr
7272
// that don't exist on their own. This will result in them "not existing" and
7373
// sorting could be weird since you still require them in order to make the
7474
// host utitlies work properly. (Thanks Biology)
75-
let parasiteUtilities = new Set([prefixCandidate(context, 'group'), prefixCandidate(context, 'peer')])
75+
let parasiteUtilities = new Set([
76+
prefixCandidate(context, 'group'),
77+
prefixCandidate(context, 'peer'),
78+
])
7679

7780
let classNamesWithOrder: [string, bigint | null][] = []
7881

7982
for (let className of classes) {
8083
let order: bigint | null =
81-
generateRules(new Set([className]), context).sort(([a], [z]) => bigSign(z - a))[0]?.[0] ?? null
84+
generateRules(new Set([className]), context).sort(([a], [z]) => bigSign(z - a))[0]?.[0] ??
85+
null
8286

8387
if (order === null && parasiteUtilities.has(className)) {
8488
// This will make sure that it is at the very beginning of the
@@ -97,7 +101,9 @@ export async function loadV3(pkgDir: string | null, jsConfig: string | null): Pr
97101

98102
return {
99103
getClassOrder: (classList: string[]) => {
100-
return context.getClassOrder ? context.getClassOrder(classList) : getClassOrderPolyfill(classList)
104+
return context.getClassOrder
105+
? context.getClassOrder(classList)
106+
: getClassOrderPolyfill(classList)
101107
},
102108
}
103109
}

0 commit comments

Comments
 (0)