Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- name: Check formatting
run: pnpm run format --check

- name: Lint
run: pnpm run lint

- name: Build Prettier Plugin
run: pnpm run build

Expand Down
6 changes: 6 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
"rules": {
"typescript/unbound-method": "off"
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"test": "vitest",
"prepublishOnly": "npm run build && node scripts/copy-licenses.js",
"format": "prettier \"src/**/*.ts\" \"scripts/**/*.js\" \"tests/*.ts\" --write --print-width 100 --single-quote --no-semi",
"lint": "knip",
"lint": "knip && oxlint --type-aware src tests/*.ts",
"release-channel": "node ./scripts/release-channel.js",
"release-notes": "node ./scripts/release-notes.js"
},
Expand All @@ -62,6 +62,8 @@
"license-checker": "^25.0.1",
"line-column": "^1.0.2",
"marko": "^5.37.46",
"oxlint": "^1.43.0",
"oxlint-tsgolint": "^0.11.4",
"postcss": "^8.5.6",
"postcss-import": "^16.1.1",
"prettier": "^3.7.3",
Expand Down
157 changes: 157 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 8 additions & 12 deletions src/create-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function createPlugin(transforms: TransformOptions<any>[]) {
}
}

for (let [name, meta] of Object.entries(opts.printers ?? {})) {
for (let [name, _meta] of Object.entries(opts.printers ?? {})) {
printers[name] = async () => {
let plugin = await loadPlugins(opts.load ?? [])
let original = plugin.printers?.[name]
Expand Down Expand Up @@ -154,17 +154,13 @@ async function loadPlugins<T>(fns: PluginLoad[]) {
}

for (let moduleName of fns) {
try {
let loaded = typeof moduleName === 'string' ? await loadIfExistsESM(moduleName) : moduleName
Object.assign(plugin.parsers!, loaded.parsers ?? {})
Object.assign(plugin.printers!, loaded.printers ?? {})
Object.assign(plugin.options!, loaded.options ?? {})
Object.assign(plugin.defaultOptions!, loaded.defaultOptions ?? {})

plugin.languages = [...(plugin.languages ?? []), ...(loaded.languages ?? [])]
} catch (err) {
throw err
}
let loaded = typeof moduleName === 'string' ? await loadIfExistsESM(moduleName) : moduleName
Object.assign(plugin.parsers!, loaded.parsers ?? {})
Object.assign(plugin.printers!, loaded.printers ?? {})
Object.assign(plugin.options!, loaded.options ?? {})
Object.assign(plugin.defaultOptions!, loaded.defaultOptions ?? {})

plugin.languages = [...(plugin.languages ?? []), ...(loaded.languages ?? [])]
}

return plugin
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as prettierParserCss from 'prettier/plugins/postcss'
import { createPlugin } from './create-plugin.js'
import type { Matcher } from './options.js'
import { sortClasses, sortClassList } from './sorting.js'
import { defineTransform, type TransformOptions } from './transform.js'
import { defineTransform } from './transform.js'
import type { StringChange, TransformerEnv } from './types'
import { spliceChangesIntoString, visit, type Path } from './utils.js'

Expand Down
4 changes: 2 additions & 2 deletions src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function maybeResolve(name: string) {
try {
modpath = resolveJsFrom(fileURLToPath(import.meta.url), name)
resolveCache.set(name, modpath)
} catch (err) {
} catch {
resolveCache.set(name, null)
return null
}
Expand All @@ -66,7 +66,7 @@ export async function loadIfExists<T>(name: string): Promise<T | null> {
export function resolveJsFrom(base: string, id: string): string {
try {
return esmResolver.resolveSync({}, base, id) || id
} catch (err) {
} catch {
return cjsResolver.resolveSync({}, base, id) || id
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/sorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ export async function getTailwindConfig(options: TailwindConfigOptions): Promise
})
}

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

async function resolveTailwindPath(
options: { packageName?: string },
baseDir: string,
): Promise<[any | null, string | null]> {
): Promise<[any, string | null]> {
let pkgName = options.packageName ?? 'tailwindcss'
let makeKey = (dir: string) => `${pkgName}:${dir}`

Expand All @@ -218,7 +218,7 @@ async function resolveTailwindPath(

let resolve = async () => {
let pkgDir: string | null = null
let mod: any | null = null
let mod: any = null

try {
let pkgPath = resolveJsFrom(baseDir, pkgName)
Expand All @@ -228,7 +228,7 @@ async function resolveTailwindPath(
pkgDir = path.dirname(pkgFile)
} catch {}

return [mod, pkgDir] as [any | null, string | null]
return [mod, pkgDir] as [any, string | null]
}

let result = await resolve()
Expand Down
2 changes: 1 addition & 1 deletion src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AstPath, ParserOptions, Plugin } from 'prettier'
import type { AstPath, Plugin } from 'prettier'
import type { TransformerEnv } from './types'

export function defineTransform<T>(opts: TransformOptions<T>) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('spliceChangesIntoString', () => {
function buildFixture(repeatCount: number, changeCount: number) {
// A large set of changes across random places in the string
let indxes = new Set(
Array.from({ length: changeCount }, (_, i) => Math.ceil(Math.random() * repeatCount)),
Array.from({ length: changeCount }, () => Math.ceil(Math.random() * repeatCount)),
)

let changes: StringChange[] = Array.from(indxes).flatMap((idx) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, describe, test } from 'vitest'
import { describe, test } from 'vitest'
import type { StringChange } from './types'
import { spliceChangesIntoString } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function loadIfExists(name: string): any {
if (require.resolve(name)) {
return require(name)
}
} catch (e) {
} catch {
return null
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/plugins.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createRequire } from 'node:module'
import dedent from 'dedent'
import * as prettier from 'prettier'
import { test } from 'vitest'
import { javascript } from './tests.js'
import type { TestEntry } from './utils.js'
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,6 @@ export let tests: Record<string, TestEntry[]> = {
acorn: javascript,
meriyah: javascript,
mdx: javascript
.filter((test) => !/^\/\*/.test(test[0]) && !/^\/\*/.test(test[1]))
.filter((test) => !test[0].startsWith('/*') && !test[1].startsWith('/*'))
.map((test) => [test[0].replace(/^;/, ''), test[1].replace(/^;/, ''), test[2]]),
}