Skip to content

Commit

Permalink
refactor: apply prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Aug 14, 2024
1 parent d068fa6 commit e28e191
Showing 1 changed file with 51 additions and 48 deletions.
99 changes: 51 additions & 48 deletions lib/utils/compat.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,79 @@
import { type TSESLint, type TSESTree } from '@typescript-eslint/utils';

declare module '@typescript-eslint/utils/dist/ts-eslint/Rule' {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface RuleContext<TMessageIds extends string, TOptions extends readonly unknown[]> {
/**
* The filename associated with the source.
*/
filename: string;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface RuleContext<
TMessageIds extends string,

Check warning on line 6 in lib/utils/compat.ts

View workflow job for this annotation

GitHub Actions / Verifications / Code Validation: lint

'TMessageIds' is defined but never used
TOptions extends readonly unknown[]

Check warning on line 7 in lib/utils/compat.ts

View workflow job for this annotation

GitHub Actions / Verifications / Code Validation: lint

'TOptions' is defined but never used
> {
/**
* The filename associated with the source.
*/
filename: string;

/**
* A SourceCode object that you can use to work with the source that
* was passed to ESLint.
*/
sourceCode: Readonly<TSESLint.SourceCode>;
}
/**
* A SourceCode object that you can use to work with the source that
* was passed to ESLint.
*/
sourceCode: Readonly<TSESLint.SourceCode>;
}
}

declare module '@typescript-eslint/utils/dist/ts-eslint/SourceCode' {
export interface SourceCode {
/**
* Returns the scope of the given node.
* This information can be used track references to variables.
* @since 8.37.0
*/
getScope(node: TSESTree.Node): TSESLint.Scope.Scope;
/**
* Returns an array of the ancestors of the given node, starting at
* the root of the AST and continuing through the direct parent of the current node.
* This array does not include the currently-traversed node itself.
* @since 8.38.0
*/
getAncestors(node: TSESTree.Node): TSESTree.Node[];
/**
* Returns a list of variables declared by the given node.
* This information can be used to track references to variables.
* @since 8.38.0
*/
getDeclaredVariables(
node: TSESTree.Node,
): readonly TSESLint.Scope.Variable[];
}
export interface SourceCode {
/**
* Returns the scope of the given node.
* This information can be used track references to variables.
* @since 8.37.0
*/
getScope(node: TSESTree.Node): TSESLint.Scope.Scope;
/**
* Returns an array of the ancestors of the given node, starting at
* the root of the AST and continuing through the direct parent of the current node.
* This array does not include the currently-traversed node itself.
* @since 8.38.0
*/
getAncestors(node: TSESTree.Node): TSESTree.Node[];
/**
* Returns a list of variables declared by the given node.
* This information can be used to track references to variables.
* @since 8.38.0
*/
getDeclaredVariables(
node: TSESTree.Node
): readonly TSESLint.Scope.Variable[];
}
}

/* istanbul ignore next */
export const getFilename = (
context: TSESLint.RuleContext<string, unknown[]>,
context: TSESLint.RuleContext<string, unknown[]>
) => {
return context.filename ?? context.getFilename();
return context.filename ?? context.getFilename();
};

/* istanbul ignore next */
export const getSourceCode = (
context: TSESLint.RuleContext<string, unknown[]>,
context: TSESLint.RuleContext<string, unknown[]>
) => {
return context.sourceCode ?? context.getSourceCode();
return context.sourceCode ?? context.getSourceCode();
};

/* istanbul ignore next */
export const getScope = (
context: TSESLint.RuleContext<string, unknown[]>,
node: TSESTree.Node,
context: TSESLint.RuleContext<string, unknown[]>,
node: TSESTree.Node
) => {
return getSourceCode(context).getScope?.(node) ?? context.getScope();
return getSourceCode(context).getScope?.(node) ?? context.getScope();
};

/* istanbul ignore next */
export const getDeclaredVariables = (
context: TSESLint.RuleContext<string, unknown[]>,
node: TSESTree.Node,
context: TSESLint.RuleContext<string, unknown[]>,
node: TSESTree.Node
) => {
return (
getSourceCode(context).getDeclaredVariables?.(node) ??
context.getDeclaredVariables(node)
);
return (
getSourceCode(context).getDeclaredVariables?.(node) ??
context.getDeclaredVariables(node)
);
};

0 comments on commit e28e191

Please sign in to comment.