Skip to content

Commit 16ce74d

Browse files
authored
feat(experimental-utils): update eslint types to match v6.8 (typescript-eslint#1846)
1 parent 7c11bd6 commit 16ce74d

File tree

7 files changed

+74
-15
lines changed

7 files changed

+74
-15
lines changed

packages/experimental-utils/src/ts-eslint-scope/ScopeManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ESLintScopeManager from 'eslint-scope/lib/scope-manager';
22
import { TSESTree } from '../ts-estree';
3+
import { EcmaVersion } from '../ts-eslint';
34
import { Scope } from './Scope';
45
import { Variable } from './Variable';
56

@@ -10,7 +11,7 @@ interface ScopeManagerOptions {
1011
nodejsScope?: boolean;
1112
sourceType?: 'module' | 'script';
1213
impliedStrict?: boolean;
13-
ecmaVersion?: number;
14+
ecmaVersion?: EcmaVersion;
1415
}
1516

1617
interface ScopeManager {

packages/experimental-utils/src/ts-eslint-scope/analyze.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { analyze as ESLintAnalyze } from 'eslint-scope';
2+
import { EcmaVersion } from '../ts-eslint';
23
import { ScopeManager } from './ScopeManager';
34

45
interface AnalysisOptions {
@@ -9,7 +10,7 @@ interface AnalysisOptions {
910
impliedStrict?: boolean;
1011
fallback?: string | ((node: {}) => string[]);
1112
sourceType?: 'script' | 'module';
12-
ecmaVersion?: number;
13+
ecmaVersion?: EcmaVersion;
1314
}
1415
const analyze = ESLintAnalyze as (
1516
ast: {},

packages/experimental-utils/src/ts-eslint/CLIEngine.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import { CLIEngine as ESLintCLIEngine } from 'eslint';
44
import { Linter } from './Linter';
5-
import { RuleModule, RuleListener } from './Rule';
5+
import { RuleMetaData, RuleModule, RuleListener } from './Rule';
66

77
interface CLIEngine {
8-
version: string;
9-
108
executeOnFiles(patterns: string[]): CLIEngine.LintReport;
119

1210
resolveFileGlobPatterns(patterns: string[]): string[];
@@ -39,6 +37,7 @@ namespace CLIEngine {
3937
configFile?: string;
4038
cwd?: string;
4139
envs?: string[];
40+
errorOnUnmatchedPattern?: boolean;
4241
extensions?: string[];
4342
fix?: boolean;
4443
globals?: string[];
@@ -49,6 +48,7 @@ namespace CLIEngine {
4948
parser?: string;
5049
parserOptions?: Linter.ParserOptions;
5150
plugins?: string[];
51+
resolvePluginsRelativeTo?: string;
5252
rules?: {
5353
[name: string]: Linter.RuleLevel | Linter.RuleLevelAndOptions;
5454
};
@@ -73,18 +73,34 @@ namespace CLIEngine {
7373
warningCount: number;
7474
fixableErrorCount: number;
7575
fixableWarningCount: number;
76+
usedDeprecatedRules: DeprecatedRuleUse[];
77+
}
78+
79+
export interface DeprecatedRuleUse {
80+
ruleId: string;
81+
replacedBy: string[];
82+
}
83+
84+
export interface LintResultData<TMessageIds extends string> {
85+
rulesMeta: {
86+
[ruleId: string]: RuleMetaData<TMessageIds>;
87+
};
7688
}
7789

78-
export type Formatter = (results: LintResult[]) => string;
90+
export type Formatter = <TMessageIds extends string>(
91+
results: LintResult[],
92+
data?: LintResultData<TMessageIds>,
93+
) => string;
7994
}
8095

8196
const CLIEngine = ESLintCLIEngine as {
8297
new (options: CLIEngine.Options): CLIEngine;
8398

8499
// static methods
85100
getErrorResults(results: CLIEngine.LintResult[]): CLIEngine.LintResult[];
86-
101+
getFormatter(format?: string): CLIEngine.Formatter;
87102
outputFixes(report: CLIEngine.LintReport): void;
103+
version: string;
88104
};
89105

90106
export { CLIEngine };

packages/experimental-utils/src/ts-eslint/Linter.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,35 @@ namespace Linter {
6060

6161
export type RuleLevelAndOptions = [RuleLevel, ...unknown[]];
6262

63-
export interface Config {
64-
rules?: {
65-
[name: string]: RuleLevel | RuleLevelAndOptions;
66-
};
63+
export type RuleEntry = RuleLevel | RuleLevelAndOptions;
64+
export type RulesRecord = Partial<Record<string, RuleEntry>>;
65+
66+
// https://github.com/eslint/eslint/blob/v6.8.0/conf/config-schema.js
67+
interface BaseConfig {
68+
$schema?: string;
69+
env?: { [name: string]: boolean };
70+
extends?: string | string[];
71+
globals?: { [name: string]: boolean };
72+
noInlineConfig?: boolean;
73+
overrides?: ConfigOverride[];
6774
parser?: string;
6875
parserOptions?: ParserOptions;
76+
plugins?: string[];
77+
processor?: string;
78+
reportUnusedDisableDirectives?: boolean;
6979
settings?: { [name: string]: unknown };
70-
env?: { [name: string]: boolean };
71-
globals?: { [name: string]: boolean };
80+
rules?: RulesRecord;
81+
}
82+
83+
export interface ConfigOverride extends BaseConfig {
84+
excludedFiles?: string | string[];
85+
files: string | string[];
86+
}
87+
export type RuleOverride = ConfigOverride; // TODO - delete this next major
88+
89+
export interface Config extends BaseConfig {
90+
ignorePatterns?: string | string[];
91+
root?: boolean;
7292
}
7393

7494
export type ParserOptions = TSParserOptions;

packages/experimental-utils/src/ts-eslint/ParserOptions.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
import { TSESTreeOptions } from '@typescript-eslint/typescript-estree';
22

3+
type EcmaVersion =
4+
| 3
5+
| 5
6+
| 6
7+
| 7
8+
| 8
9+
| 9
10+
| 10
11+
| 11
12+
| 2015
13+
| 2016
14+
| 2017
15+
| 2018
16+
| 2019
17+
| 2020;
18+
319
interface ParserOptions {
420
comment?: boolean;
521
ecmaFeatures?: {
622
globalReturn?: boolean;
723
jsx?: boolean;
824
};
9-
ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 2015 | 2016 | 2017 | 2018 | 2019;
25+
ecmaVersion?: EcmaVersion;
1026
errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;
1127
errorOnUnknownASTType?: boolean;
1228
extraFileExtensions?: string[];
@@ -25,4 +41,4 @@ interface ParserOptions {
2541
warnOnUnsupportedTypeScriptVersion?: boolean;
2642
}
2743

28-
export { ParserOptions };
44+
export { EcmaVersion, ParserOptions };

packages/experimental-utils/src/ts-eslint/Rule.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ interface ReportDescriptorBase<TMessageIds extends string> {
128128
* The messageId which is being reported.
129129
*/
130130
messageId: TMessageIds;
131+
131132
// we disallow this because it's much better to use messageIds for reusable errors that are easily testable
132133
// desc?: string;
133134
}

packages/experimental-utils/src/ts-eslint/RuleTester.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface SuggestionOutput<TMessageIds extends string> {
2424
* Each individual error has its own suggestion, so you have to show the correct, _isolated_ output for each suggestion.
2525
*/
2626
output: string;
27+
// we disallow this because it's much better to use messageIds for reusable errors that are easily testable
28+
// desc?: string;
2729
}
2830

2931
interface InvalidTestCase<
@@ -36,6 +38,8 @@ interface InvalidTestCase<
3638

3739
interface TestCaseError<TMessageIds extends string> {
3840
messageId: TMessageIds;
41+
// we disallow this because it's much better to use messageIds for reusable errors that are easily testable
42+
// message?: string;
3943
data?: Record<string, unknown>;
4044
type?: AST_NODE_TYPES | AST_TOKEN_TYPES;
4145
line?: number;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy