The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Utilities for analyzing and managing ESLint configurations, focusing on type-aware rule detection for TypeScript projects.
import { hasRulesRequiringTypeChecking } from '@nx/eslint';
import type { Linter } from 'eslint';The primary utility for determining if an ESLint configuration uses rules that require TypeScript type information.
/**
* Determines if an ESLint configuration uses rules requiring type checking
* @param eslintConfig - ESLint configuration object to analyze
* @returns Boolean indicating if type-aware rules are present
*/
function hasRulesRequiringTypeChecking(eslintConfig: Linter.Config): boolean;
interface Linter.Config {
parser?: string;
parserOptions?: {
project?: string | string[];
[key: string]: any;
};
rules?: Record<string, any>;
overrides?: Array<{
files: string | string[];
rules?: Record<string, any>;
parserOptions?: any;
}>;
}Usage Examples:
import { hasRulesRequiringTypeChecking } from '@nx/eslint';
// Check if config uses type-aware rules
const config = {
rules: {
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error'
}
};
const requiresTypeInfo = hasRulesRequiringTypeChecking(config);
// Returns: true (both rules require type information)
// Example with no type-aware rules
const simpleConfig = {
rules: {
'no-console': 'warn',
'prefer-const': 'error'
}
};
const noTypeInfo = hasRulesRequiringTypeChecking(simpleConfig);
// Returns: false (no type-aware rules)The following TypeScript ESLint rules require type information and will cause hasRulesRequiringTypeChecking to return true:
@typescript-eslint/await-thenable@typescript-eslint/dot-notation@typescript-eslint/no-floating-promises@typescript-eslint/no-for-in-array@typescript-eslint/no-implied-eval@typescript-eslint/no-misused-promises@typescript-eslint/no-throw-literal@typescript-eslint/no-unnecessary-type-assertion@typescript-eslint/no-unsafe-argument@typescript-eslint/no-unsafe-assignment@typescript-eslint/no-unsafe-call@typescript-eslint/no-unsafe-member-access@typescript-eslint/no-unsafe-return@typescript-eslint/prefer-includes@typescript-eslint/prefer-nullish-coalescing@typescript-eslint/prefer-readonly@typescript-eslint/prefer-readonly-parameter-types@typescript-eslint/prefer-reduce-type-parameter@typescript-eslint/prefer-regexp-exec@typescript-eslint/prefer-string-starts-ends-with@typescript-eslint/promise-function-async@typescript-eslint/require-array-sort-compare@typescript-eslint/restrict-plus-operands@typescript-eslint/restrict-template-expressions@typescript-eslint/strict-boolean-expressions@typescript-eslint/switch-exhaustiveness-check@typescript-eslint/unbound-methodThis utility is primarily used by the @nx/eslint:lint executor to determine if the hasTypeAwareRules option should be set, which affects caching behavior:
import { hasRulesRequiringTypeChecking } from '@nx/eslint';
// In a project configuration
const projectConfig = {
targets: {
lint: {
executor: '@nx/eslint:lint',
options: {
lintFilePatterns: ['src/**/*.ts'],
hasTypeAwareRules: hasRulesRequiringTypeChecking(eslintConfig)
}
}
}
};When hasTypeAwareRules is true, the lint executor will invalidate its cache when any TypeScript files or tsconfig.json files change, ensuring accurate type-aware linting.
Install with Tessl CLI
npx tessl i tessl/npm-nx--eslint