eslint-config-styleguidejs
Version:
JS Style Guide ESLint Configuration
82 lines (65 loc) โข 2.47 kB
JavaScript
import {ESLint} from 'eslint';
import path from 'path';
import {fileURLToPath} from 'url';
import {config, typescriptConfig} from '../eslint.config.js';
import {validateRules} from './validate-rules.js';
// Get the directory name of the current module
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const runTypescriptTest = async () => {
console.log('Running TypeScript configuration test...');
try {
const eslint = new ESLint({
overrideConfig: typescriptConfig,
overrideConfigFile: true
});
const testFiles = [
path.join(__dirname, 'import-external-builtin-order.test.ts'),
path.join(__dirname, 'import-builtin-external-order.test.ts'),
path.join(__dirname, 'import-type-placement.test.ts'),
path.join(__dirname, 'import-type-sort.test.ts'),
path.join(__dirname, 'typescript-test.ts'),
];
const results = await eslint.lintFiles(testFiles);
const formatter = await eslint.loadFormatter('stylish');
const resultText = formatter.format(results);
console.log('ESLint Results:');
console.log(resultText);
// Check if there are any errors
const hasErrors = results.some((result) => result.errorCount > 0);
if(hasErrors) {
console.error('โ TypeScript configuration test failed with errors.');
return false;
}
console.log('โ
TypeScript configuration test passed successfully!');
return true;
} catch(error) {
console.error('โ Error running TypeScript test:', error);
return false;
}
};
const runAllTests = async () => {
console.log('๐งช Running all tests for eslint-config-styleguidejs...\n');
const testResults = [];
// Run TypeScript test
testResults.push(await runTypescriptTest());
// Run rule validation test
console.log('\nRunning rule validation test...');
testResults.push(await validateRules());
// Add more tests here as needed
// Print summary
console.log('\n๐ Test Summary:');
const passedCount = testResults.filter((result) => result).length;
const failedCount = testResults.filter((result) => !result).length;
console.log(`Passed: ${passedCount}, Failed: ${failedCount}, Total: ${testResults.length}`);
// Exit with appropriate code
if(failedCount > 0) {
console.log('\nโ Some tests failed.');
process.exit(1);
} else {
console.log('\nโ
All tests passed!');
process.exit(0);
}
};
// Run all tests
runAllTests();