Skip to content

Commit

Permalink
Update TypeScript typings and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed Jul 27, 2024
1 parent 350582a commit 3e24886
Show file tree
Hide file tree
Showing 6 changed files with 959 additions and 531 deletions.
46 changes: 3 additions & 43 deletions lib/eslint.d.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,14 @@
import type { ESLint, Linter, Rule } from 'eslint';
import type { ESLint, Linter } from 'eslint';

type ConfigData = Linter.Config;
type ESLintrcOptions = ESLint.LegacyOptions;

type ESLintOptions =
Omit<
ESLint.Options,
| 'baseConfig'
| 'fixTypes'
| 'overrideConfig'
| 'overrideConfigFile'
| 'plugins'
| 'reportUnusedDisableDirectives'
| 'resolvePluginsRelativeTo'
> &
{
baseConfig?: Linter.Config | null | undefined;
fixTypes?: Rule.RuleMetaData['type'][] | null | undefined;
flags?: string[] | undefined;
overrideConfig?: Linter.Config | null | undefined;
overrideConfigFile?: string | null | undefined;
plugins?: Record<string, ESLint.Plugin> | null | undefined;
reportUnusedDisableDirectives?: Linter.StringSeverity | null | undefined;
resolvePluginsRelativeTo?: string | null | undefined;
};

type FlatConfig =
Omit<Linter.FlatConfig, 'languageOptions'> &
{
languageOptions?: LanguageOptions;
name?: string;
};
type FlatESLintOptions = ESLint.Options;

type FormatterContext = ESLint.LintResultData & ResultsMeta;

type FormatterFunction =
(results: ESLint.LintResult[], context?: FormatterContext) => string | Promise<string>;

type GlobalConf = boolean | 'off' | 'readable' | 'readonly' | 'writable' | 'writeable';

interface LanguageOptions
{
ecmaVersion?: number | 'latest';
globals?: Record<string, GlobalConf>;
parser?: Linter.ParserModule;
parserOptions?: Linter.ParserOptions;
sourceType?: 'script' | 'module' | 'commonjs';
}

type LintMessage = Linter.LintMessage;

type LintResult = ESLint.LintResult;
Expand All @@ -62,5 +24,3 @@ interface ResultsMeta
maxWarnings: number;
};
}

type Severity = Linter.Severity;
116 changes: 49 additions & 67 deletions lib/gulp-eslint-new.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ import 'node';

type Awaitable<T = unknown> = T | Promise<T>;

type FlatConfig = eslint.FlatConfig;
type ESLintOptions = eslint.ESLintOptions;
type LintMessage = eslint.LintMessage;
type ESLintrcOptions = eslint.ESLintrcOptions;
type FlatESLintOptions = eslint.FlatESLintOptions;
type LintMessage = eslint.LintMessage;

type LintResultStreamFunction<Type> =
((action: (value: Type, callback: TransformCallback) => void) => NodeJS.ReadWriteStream) &
((action: (value: Type) => Awaitable) => NodeJS.ReadWriteStream);

declare namespace gulpESLintNew
{
interface AdditionalOptions
{
quiet?:
| boolean
| ((message: LintMessage, index: number, list: LintMessage[]) => unknown)
| undefined;

warnIgnored?: boolean | undefined;
}

type FormatterContext = eslint.FormatterContext;

type FormatterFunction = eslint.FormatterFunction;
Expand All @@ -26,7 +36,7 @@ declare namespace gulpESLintNew
* @param options - Options for gulp-eslint-new.
* @returns gulp file stream.
*/
(options?: GulpESLintOptions): NodeJS.ReadWriteStream;
(options?: GulpESLintNewOptions): NodeJS.ReadWriteStream;

/**
* Append ESLint result to each file.
Expand All @@ -42,15 +52,15 @@ declare namespace gulpESLintNew
* @param action - A function to handle each ESLint result.
* @returns gulp file stream.
*/
result: LintResultStreamFunction<GulpESLintResult>;
result: LintResultStreamFunction<LintResult>;

/**
* Handle all ESLint results at the end of the stream.
*
* @param action - A function to handle all ESLint results.
* @returns gulp file stream.
*/
results: LintResultStreamFunction<GulpESLintResults>;
results: LintResultStreamFunction<LintResults>;

/**
* Fail when an ESLint error is found in an ESLint result.
Expand Down Expand Up @@ -81,7 +91,7 @@ declare namespace gulpESLintNew
formatEach
(
formatter?: string | LoadedFormatter | FormatterFunction,
writer?: GulpESLintWriter | NodeJS.WritableStream
writer?: Writer | NodeJS.WritableStream
):
NodeJS.ReadWriteStream;

Expand All @@ -100,7 +110,7 @@ declare namespace gulpESLintNew
format
(
formatter?: string | LoadedFormatter | FormatterFunction,
writer?: GulpESLintWriter | NodeJS.WritableStream
writer?: Writer | NodeJS.WritableStream
):
NodeJS.ReadWriteStream;

Expand All @@ -112,84 +122,56 @@ declare namespace gulpESLintNew
fix(): NodeJS.ReadWriteStream;
}

type GulpESLintOptions =
| ((GulpESLintrcOptions | GulpFlatESLintOptions) & { configType?: null | undefined; })
| (GulpESLintrcOptions & { configType: 'eslintrc'; })
| (GulpFlatESLintOptions & { configType: 'flat'; });

type GulpESLintResult = eslint.LintResult;

type GulpESLintResults
=
GulpESLintResult[] &
{
errorCount: number;
fatalErrorCount: number;
warningCount: number;
fixableErrorCount: number;
fixableWarningCount: number;
};

type GulpESLintWriter = (str: string) => Awaitable;

type GulpESLintrcOptions
type GulpESLintNewEslintrcOptions
=
Omit<
ESLintOptions,
ESLintrcOptions,
| 'cache'
| 'cacheLocation'
| 'cacheStrategy'
| 'errorOnUnmatchedPattern'
| 'extensions'
| 'globInputPaths'
> &
{
quiet?:
| boolean
| ((message: LintMessage, index: number, list: LintMessage[]) => unknown)
| undefined;
>
& AdditionalOptions;

warnIgnored?: boolean | undefined;
};

type GulpFlatESLintOptions
type GulpESLintNewFlatOptions
=
Pick<
ESLintOptions,
| 'allowInlineConfig'
| 'cwd'
| 'fix'
| 'fixTypes'
| 'flags'
| 'ignore'
| 'plugins'
> &
{
baseConfig?: FlatConfig | (string | FlatConfig)[] | null | undefined;

ignorePatterns?: string[] | null | undefined;

overrideConfig?: FlatConfig | (string | FlatConfig)[] | null | undefined;

overrideConfigFile?: string | true | null | undefined;

quiet?:
| boolean
| ((message: LintMessage, index: number, list: LintMessage[]) => unknown)
| undefined;
Omit<
FlatESLintOptions,
| 'cache'
| 'cacheLocation'
| 'cacheStrategy'
| 'errorOnUnmatchedPattern'
| 'globInputPaths'
| 'passOnNoPatterns'
>
& AdditionalOptions;

ruleFilter?: ((rule: { ruleId: string; severity: Severity; }) => unknown) | undefined;
type GulpESLintNewOptions =
|
((GulpESLintNewEslintrcOptions | GulpESLintNewFlatOptions) & { configType?: null | undefined; })
| (GulpESLintNewEslintrcOptions & { configType: 'eslintrc'; })
| (GulpESLintNewFlatOptions & { configType: 'flat'; });

stats?: boolean | undefined;
type LintResult = eslint.LintResult;

warnIgnored?: boolean | undefined;
type LintResults
=
LintResult[] &
{
errorCount: number;
fatalErrorCount: number;
warningCount: number;
fixableErrorCount: number;
fixableWarningCount: number;
};

type LoadedFormatter = eslint.LoadedFormatter;

type ResultsMeta = eslint.ResultsMeta;

type Severity = eslint.Severity;
type Writer = (str: string) => Awaitable;
}

declare const gulpESLintNew: gulpESLintNew.GulpESLintNew;
Expand Down
25 changes: 9 additions & 16 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
'use strict';

/**
* @typedef {import('eslint').ESLint} ESLint
* @typedef {import('./gulp-eslint-new').GulpESLintWriter} GulpESLintWriter
* @typedef {import('./eslint').LintMessage} LintMessage
* @typedef {import('./eslint').LintResult} LintResult
* @typedef {import('./eslint').LintResultData} LintResultData
* @typedef {import('./eslint').LoadedFormatter} LoadedFormatter
*/

/**
* @callback FormatterFunction
* @param {LintResult[]} results
* @param {LintResultData} [data]
* @returns {string | Promise<string>}
* @typedef {import('eslint').ESLint} ESLint
* @typedef {import('./eslint').FormatterFunction} FormatterFunction
* @typedef {import('./eslint').LintMessage} LintMessage
* @typedef {import('./eslint').LintResult} LintResult
* @typedef {import('./eslint').LoadedFormatter} LoadedFormatter
* @typedef {import('./gulp-eslint-new').Writer} Writer
*/

const { normalize, relative } = require('path');
Expand Down Expand Up @@ -449,9 +442,9 @@ async ({ cwd, eslint }, formatter) =>
/**
* Resolve a writer function used to write formatted ESLint messages.
*
* @param {GulpESLintWriter | NodeJS.WritableStream} [writer=require('fancy-log')]
* @param {Writer | NodeJS.WritableStream} [writer=require('fancy-log')]
* A stream or function to resolve as a format writer.
* @returns {GulpESLintWriter} A function that writes formatted messages.
* @returns {Writer} A function that writes formatted messages.
*/
exports.resolveWriter =
(writer = require('fancy-log')) =>
Expand All @@ -474,7 +467,7 @@ exports.resolveWriter =
* @param {LoadedFormatter} formatterObj
* A formatter object.
*
* @param {GulpESLintWriter} [writer]
* @param {Writer} [writer]
* A function used to write formatted ESLint messages.
*/
exports.writeResults =
Expand Down
Loading

0 comments on commit 3e24886

Please sign in to comment.