Skip to content

Commit 285c925

Browse files
committed
chore: wip
1 parent 361541a commit 285c925

File tree

8 files changed

+17
-16
lines changed

8 files changed

+17
-16
lines changed

docs/features/linting-basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const obj = { b: 1, a: 2 }
5656
const obj2 = { y: 1, x: 2 }
5757

5858
// pickier-disable-next-line ts/no-require-imports
59-
const fs = require('fs')
59+
const fs = require('node:fs')
6060
```
6161

6262
Notes:

docs/rules/ts-no-require-imports.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Examples (violations):
1717

1818
```ts
1919
// a.ts
20-
const fs = require('fs')
20+
const fs = require('node:fs')
2121
```
2222

2323
```ts
@@ -29,7 +29,7 @@ Non-violations:
2929

3030
```ts
3131
// dynamic import
32-
const mod = await import('fs')
32+
const mod = await import('node:fs')
3333
```
3434

3535
Rationale: TypeScript projects commonly target ESM. Mixing `require()` with ESM import/export leads to interop edge cases and bundler inconsistencies.

eslint.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const config: ESLintConfig = stacks({
1313
ignores: [
1414
'**/test/fixtures/**',
1515
'**/test/output/**',
16+
'docs/**',
1617
],
1718
})
1819

packages/pickier/src/cli/run-lint.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ function applyPlugins(filePath: string, content: string, cfg: PickierConfig): Pl
18031803
meta: { docs: 'Detects potentially super-linear backtracking patterns in regex literals (heuristic)' },
18041804
check: (text, ctx) => {
18051805
const issues: PluginLintIssue[] = []
1806-
const regexLiteral = /\/[^\/\\]*(?:\\.[^\/\\]*)*\//g
1806+
const regexLiteral = /\/[^/\\]*(?:\\.[^/\\]*)*\//g
18071807
const mark = (idx: number, len: number, msg: string) => {
18081808
const before = text.slice(0, idx)
18091809
const line = (before.match(/\n/g) || []).length + 1
@@ -1899,7 +1899,7 @@ function applyPlugins(filePath: string, content: string, cfg: PickierConfig): Pl
18991899
continue
19001900
}
19011901
// also flag import = require('...') pattern
1902-
if (/^import\s+.+=\s*require\s*\(/.test(trimmed)) {
1902+
if (/^import\s+(?:\S.*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF])=\s*require\s*\(/.test(trimmed)) {
19031903
const col = raw.indexOf('require(')
19041904
issues.push({
19051905
filePath: ctx.filePath,
@@ -2103,7 +2103,7 @@ function scanContent(filePath: string, content: string, cfg: PickierConfig): Lin
21032103
severity: cfg.rules.noUnusedCapturingGroup === 'error' ? 'error' : 'warning',
21042104
})
21052105
}
2106-
const regexLiteral = /\/[^\/\\]*(?:\\.[^\/\\]*)*\//g
2106+
const regexLiteral = /\/[^/\\]*(?:\\.[^/\\]*)*\//g
21072107
for (let i = 0; i < lines.length; i++) {
21082108
const line = lines[i]
21092109
regexLiteral.lastIndex = 0

packages/pickier/src/format.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ function parseImportStatement(stmt: string): ParsedImport | undefined {
549549
function trySortKnownJson(input: string, filePath: string): string | null {
550550
if (/package\.json$/i.test(filePath))
551551
return sortPackageJsonContent(input)
552-
if (/[jt]sconfig(\..+)?\.json$/i.test(filePath))
552+
if (/[jt]sconfig(?:\..+)?\.json$/i.test(filePath))
553553
return sortTsconfigContent(input)
554554
return null
555555
}
@@ -650,7 +650,7 @@ function sortPackageJsonContent(text: string): string {
650650
}
651651
// sort deps blocks A-Z
652652
for (const k of Object.keys(sortedTop)) {
653-
if (/^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$/.test(k) || /^(?:resolutions|overrides|pnpm\.overrides)$/.test(k)) {
653+
if (/^(?:dev|peer|optional|bundled)?[Dd]ependencies(?:Meta)?$/.test(k) || /^(?:resolutions|overrides|pnpm\.overrides)$/.test(k)) {
654654
if (sortedTop[k] && typeof sortedTop[k] === 'object')
655655
sortedTop[k] = sortDepsAsc(sortedTop[k])
656656
}

packages/pickier/test/lint-disable-next-line.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('disable-next-line directives', () => {
9090
const file = 'e.ts'
9191
const src = [
9292
'// pickier-disable-next-line ts/no-require-imports',
93-
"const fs = require('fs')",
93+
'const fs = require(\'fs\')',
9494
'',
9595
].join('\n')
9696
writeFileSync(join(dir, file), src, 'utf8')
@@ -122,4 +122,4 @@ describe('disable-next-line directives', () => {
122122
const code = await runLint([dir], { reporter: 'json' })
123123
expect(code).toBe(0)
124124
})
125-
})
125+
})

packages/pickier/test/lint-fixtures-disable-next-line.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ describe('disable-next-line fixtures', () => {
3030
writeFileSync(cfgPath, JSON.stringify({
3131
verbose: false,
3232
ignores: [],
33-
lint: { extensions: ['ts','js'], reporter: 'json', cache: false, maxWarnings: -1 },
34-
format: { extensions: ['ts','js'], trimTrailingWhitespace: true, maxConsecutiveBlankLines: 1, finalNewline: 'one', indent: 2, quotes: 'single', semi: false },
33+
lint: { extensions: ['ts', 'js'], reporter: 'json', cache: false, maxWarnings: -1 },
34+
format: { extensions: ['ts', 'js'], trimTrailingWhitespace: true, maxConsecutiveBlankLines: 1, finalNewline: 'one', indent: 2, quotes: 'single', semi: false },
3535
rules: { noDebugger: 'error', noConsole: 'warn' },
3636
pluginRules: { 'sort-objects': 'warn', 'ts/no-require-imports': 'error' },
3737
}, null, 2), 'utf8')
@@ -48,4 +48,4 @@ describe('disable-next-line fixtures', () => {
4848
const lintCode = await runLint([dir], { config: cfgPath, reporter: 'json' })
4949
expect(lintCode).toBe(0)
5050
})
51-
})
51+
})

packages/pickier/test/rules-ts-no-require-imports.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('ts/no-require-imports', () => {
1313
const dir = tmp()
1414
const file = 'a.ts'
1515
const src = [
16-
"const fs = require('fs')",
16+
'const fs = require(\'fs\')',
1717
'export const x = fs.existsSync ? 1 : 0',
1818
'',
1919
].join('\n')
@@ -38,7 +38,7 @@ describe('ts/no-require-imports', () => {
3838
const dir = tmp()
3939
const file = 'b.ts'
4040
const src = [
41-
"const mod = await import('fs')",
41+
'const mod = await import(\'fs\')',
4242
'export { mod }',
4343
'',
4444
].join('\n')
@@ -57,4 +57,4 @@ describe('ts/no-require-imports', () => {
5757
const code = await runLint([dir], { config: cfgPath, reporter: 'json' })
5858
expect(code).toBe(0)
5959
})
60-
})
60+
})

0 commit comments

Comments
 (0)