refactor: migrate to eslint flat config and format codebase with prettier

- Remove legacy .eslintrc.cjs and .eslintignore
- Add eslint.config.js with flat config, security rules (no-eval, no-implied-eval, no-new-func, no-script-url)
- Add .prettierrc and .prettierignore
- Format entire codebase with prettier
This commit is contained in:
c0mrade
2026-01-27 17:37:31 +03:00
parent 111ccc4e7a
commit bc90ba3779
133 changed files with 19972 additions and 15523 deletions

View File

@@ -3,11 +3,11 @@
*/
interface RateLimitEntry {
count: number
resetTime: number
count: number;
resetTime: number;
}
const rateLimitStore = new Map<string, RateLimitEntry>()
const rateLimitStore = new Map<string, RateLimitEntry>();
/**
* Check if action is rate limited
@@ -19,52 +19,52 @@ const rateLimitStore = new Map<string, RateLimitEntry>()
export function checkRateLimit(
key: string,
maxRequests: number = 3,
windowMs: number = 10000
windowMs: number = 10000,
): boolean {
const now = Date.now()
const entry = rateLimitStore.get(key)
const now = Date.now();
const entry = rateLimitStore.get(key);
// Clean up expired entry
if (entry && now >= entry.resetTime) {
rateLimitStore.delete(key)
rateLimitStore.delete(key);
}
const currentEntry = rateLimitStore.get(key)
const currentEntry = rateLimitStore.get(key);
if (!currentEntry) {
// First request - allow and start tracking
rateLimitStore.set(key, {
count: 1,
resetTime: now + windowMs,
})
return true
});
return true;
}
if (currentEntry.count >= maxRequests) {
// Rate limit exceeded
return false
return false;
}
// Increment counter and allow
currentEntry.count++
return true
currentEntry.count++;
return true;
}
/**
* Get remaining time until rate limit resets (in seconds)
*/
export function getRateLimitResetTime(key: string): number {
const entry = rateLimitStore.get(key)
if (!entry) return 0
const remaining = entry.resetTime - Date.now()
return remaining > 0 ? Math.ceil(remaining / 1000) : 0
const entry = rateLimitStore.get(key);
if (!entry) return 0;
const remaining = entry.resetTime - Date.now();
return remaining > 0 ? Math.ceil(remaining / 1000) : 0;
}
/**
* Reset rate limit for a key (e.g., after successful action)
*/
export function resetRateLimit(key: string): void {
rateLimitStore.delete(key)
rateLimitStore.delete(key);
}
/**
@@ -72,19 +72,19 @@ export function resetRateLimit(key: string): void {
*/
export function debounce<T extends (...args: unknown[]) => unknown>(
func: T,
wait: number
wait: number,
): (...args: Parameters<T>) => void {
let timeoutId: ReturnType<typeof setTimeout> | null = null
let timeoutId: ReturnType<typeof setTimeout> | null = null;
return (...args: Parameters<T>) => {
if (timeoutId) {
clearTimeout(timeoutId)
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
func(...args)
timeoutId = null
}, wait)
}
func(...args);
timeoutId = null;
}, wait);
};
}
/**
@@ -92,19 +92,19 @@ export function debounce<T extends (...args: unknown[]) => unknown>(
*/
export function throttle<T extends (...args: unknown[]) => unknown>(
func: T,
limit: number
limit: number,
): (...args: Parameters<T>) => void {
let inThrottle = false
let inThrottle = false;
return (...args: Parameters<T>) => {
if (!inThrottle) {
func(...args)
inThrottle = true
func(...args);
inThrottle = true;
setTimeout(() => {
inThrottle = false
}, limit)
inThrottle = false;
}, limit);
}
}
};
}
// Rate limit keys for different actions
@@ -114,4 +114,4 @@ export const RATE_LIMIT_KEYS = {
TICKET_REPLY: 'ticket-reply',
PROMO_ACTIVATE: 'promo-activate',
WHEEL_SPIN: 'wheel-spin',
} as const
} as const;