Skip to content

feat(experimental-utils): update eslint types to match v6.8 #1846

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

Merged
merged 1 commit into from
Apr 5, 2020
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ESLintScopeManager from 'eslint-scope/lib/scope-manager';
import { TSESTree } from '../ts-estree';
import { EcmaVersion } from '../ts-eslint';
import { Scope } from './Scope';
import { Variable } from './Variable';

Expand All @@ -10,7 +11,7 @@ interface ScopeManagerOptions {
nodejsScope?: boolean;
sourceType?: 'module' | 'script';
impliedStrict?: boolean;
ecmaVersion?: number;
ecmaVersion?: EcmaVersion;
}

interface ScopeManager {
Expand Down
3 changes: 2 additions & 1 deletion packages/experimental-utils/src/ts-eslint-scope/analyze.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { analyze as ESLintAnalyze } from 'eslint-scope';
import { EcmaVersion } from '../ts-eslint';
import { ScopeManager } from './ScopeManager';

interface AnalysisOptions {
Expand All @@ -9,7 +10,7 @@ interface AnalysisOptions {
impliedStrict?: boolean;
fallback?: string | ((node: {}) => string[]);
sourceType?: 'script' | 'module';
ecmaVersion?: number;
ecmaVersion?: EcmaVersion;
}
const analyze = ESLintAnalyze as (
ast: {},
Expand Down
26 changes: 21 additions & 5 deletions packages/experimental-utils/src/ts-eslint/CLIEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import { CLIEngine as ESLintCLIEngine } from 'eslint';
import { Linter } from './Linter';
import { RuleModule, RuleListener } from './Rule';
import { RuleMetaData, RuleModule, RuleListener } from './Rule';

interface CLIEngine {
version: string;

executeOnFiles(patterns: string[]): CLIEngine.LintReport;

resolveFileGlobPatterns(patterns: string[]): string[];
Expand Down Expand Up @@ -39,6 +37,7 @@ namespace CLIEngine {
configFile?: string;
cwd?: string;
envs?: string[];
errorOnUnmatchedPattern?: boolean;
extensions?: string[];
fix?: boolean;
globals?: string[];
Expand All @@ -49,6 +48,7 @@ namespace CLIEngine {
parser?: string;
parserOptions?: Linter.ParserOptions;
plugins?: string[];
resolvePluginsRelativeTo?: string;
rules?: {
[name: string]: Linter.RuleLevel | Linter.RuleLevelAndOptions;
};
Expand All @@ -73,18 +73,34 @@ namespace CLIEngine {
warningCount: number;
fixableErrorCount: number;
fixableWarningCount: number;
usedDeprecatedRules: DeprecatedRuleUse[];
}

export interface DeprecatedRuleUse {
ruleId: string;
replacedBy: string[];
}

export interface LintResultData<TMessageIds extends string> {
rulesMeta: {
[ruleId: string]: RuleMetaData<TMessageIds>;
};
}

export type Formatter = (results: LintResult[]) => string;
export type Formatter = <TMessageIds extends string>(
results: LintResult[],
data?: LintResultData<TMessageIds>,
) => string;
}

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

// static methods
getErrorResults(results: CLIEngine.LintResult[]): CLIEngine.LintResult[];

getFormatter(format?: string): CLIEngine.Formatter;
outputFixes(report: CLIEngine.LintReport): void;
version: string;
};

export { CLIEngine };
32 changes: 26 additions & 6 deletions packages/experimental-utils/src/ts-eslint/Linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,35 @@ namespace Linter {

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

export interface Config {
rules?: {
[name: string]: RuleLevel | RuleLevelAndOptions;
};
export type RuleEntry = RuleLevel | RuleLevelAndOptions;
export type RulesRecord = Partial<Record<string, RuleEntry>>;

// https://github.com/eslint/eslint/blob/v6.8.0/conf/config-schema.js
interface BaseConfig {
$schema?: string;
env?: { [name: string]: boolean };
extends?: string | string[];
globals?: { [name: string]: boolean };
noInlineConfig?: boolean;
overrides?: ConfigOverride[];
parser?: string;
parserOptions?: ParserOptions;
plugins?: string[];
processor?: string;
reportUnusedDisableDirectives?: boolean;
settings?: { [name: string]: unknown };
env?: { [name: string]: boolean };
globals?: { [name: string]: boolean };
rules?: RulesRecord;
}

export interface ConfigOverride extends BaseConfig {
excludedFiles?: string | string[];
files: string | string[];
}
export type RuleOverride = ConfigOverride; // TODO - delete this next major

export interface Config extends BaseConfig {
ignorePatterns?: string | string[];
root?: boolean;
}

export type ParserOptions = TSParserOptions;
Expand Down
20 changes: 18 additions & 2 deletions packages/experimental-utils/src/ts-eslint/ParserOptions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import { TSESTreeOptions } from '@typescript-eslint/typescript-estree';

type EcmaVersion =
| 3
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 2015
| 2016
| 2017
| 2018
| 2019
| 2020;

interface ParserOptions {
comment?: boolean;
ecmaFeatures?: {
globalReturn?: boolean;
jsx?: boolean;
};
ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 2015 | 2016 | 2017 | 2018 | 2019;
ecmaVersion?: EcmaVersion;
errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;
errorOnUnknownASTType?: boolean;
extraFileExtensions?: string[];
Expand All @@ -25,4 +41,4 @@ interface ParserOptions {
warnOnUnsupportedTypeScriptVersion?: boolean;
}

export { ParserOptions };
export { EcmaVersion, ParserOptions };
1 change: 1 addition & 0 deletions packages/experimental-utils/src/ts-eslint/Rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ interface ReportDescriptorBase<TMessageIds extends string> {
* The messageId which is being reported.
*/
messageId: TMessageIds;

// we disallow this because it's much better to use messageIds for reusable errors that are easily testable
// desc?: string;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/experimental-utils/src/ts-eslint/RuleTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface SuggestionOutput<TMessageIds extends string> {
* Each individual error has its own suggestion, so you have to show the correct, _isolated_ output for each suggestion.
*/
output: string;
// we disallow this because it's much better to use messageIds for reusable errors that are easily testable
// desc?: string;
}

interface InvalidTestCase<
Expand All @@ -36,6 +38,8 @@ interface InvalidTestCase<

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