Skip to content

Commit

Permalink
Use lint script for all linting
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Nov 24, 2024
1 parent 20df406 commit 1a8129f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dev": "pnpm dev:stage1 && pnpm dev:stage2 && pnpm dev:stage3",
"watch:tsc": "tsc -w -p src",
"start": "pnpm watch",
"lint": "tsx scripts/lint.ts",
"============SCRIPTS": "============",
"spritesheet": "tsx ./scripts/spritesheet.ts && pnpm lint:biome",
"data": "concurrently \"tsx ./scripts/monster_table.ts\" && pnpm lint",
Expand All @@ -32,11 +33,6 @@
"test:docker": "docker compose up --no-attach db --no-attach redis --build --abort-on-container-exit && docker compose down -v",
"test:watch": "vitest --config vitest.unit.config.mts --coverage",
"test:ci:unit": "pnpm concurrent \"pnpm test:unit\" \"pnpm test:lint\" \"tsc -p tests/integration\" \"tsc -p tests/unit\"",
"============LINTING": "============",
"lint:biome": "git diff --name-only --diff-filter=d HEAD | xargs biome check --write --unsafe --diagnostic-level=error",
"lint:prettier": "prettier --use-tabs \"./**/*.{md,yml}\" --write --log-level silent",
"lint:prisma": "pnpm concurrent \"prisma format --schema ./prisma/robochimp.prisma\" \"prisma format --schema ./prisma/schema.prisma\"",
"lint": "pnpm concurrent \"pnpm lint:biome\" \"pnpm lint:prettier\"",
"============MISC": "============",
"concurrent": "concurrently --raw --kill-others-on-fail",
"build:packages": "concurrently --raw \"pnpm --stream -r build:esbuild\" \"pnpm --stream -r build:types\"",
Expand Down
39 changes: 39 additions & 0 deletions scripts/lint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { execSync } from 'node:child_process';

try {
const changedFiles = execSync(
'git diff --name-only --diff-filter=AM HEAD && git ls-files --others --exclude-standard'
)
.toString()
.trim()
.split('\n');

if (changedFiles.length > 0) {
execSync(`biome check ${changedFiles.join(' ')} --write --unsafe --diagnostic-level=error`, {
stdio: 'inherit'
});

// Prettier
const prettierFiles = changedFiles.filter(f => /\.(md|yaml)$/.exec(f));
if (prettierFiles.length) {
console.log(`Prettier is formatting: ${prettierFiles.join(', ')}`);
execSync(`prettier --use-tabs ${prettierFiles.join(' ')} --write --log-level silent`, {
stdio: 'inherit'
});
} else {
console.log('Nothing for prettier to format.');
}

// Prisma
if (changedFiles.some(f => f.includes('prisma/schema.prisma'))) {
console.log('Formatting Prisma schema files');
execSync(
'prisma format --schema ./prisma/robochimp.prisma && prisma format --schema ./prisma/schema.prisma',
{ stdio: 'inherit' }
);
}
}
} catch (error) {
console.error('Error occurred while running biome lint:', error);
process.exit(1);
}

0 comments on commit 1a8129f

Please sign in to comment.