super-productivity/tools/check-file.js
Johannes Millan c4023b4f45 fix(security): address CodeQL security alerts
- Fix incomplete HTML sanitization in errors.ts (alerts #50-52)
  Apply regex repeatedly to handle nested inputs like <scri<script>pt>
- Add lgtm comment for intentional cert bypass in jira.ts (alert #40)
- Fix incomplete string escaping in load-env.js (alert #39)
  Escape backslashes before quotes
- Fix shell command injection in check-file.js (alerts #37-38)
  Use execFileSync with args array instead of string interpolation
2025-12-23 13:42:57 +01:00

46 lines
1.2 KiB
JavaScript

#!/usr/bin/env node
const { execFileSync } = require('child_process');
const path = require('path');
const file = process.argv[2];
if (!file) {
console.error('❌ Please provide a file path');
process.exit(1);
}
// Get absolute path
const absolutePath = path.resolve(file);
try {
// Run prettier
console.log(`🎨 Formatting ${path.basename(file)}...`);
execFileSync('npm', ['run', 'prettier:file', '--', absolutePath], {
stdio: 'pipe',
encoding: 'utf8',
});
// Run lint based on file type
console.log(`🔍 Linting ${path.basename(file)}...`);
if (file.endsWith('.scss')) {
// Use stylelint for SCSS files
execFileSync('npx', ['stylelint', absolutePath], {
stdio: 'pipe',
encoding: 'utf8',
});
} else {
// Use ng lint for TypeScript/JavaScript files
execFileSync('npm', ['run', 'lint:file', '--', absolutePath], {
stdio: 'pipe',
encoding: 'utf8',
});
}
// If we get here, both commands succeeded
console.log(`${path.basename(file)} - All checks passed!`);
} catch (error) {
// If there's an error, show the full output
console.error('\n❌ Errors found:\n');
console.error(error.stdout || error.stderr || error.message);
process.exit(1);
}