An ESLint runner for Jest that integrates ESLint into the Jest testing framework for unified code testing and quality checks
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The main Jest runner that integrates ESLint into the Jest testing framework, treating linting as tests with full Jest compatibility.
The primary export that provides Jest runner functionality for ESLint integration.
/**
* Jest runner that integrates ESLint into Jest testing workflow
* Created using create-jest-runner with ESLint-specific configuration
*/
const runner = require("jest-runner-eslint");Usage Examples:
// jest.config.js - Standalone runner
module.exports = {
runner: 'jest-runner-eslint',
displayName: 'lint',
testMatch: ['<rootDir>/src/**/*.js'],
};
// jest.config.js - Multi-project setup
module.exports = {
projects: [
{
displayName: 'test',
testMatch: ['<rootDir>/src/**/*.test.js'],
},
{
runner: 'jest-runner-eslint',
displayName: 'lint',
testMatch: ['<rootDir>/src/**/*.js'],
},
],
};Core function that runs ESLint on individual files and formats results for Jest.
/**
* Executes ESLint on a test file and returns Jest-compatible results
* Supports both legacy and flat ESLint configurations automatically
* @param testPath - Path to the file to lint
* @param config - Jest configuration object
* @param extraOptions - Additional options from runner (e.g., fix override)
* @returns Promise resolving to Jest TestResult object
*/
async function runESLint({
testPath: string,
config: JestConfig,
extraOptions: ExtraOptions
}): Promise<TestResult>;
interface JestConfig {
rootDir: string;
setupTestFrameworkScriptFile?: string;
setupFilesAfterEnv?: string[];
[key: string]: any;
}
interface ExtraOptions {
fix?: boolean;
[key: string]: any;
}Usage Examples:
// Internal usage by Jest runner framework
const result = await runESLint({
testPath: '/path/to/file.js',
config: jestConfig,
extraOptions: { fix: true }
});
// Result contains Jest-compatible test results
console.log(result.numFailingTests); // Number of ESLint errors
console.log(result.testResults); // Detailed error informationFunctions that convert ESLint output into Jest-compatible test results.
/**
* Creates Jest TestResult object from ESLint execution data
* @param options - Result creation options
* @returns Jest TestResult object
*/
function mkTestResults({
message?: string,
start: number,
end: number,
numFailingTests: number,
numPassingTests: number,
testPath: string,
assertionResults: TestAssertionResult[],
cliOptions?: ESLintCliOptions
}): TestResult;
/**
* Converts ESLint messages to Jest assertion results
* @param testPath - Path to the file that was linted
* @param report - ESLint report output
* @returns Array of Jest assertion results
*/
function mkAssertionResults(
testPath: string,
report: ESLintReport[]
): TestAssertionResult[];
interface ESLintReport {
messages: ESLintMessage[];
errorCount: number;
warningCount: number;
}
interface ESLintMessage {
message: string;
line: number;
column: number;
ruleId: string;
severity: number;
}Functions for integrating with Jest runner configuration and ESLint options.
/**
* Computes the fix option value based on configuration
* @param options - Configuration options
* @returns Fix function or boolean value for ESLint
*/
function getComputedFixValue({
fix?: boolean,
quiet?: boolean,
fixDryRun?: boolean
}): boolean | ((result: { severity: number }) => boolean) | undefined;
/**
* Removes undefined values from configuration object
* @param object - Configuration object to clean
* @returns Object with undefined values removed
*/
function removeUndefinedFromObject(object: Record<string, any>): Record<string, any>;
/**
* Gets cached ESLint instance and related functions
* @param config - Jest configuration
* @param extraOptions - Additional options
* @returns Cached ESLint instance and utilities
*/
async function getCachedValues(
config: JestConfig,
extraOptions: ExtraOptions
): Promise<{
isPathIgnored: (path: string) => Promise<boolean>;
lintFiles: (files: string[]) => Promise<ESLintReport[]>;
formatter: (results: ESLintReport[]) => Promise<string>;
cliOptions: ESLintCliOptions;
ESLintConstructor: typeof ESLint;
}>;Usage Examples:
// Example of how ESLint execution handles different scenarios
const { isPathIgnored, lintFiles, formatter } = await getCachedValues(config, extraOptions);
// Check if file should be ignored
if (await isPathIgnored(testPath)) {
return mkTestResults({
start: Date.now(),
end: Date.now(),
testPath,
numFailingTests: 0,
numPassingTests: 0,
assertionResults: [{
title: 'ESLint',
status: 'skipped',
}],
});
}
// Run ESLint and format results
const report = await lintFiles([testPath]);
const message = await formatter(report);