Skip to content

Commit 581f9e4

Browse files
Boshenclaude
andcommitted
Add oxlint with type-aware linting
- Add oxlint and oxlint-tsgolint for type-aware linting - Configure .oxlintrc.json to disable noisy rules - Update lint script to run oxlint on src and tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9caa70c commit 581f9e4

File tree

14 files changed

+189
-26
lines changed

14 files changed

+189
-26
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
- name: Check formatting
4040
run: pnpm run format --check
4141

42+
- name: Lint
43+
run: pnpm run lint
44+
4245
- name: Build Prettier Plugin
4346
run: pnpm run build
4447

.oxlintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
3+
"rules": {
4+
"typescript/unbound-method": "off"
5+
}
6+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"test": "vitest",
3737
"prepublishOnly": "npm run build && node scripts/copy-licenses.js",
3838
"format": "prettier \"src/**/*.ts\" \"scripts/**/*.js\" \"tests/*.ts\" --write --print-width 100 --single-quote --no-semi",
39-
"lint": "knip",
39+
"lint": "knip && oxlint --type-aware src tests/*.ts",
4040
"release-channel": "node ./scripts/release-channel.js",
4141
"release-notes": "node ./scripts/release-notes.js"
4242
},
@@ -62,6 +62,8 @@
6262
"license-checker": "^25.0.1",
6363
"line-column": "^1.0.2",
6464
"marko": "^5.37.46",
65+
"oxlint": "^1.43.0",
66+
"oxlint-tsgolint": "^0.11.4",
6567
"postcss": "^8.5.6",
6668
"postcss-import": "^16.1.1",
6769
"prettier": "^3.7.3",

pnpm-lock.yaml

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/create-plugin.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function createPlugin(transforms: TransformOptions<any>[]) {
3333
}
3434
}
3535

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

156156
for (let moduleName of fns) {
157-
try {
158-
let loaded = typeof moduleName === 'string' ? await loadIfExistsESM(moduleName) : moduleName
159-
Object.assign(plugin.parsers!, loaded.parsers ?? {})
160-
Object.assign(plugin.printers!, loaded.printers ?? {})
161-
Object.assign(plugin.options!, loaded.options ?? {})
162-
Object.assign(plugin.defaultOptions!, loaded.defaultOptions ?? {})
163-
164-
plugin.languages = [...(plugin.languages ?? []), ...(loaded.languages ?? [])]
165-
} catch (err) {
166-
throw err
167-
}
157+
let loaded = typeof moduleName === 'string' ? await loadIfExistsESM(moduleName) : moduleName
158+
Object.assign(plugin.parsers!, loaded.parsers ?? {})
159+
Object.assign(plugin.printers!, loaded.printers ?? {})
160+
Object.assign(plugin.options!, loaded.options ?? {})
161+
Object.assign(plugin.defaultOptions!, loaded.defaultOptions ?? {})
162+
163+
plugin.languages = [...(plugin.languages ?? []), ...(loaded.languages ?? [])]
168164
}
169165

170166
return plugin

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as prettierParserCss from 'prettier/plugins/postcss'
99
import { createPlugin } from './create-plugin.js'
1010
import type { Matcher } from './options.js'
1111
import { sortClasses, sortClassList } from './sorting.js'
12-
import { defineTransform, type TransformOptions } from './transform.js'
12+
import { defineTransform } from './transform.js'
1313
import type { StringChange, TransformerEnv } from './types'
1414
import { spliceChangesIntoString, visit, type Path } from './utils.js'
1515

src/resolve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function maybeResolve(name: string) {
4343
try {
4444
modpath = resolveJsFrom(fileURLToPath(import.meta.url), name)
4545
resolveCache.set(name, modpath)
46-
} catch (err) {
46+
} catch {
4747
resolveCache.set(name, null)
4848
return null
4949
}
@@ -66,7 +66,7 @@ export async function loadIfExists<T>(name: string): Promise<T | null> {
6666
export function resolveJsFrom(base: string, id: string): string {
6767
try {
6868
return esmResolver.resolveSync({}, base, id) || id
69-
} catch (err) {
69+
} catch {
7070
return cjsResolver.resolveSync({}, base, id) || id
7171
}
7272
}

src/sorter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ export async function getTailwindConfig(options: TailwindConfigOptions): Promise
201201
})
202202
}
203203

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

206206
async function resolveTailwindPath(
207207
options: { packageName?: string },
208208
baseDir: string,
209-
): Promise<[any | null, string | null]> {
209+
): Promise<[any, string | null]> {
210210
let pkgName = options.packageName ?? 'tailwindcss'
211211
let makeKey = (dir: string) => `${pkgName}:${dir}`
212212

@@ -218,7 +218,7 @@ async function resolveTailwindPath(
218218

219219
let resolve = async () => {
220220
let pkgDir: string | null = null
221-
let mod: any | null = null
221+
let mod: any = null
222222

223223
try {
224224
let pkgPath = resolveJsFrom(baseDir, pkgName)
@@ -228,7 +228,7 @@ async function resolveTailwindPath(
228228
pkgDir = path.dirname(pkgFile)
229229
} catch {}
230230

231-
return [mod, pkgDir] as [any | null, string | null]
231+
return [mod, pkgDir] as [any, string | null]
232232
}
233233

234234
let result = await resolve()

src/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AstPath, ParserOptions, Plugin } from 'prettier'
1+
import type { AstPath, Plugin } from 'prettier'
22
import type { TransformerEnv } from './types'
33

44
export function defineTransform<T>(opts: TransformOptions<T>) {

src/utils.bench.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('spliceChangesIntoString', () => {
1313
function buildFixture(repeatCount: number, changeCount: number) {
1414
// A large set of changes across random places in the string
1515
let indxes = new Set(
16-
Array.from({ length: changeCount }, (_, i) => Math.ceil(Math.random() * repeatCount)),
16+
Array.from({ length: changeCount }, () => Math.ceil(Math.random() * repeatCount)),
1717
)
1818

1919
let changes: StringChange[] = Array.from(indxes).flatMap((idx) => {

0 commit comments

Comments
 (0)