Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync to eslint Linter.Rule types #173

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/rules/rule-config.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
import type { RuleSeverity } from './rule-severity';
import type { RuleLevel } from './rule-severity';

// Synced to https://github.com/DefinitelyTyped/DefinitelyTyped/blob/042141ce5f77f36df01c344ad09f32feda26c4fd/types/eslint/helpers.d.ts#L1-L3

export type Prepend<Tuple extends any[], Addend> = ((
_: Addend,
..._1: Tuple
) => any) extends (..._: infer Result) => any
? Result
: never;

// Synced to https://github.com/DefinitelyTyped/DefinitelyTyped/blob/042141ce5f77f36df01c344ad09f32feda26c4fd/types/eslint/index.d.ts#L717-L719

/**
* Rule configuration.
*/
export type RuleLevelAndOptions<Options extends any[] = any[]> = Prepend<
Partial<Options>,
RuleLevel
>;

export type RuleEntry<Options extends any[] = any[]> =
| RuleLevel
| RuleLevelAndOptions<Options>;

/**
* Rule configuration.
*
* @alias RuleEntry
*/
export type RuleConfig<Options extends unknown[] = unknown[]> =
| RuleSeverity
| [RuleSeverity, ...Options];
export type RuleConfig<Options extends any[] = any[]> = RuleEntry<Options>;
16 changes: 15 additions & 1 deletion src/rules/rule-severity.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// Synced to https://github.com/DefinitelyTyped/DefinitelyTyped/blob/042141ce5f77f36df01c344ad09f32feda26c4fd/types/eslint/index.d.ts#L714-L716

/**
* Rule ordinal severity.
*/
export type Severity = 0 | 1 | 2;

/**
* Rule severity.
*/
export type RuleLevel = Severity | 'off' | 'warn' | 'error';

/**
* Rule severity.
*
* @alias RuleLevel
*/
export type RuleSeverity = 'off' | 'warn' | 'error' | 0 | 1 | 2;
export type RuleSeverity = RuleLevel;