Skip to content

Commit

Permalink
feat(experimental-utils): move some util function files from eslint-p…
Browse files Browse the repository at this point in the history
…lugin to experimental-utils

files moved:
 - isTypeReadonly
 - nullThrows
 - propertyTypes

fix typescript-eslint#3657
  • Loading branch information
RebeccaStevens committed Jul 25, 2021
1 parent d358785 commit ffd668a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 9 deletions.
11 changes: 8 additions & 3 deletions packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts
Expand Up @@ -3,9 +3,14 @@ import {
AST_NODE_TYPES,
TSESLint,
} from '@typescript-eslint/experimental-utils';
import { isTypeAssertion, isConstructor, isSetter } from './astUtils';
import { getFunctionHeadLoc } from './getFunctionHeadLoc';
import { nullThrows, NullThrowsReasons } from './nullThrows';
import {
isTypeAssertion,
isConstructor,
isSetter,
getFunctionHeadLoc,
nullThrows,
NullThrowsReasons,
} from '.';

type FunctionExpression =
| TSESTree.ArrowFunctionExpression
Expand Down
21 changes: 16 additions & 5 deletions packages/eslint-plugin/src/util/index.ts
Expand Up @@ -6,17 +6,23 @@ export * from './createRule';
export * from './getFunctionHeadLoc';
export * from './getThisExpression';
export * from './getWrappingFixer';
export * from './isTypeReadonly';
export * from './misc';
export * from './nullThrows';
export * from './objectIterators';
export * from './propertyTypes';
export * from './requiresQuoting';
export * from './types';

// this is done for convenience - saves migrating all of the old rules
const { applyDefault, deepMerge, isObjectNotArray, getParserServices } =
ESLintUtils;
const {
applyDefault,
deepMerge,
isObjectNotArray,
isTypeReadonly,
getParserServices,
getTypeOfPropertyOfName,
getTypeOfPropertyOfType,
nullThrows,
NullThrowsReasons,
} = ESLintUtils;
type InferMessageIdsTypeFromRule<T> =
ESLintUtils.InferMessageIdsTypeFromRule<T>;
type InferOptionsTypeFromRule<T> = ESLintUtils.InferOptionsTypeFromRule<T>;
Expand All @@ -25,7 +31,12 @@ export {
applyDefault,
deepMerge,
isObjectNotArray,
isTypeReadonly,
getParserServices,
getTypeOfPropertyOfName,
getTypeOfPropertyOfType,
nullThrows,
NullThrowsReasons,
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
};
3 changes: 2 additions & 1 deletion packages/experimental-utils/package.json
Expand Up @@ -44,7 +44,8 @@
"@typescript-eslint/types": "4.28.4",
"@typescript-eslint/typescript-estree": "4.28.4",
"eslint-scope": "^5.1.1",
"eslint-utils": "^3.0.0"
"eslint-utils": "^3.0.0",
"tsutils": "^3.21.0"
},
"peerDependencies": {
"eslint": "*"
Expand Down
3 changes: 3 additions & 0 deletions packages/experimental-utils/src/eslint-utils/index.ts
Expand Up @@ -5,3 +5,6 @@ export * from './InferTypesFromRule';
export * from './RuleCreator';
export * from './RuleTester';
export * from './deepMerge';
export * from './isTypeReadonly';
export * from './propertyTypes';
export * from './nullThrows';
33 changes: 33 additions & 0 deletions packages/experimental-utils/typings/typescript.d.ts
@@ -0,0 +1,33 @@
import 'typescript';

declare module 'typescript' {
interface TypeChecker {
// internal TS APIs

/**
* @returns `true` if the given type is an array type:
* - `Array<foo>`
* - `ReadonlyArray<foo>`
* - `foo[]`
* - `readonly foo[]`
*/
isArrayType(type: Type): type is TypeReference;
/**
* @returns `true` if the given type is a tuple type:
* - `[foo]`
* - `readonly [foo]`
*/
isTupleType(type: Type): type is TupleTypeReference;
/**
* Return the type of the given property in the given type, or undefined if no such property exists
*/
getTypeOfPropertyOfType(type: Type, propertyName: string): Type | undefined;
}

interface Type {
/**
* If the type is `any`, and this is set to "error", then TS was unable to resolve the type
*/
intrinsicName?: string;
}
}

0 comments on commit ffd668a

Please sign in to comment.