Skip to content

Commit

Permalink
feat: fix tests, move more utils
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Dec 29, 2021
1 parent 7742976 commit b482f03
Show file tree
Hide file tree
Showing 31 changed files with 601 additions and 605 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -44,7 +44,6 @@
"start": "nx run website:start",
"test": "nx run-many --target=test --all --parallel",
"test-integration": "yarn jest -c ./tests/integration/jest.config.js",
"test-kill-integration-containers": "docker-compose -f tests/integration/docker-compose.yml down -v --rmi local",
"typecheck": "nx run-many --target=typecheck --all --parallel"
},
"config": {
Expand Down
Expand Up @@ -158,7 +158,7 @@ export default util.createRule<Options, MessageIds>({
function deconstructComparison(
node: TSESTree.BinaryExpression,
): BooleanComparison | undefined {
const comparisonType = util.getEqualsKind(node.operator);
const comparisonType = getEqualsKind(node.operator);
if (!comparisonType) {
return undefined;
}
Expand Down Expand Up @@ -275,3 +275,39 @@ export default util.createRule<Options, MessageIds>({
};
},
});

interface EqualsKind {
isPositive: boolean;
isStrict: boolean;
}

function getEqualsKind(operator: string): EqualsKind | undefined {
switch (operator) {
case '==':
return {
isPositive: true,
isStrict: false,
};

case '===':
return {
isPositive: true,
isStrict: true,
};

case '!=':
return {
isPositive: false,
isStrict: false,
};

case '!==':
return {
isPositive: false,
isStrict: true,
};

default:
return undefined;
}
}
Expand Up @@ -17,14 +17,14 @@ import {
createRule,
getParserServices,
getConstrainedTypeAtLocation,
getTypeOfPropertyOfName,
isNullableType,
nullThrows,
NullThrowsReasons,
isIdentifier,
isTypeAnyType,
isTypeUnknownType,
getTypeName,
getTypeOfPropertyOfName,
} from '../util';

// Truthiness utilities
Expand Down
Expand Up @@ -2,14 +2,13 @@ import {
AST_NODE_TYPES,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import { ESLintTypeUtils } from '@typescript-eslint/type-utils';
import * as util from '../util';

type Options = [
{
checkParameterProperties?: boolean;
ignoreInferredTypes?: boolean;
} & ESLintTypeUtils.ReadonlynessOptions,
} & util.ReadonlynessOptions,
];
type MessageIds = 'shouldBeReadonly';

Expand All @@ -34,7 +33,7 @@ export default util.createRule<Options, MessageIds>({
ignoreInferredTypes: {
type: 'boolean',
},
...ESLintTypeUtils.readonlynessOptionsSchema.properties,
...util.readonlynessOptionsSchema.properties,
},
},
],
Expand All @@ -46,7 +45,7 @@ export default util.createRule<Options, MessageIds>({
{
checkParameterProperties: true,
ignoreInferredTypes: false,
...ESLintTypeUtils.readonlynessOptionsDefaults,
...util.readonlynessOptionsDefaults,
},
],
create(
Expand Down Expand Up @@ -98,7 +97,7 @@ export default util.createRule<Options, MessageIds>({

const tsNode = esTreeNodeToTSNodeMap.get(actualParam);
const type = checker.getTypeAtLocation(tsNode);
const isReadOnly = ESLintTypeUtils.isTypeReadonly(checker, type, {
const isReadOnly = util.isTypeReadonly(checker, type, {
treatMethodsAsReadonly: treatMethodsAsReadonly!,
});

Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin/src/util/getWrappingFixer.ts
Expand Up @@ -4,7 +4,6 @@ import {
ASTUtils,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import { SourceCode } from '@typescript-eslint/experimental-utils/src/ts-eslint';

interface WrappingFixerParams {
/** Source code. */
Expand Down Expand Up @@ -135,7 +134,7 @@ function isWeakPrecedenceParent(node: TSESTree.Node): boolean {
*/
function isMissingSemicolonBefore(
node: TSESTree.Node,
sourceCode: SourceCode,
sourceCode: TSESLint.SourceCode,
): boolean {
for (;;) {
const parent = node.parent!;
Expand Down
17 changes: 1 addition & 16 deletions packages/eslint-plugin/src/util/index.ts
@@ -1,5 +1,4 @@
import { ESLintUtils } from '@typescript-eslint/experimental-utils';
import { ESLintTypeUtils } from '@typescript-eslint/type-utils';

export * from './astUtils';
export * from './collectUnusedVariables';
Expand All @@ -9,10 +8,9 @@ export * from './getThisExpression';
export * from './getWrappingFixer';
export * from './misc';
export * from './objectIterators';
export * from './requiresQuoting';
export * from './types';

// this is done for convenience - saves migrating all of the old rules
export * from '@typescript-eslint/type-utils';
const {
applyDefault,
deepMerge,
Expand All @@ -25,26 +23,13 @@ type InferMessageIdsTypeFromRule<T> =
ESLintUtils.InferMessageIdsTypeFromRule<T>;
type InferOptionsTypeFromRule<T> = ESLintUtils.InferOptionsTypeFromRule<T>;

const {
getTypeOfPropertyOfName,
isTypeReadonly,
readonlynessOptionsSchema,
readonlynessOptionsDefaults,
} = ESLintTypeUtils;
type ReadonlynessOptions = ESLintTypeUtils.ReadonlynessOptions;

export {
applyDefault,
deepMerge,
isObjectNotArray,
getParserServices,
getTypeOfPropertyOfName,
isTypeReadonly,
nullThrows,
readonlynessOptionsDefaults,
readonlynessOptionsSchema,
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
NullThrowsReasons,
ReadonlynessOptions,
};
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/util/misc.ts
Expand Up @@ -7,7 +7,7 @@ import {
TSESLint,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import { requiresQuoting } from './requiresQuoting';
import { requiresQuoting } from '@typescript-eslint/type-utils';

/**
* Check if the context file name is *.d.ts or *.d.tsx
Expand Down

0 comments on commit b482f03

Please sign in to comment.