@addon24/eslint-config
Version:
ESLint configuration rules for WorldOfTextcraft projects - Centralized configuration for all project types
162 lines (131 loc) • 5.65 kB
JavaScript
#!/usr/bin/env node
import { execSync } from 'child_process';
import fs from 'fs';
console.log('🧪 ESLint-Plugin Integrationstests für no-entity-type-casting Regel');
console.log('================================================================');
console.log('');
// Test 1: no-entity-type-casting Regel - Verbotene Type-Castings erkennen
console.log('📋 Test 1: no-entity-type-casting - Verbotene Type-Castings erkennen');
console.log('--------------------------------------------------------------------');
try {
// Erstelle eine Test-Datei mit verbotenen Type-Castings
const badServiceContent = `
import { Injectable } from "@nestjs/common";
import MonsterTypeEntity from "@/entity/Wot/Data/MonsterTypeEntity";
import AreaEntity from "@/entity/Wot/World/AreaEntity";
@Injectable()
export class TestService {
public badExample1() {
const updateData: any = {};
updateData.monsterType = { id: "123" } as MonsterTypeEntity;
}
public badExample2() {
const area = { id: "456" } as AreaEntity;
}
public badExample3(requestId: string) {
const user = { id: requestId } as UserEntity;
}
}`;
fs.writeFileSync('/app/backend/src/BadService.ts', badServiceContent);
// Teste mit ESLint
const result = execSync('cd /app/backend && yarn run eslint -c eslint.config.js src/BadService.ts --no-color', {
encoding: 'utf8',
stdio: 'pipe'
});
console.log('❌ Unerwartet: Keine Fehler bei verbotenen Type-Castings gefunden');
console.log(' - Regel funktioniert möglicherweise nicht korrekt');
} catch (error) {
if (error.stdout && error.stdout.includes('no-entity-type-casting')) {
console.log('✅ no-entity-type-casting Regel funktioniert korrekt:');
const errorLines = error.stdout.split('\n').filter(line => line.includes('no-entity-type-casting'));
errorLines.slice(0, 3).forEach(line => {
console.log(' ', line.trim());
});
console.log(` - ${errorLines.length} Fehler gefunden (erwartet: 3)`);
} else {
console.log('❌ no-entity-type-casting Regel meldet keine Fehler bei verbotenen Type-Castings');
}
}
console.log('');
// Test 2: no-entity-type-casting Regel - Erlaubte Patterns nicht blockieren
console.log('📋 Test 2: no-entity-type-casting - Erlaubte Patterns nicht blockieren');
console.log('--------------------------------------------------------------------');
try {
// Erstelle eine Test-Datei mit erlaubten Patterns
const goodServiceContent = `
import { Injectable } from "@nestjs/common";
import MonsterTypeEntity from "@/entity/Wot/Data/MonsterTypeEntity";
import AreaEntity from "@/entity/Wot/World/AreaEntity";
@Injectable()
export class TestService {
public goodExample1(monsterType: MonsterTypeEntity) {
const updateData: any = {};
updateData.monsterType = monsterType;
}
public goodExample2() {
const monsterType = {
id: "123",
name: "Goblin",
description: "A small creature"
} as MonsterTypeEntity;
}
public goodExample3() {
const config = { setting: "value" } as ConfigType;
}
}`;
fs.writeFileSync('/app/backend/src/GoodService.ts', goodServiceContent);
// Teste mit ESLint
const result = execSync('cd /app/backend && yarn run eslint -c eslint.config.js src/GoodService.ts --no-color', {
encoding: 'utf8',
stdio: 'pipe'
});
console.log('✅ Erlaubte Patterns: Keine no-entity-type-casting Fehler');
console.log(' - Echte Entity-Objekte werden nicht blockiert');
console.log(' - Vollständige Objekte werden nicht blockiert');
console.log(' - Type-Casting für andere Typen wird nicht blockiert');
} catch (error) {
if (error.stdout && error.stdout.includes('no-entity-type-casting')) {
console.log('❌ no-entity-type-casting Regel meldet False Positives:');
const errorLines = error.stdout.split('\n').filter(line => line.includes('no-entity-type-casting'));
errorLines.slice(0, 3).forEach(line => {
console.log(' ', line.trim());
});
} else {
console.log('✅ Erlaubte Patterns: Keine no-entity-type-casting Fehler');
}
}
console.log('');
// Test 3: no-entity-type-casting Regel - MonsterService.ts testen
console.log('📋 Test 3: no-entity-type-casting - MonsterService.ts testen');
console.log('----------------------------------------------------------');
try {
// Teste die echte MonsterService.ts Datei
const result = execSync('cd /app/backend && yarn run eslint -c eslint.config.js src/service/Wot/Game/Monster/MonsterService.ts --no-color', {
encoding: 'utf8',
stdio: 'pipe'
});
console.log('✅ MonsterService.ts: Keine no-entity-type-casting Fehler');
console.log(' - Alle Type-Castings wurden bereits behoben');
} catch (error) {
if (error.stdout && error.stdout.includes('no-entity-type-casting')) {
console.log('❌ MonsterService.ts hat noch no-entity-type-casting Fehler:');
const errorLines = error.stdout.split('\n').filter(line => line.includes('no-entity-type-casting'));
errorLines.slice(0, 3).forEach(line => {
console.log(' ', line.trim());
});
} else {
console.log('✅ MonsterService.ts: Keine no-entity-type-casting Fehler');
}
}
console.log('');
// Cleanup
try {
fs.unlinkSync('/app/backend/src/BadService.ts');
fs.unlinkSync('/app/backend/src/GoodService.ts');
console.log('🧹 Test-Dateien aufgeräumt');
} catch (cleanupError) {
console.log('⚠️ Cleanup-Fehler (nicht kritisch):', cleanupError.message);
}
console.log('');
console.log('🎯 Integrationstest für no-entity-type-casting Regel abgeschlossen');
console.log('================================================================');