import { JSONSchema4 } from '@typescript-eslint/utils/json-schema' import { TSESLint } from '@typescript-eslint/utils' import { CommonPartitionOptions } from '../types/common-partition-options.js' import { CommonGroupsOptions } from '../types/common-groups-options.js' import { TsConfigOption } from '../types/ts-config-option.js' import { CommonOptions } from '../types/common-options.js' /** * Global settings for the Perfectionist plugin. * * These settings can be configured in ESLint configuration under the * 'perfectionist' key and apply to all Perfectionist rules unless overridden by * rule-specific options. */ export type Settings = Partial< Pick< CommonGroupsOptions, 'newlinesBetween' | 'newlinesInside' > & { tsconfig: TsConfigOption } & CommonPartitionOptions & CommonOptions > /** * Validates the values of the settings that a rule uses. * * A rule uses a setting when the setting is one of the rule options and the * rule options do not override it. The values of these settings must match the * JSON schemas of the rule options, which ESLint checks only for the options * themselves. The other settings do not affect the rule, so they are not * checked. As in ESLint, settings set to `undefined` are not checked either. * Unknown settings have no JSON schema and are rejected by `getSettings`. * * Some rules allow additional values for the common options, such as the * `'type-import-first'` type of `sort-imports`. These rules pass their own * common JSON schemas. * * @example * * ```ts * validateSettingsValues({ * settings: { type: 'Natural' }, * defaults: { type: 'alphabetical' }, * options: {}, * }) * // Throws: Error: Invalid value(s) for Perfectionist setting(s): type * * validateSettingsValues({ * settings: { type: 'Natural' }, * defaults: { type: 'alphabetical' }, * options: { type: 'natural' }, * }) * // Does not throw: the options override the setting. * ``` * * @param params - Parameters object. * @param params.commonJsonSchemas - JSON schemas of the common options of the * rule, built with `buildCommonJsonSchemas`. * @param params.settings - Settings returned by `getSettings`. * @param params.defaults - Default values of the rule options. * @param params.options - Rule options that override the settings. * @throws {Error} If a setting that the rule uses has an invalid value. */ export declare function validateSettingsValues({ commonJsonSchemas, settings, defaults, options, }: { commonJsonSchemas?: Record | undefined settings: Record defaults: Record options: Record }): void /** * Extracts and validates Perfectionist settings from ESLint configuration. * * Retrieves global Perfectionist settings that apply to all rules. Validates * that only allowed settings are provided and throws an error if invalid * options are detected. This ensures configuration errors are caught early with * clear error messages. The setting values are validated later by * `validateSettingsValues`, once it is known which settings a rule uses. * * The settings are accessed from the 'perfectionist' key in ESLint's shared * configuration settings. * * @example * * ```ts * // Valid usage: * const settings = getSettings(context.settings) * // Returns: { type: 'natural', order: 'asc', ignoreCase: true } * ``` * * @example * * ```ts * // Invalid setting throws error: * getSettings({ * perfectionist: { * type: 'natural', * invalidOption: true, // This will throw * }, * }) * // Throws: Error: Invalid Perfectionist setting(s): invalidOption * ``` * * @param settings - ESLint shared configuration settings object. * @returns Validated Perfectionist settings or empty object if none configured. * @throws {Error} If invalid settings are provided. */ export declare function getSettings( settings: TSESLint.SharedConfigurationSettings, ): Settings