86cce6d161
Biome as it is now didn't work out for us 😢 Summary for posterity: * it IS much, much faster, fast enough to skip any sort of caching * we couldn't fully replace Prettier just yet. We use Prettier programmatically to format code in docs, and Biome's JS interface is officially alpha and [had legacy peer deps set](https://github.com/biomejs/biome/pull/1756) (which would fail our CI build as we don't allow installation warnings) * ternary formatting differs from Prettier, leading to a large diff https://github.com/biomejs/biome/issues/1661 * import sorting differs from Prettier's `prettier-plugin-organize-imports`, making the diff even bigger * the deal breaker is a multi-second delay on saving large files (for us it's [Editor.ts](https://github.com/tldraw/tldraw/blob/main/packages/editor/src/lib/editor/Editor.ts)) in VSCode when import sorting is enabled. There is a seemingly relevant Biome issue where I posted a small summary of our findings: https://github.com/biomejs/biome/issues/1569#issuecomment-1930411623 Further actions: * reevaluate in a few months as Biome matures ### Change Type - [x] `internal` — Any other changes that don't affect the published package
73 lines
1.9 KiB
TypeScript
Executable file
73 lines
1.9 KiB
TypeScript
Executable file
import ignore from 'ignore'
|
|
import * as path from 'path'
|
|
import { exec } from './lib/exec'
|
|
import { REPO_ROOT, readFileIfExists } from './lib/file'
|
|
|
|
const ESLINT_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx']
|
|
const PRETTIER_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx', 'json']
|
|
|
|
async function main() {
|
|
const shouldFix = process.argv.includes('--fix')
|
|
|
|
const lsFiles = await exec('git', ['ls-files', '.'], {
|
|
processStdoutLine: () => {
|
|
// don't print anything
|
|
},
|
|
})
|
|
|
|
const filesByExtension = new Map<string, string[]>()
|
|
for (const file of lsFiles.trim().split('\n')) {
|
|
const ext = file.split('.').pop()
|
|
if (!ext) continue
|
|
let files = filesByExtension.get(ext)
|
|
if (!files) {
|
|
files = []
|
|
filesByExtension.set(ext.toLowerCase(), files)
|
|
}
|
|
files.push(file)
|
|
}
|
|
|
|
let prettierFiles = PRETTIER_EXTENSIONS.flatMap((ext) => filesByExtension.get(ext) ?? [])
|
|
let eslintFiles = ESLINT_EXTENSIONS.flatMap((ext) => filesByExtension.get(ext) ?? [])
|
|
|
|
const relativeCwd = path.relative(REPO_ROOT, process.cwd())
|
|
|
|
const prettierIgnoreFile = await readFileIfExists(path.join(REPO_ROOT, '.prettierignore'))
|
|
if (prettierIgnoreFile) {
|
|
prettierFiles = prettierFiles
|
|
.map((f) => path.join(relativeCwd, f))
|
|
.filter(ignore().add(prettierIgnoreFile).createFilter())
|
|
.map((f) => path.relative(relativeCwd, f))
|
|
}
|
|
|
|
const eslintIgnoreFile = await readFileIfExists(path.join(REPO_ROOT, '.eslintignore'))
|
|
if (eslintIgnoreFile) {
|
|
eslintFiles = eslintFiles
|
|
.map((f) => path.join(relativeCwd, f))
|
|
.filter(ignore().add(eslintIgnoreFile).createFilter())
|
|
.map((f) => path.relative(relativeCwd, f))
|
|
}
|
|
|
|
try {
|
|
await exec('yarn', [
|
|
'run',
|
|
'-T',
|
|
'prettier',
|
|
shouldFix ? '--write' : '--check',
|
|
'--cache',
|
|
...prettierFiles,
|
|
])
|
|
await exec('yarn', [
|
|
'run',
|
|
'-T',
|
|
'eslint',
|
|
'--report-unused-disable-directives',
|
|
shouldFix ? '--fix' : null,
|
|
...eslintFiles,
|
|
])
|
|
} catch (error) {
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
main()
|