Skip to content

Commit

Permalink
Update packages, reformat files
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel7grant committed Nov 14, 2023
1 parent c1f341c commit 901b6ee
Show file tree
Hide file tree
Showing 8 changed files with 766 additions and 2,390 deletions.
3,068 changes: 719 additions & 2,349 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.8",
"eslint-plugin-prettier": "^5.0.1",
"prettier": "^3.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
},
"dependencies": {
"@typescript-eslint/parser": "^6.10.0",
"@typescript-eslint/utils": "^5.60.1"
"@typescript-eslint/utils": "^5.62.0"
}
}
2 changes: 1 addition & 1 deletion src/rules/enforce-column-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { findDecoratorArguments, findParentClass } from '../utils/treeTraversal'

const createRule = ESLintUtils.RuleCreator(
(name) =>
`https://github.com/daniel7grant/eslint-plugin-typeorm-typescript#typeorm-typescript${name}`
`https://github.com/daniel7grant/eslint-plugin-typeorm-typescript#typeorm-typescript${name}`,
);

const enforceColumnTypes = createRule({
Expand Down
4 changes: 2 additions & 2 deletions src/rules/enforce-relation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {

const createRule = ESLintUtils.RuleCreator(
(name) =>
`https://github.com/daniel7grant/eslint-plugin-typeorm-typescript#typeorm-typescript${name}`
`https://github.com/daniel7grant/eslint-plugin-typeorm-typescript#typeorm-typescript${name}`,
);

type EnforceColumnMessages =
Expand Down Expand Up @@ -59,7 +59,7 @@ const enforceColumnTypes = createRule({
(relation): [Relation, TSESTree.CallExpressionArgument[] | undefined] => [
relation,
findDecoratorArguments(node.decorators, relation),
]
],
);
const relationArguments = relationsArguments.find(([, args]) => args);
if (!relationArguments) {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/columnType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function convertTypeOrmToColumnType(arg: string): ColumnTypeString {
}

export function convertArgumentToColumnType(
arg: TSESTree.CallExpressionArgument
arg: TSESTree.CallExpressionArgument,
): ColumnType | undefined {
const parsed = parseObjectLiteral(arg) as { type?: string; nullable?: boolean };
if (parsed.type) {
Expand Down Expand Up @@ -150,7 +150,7 @@ export function convertTypeToColumnType(arg: TSESTree.TypeNode): ColumnType | un
columnType: 'other',
nullable: false,
literal: false,
}
},
);
case AST_NODE_TYPES.TSLiteralType: // Literal type
switch (arg.literal.type) {
Expand Down Expand Up @@ -184,7 +184,7 @@ export function convertTypeToColumnType(arg: TSESTree.TypeNode): ColumnType | un

export function isTypesEqual(
toType: ColumnType | undefined,
tsType: ColumnType | undefined
tsType: ColumnType | undefined,
): boolean {
// If either is undefined, that means we are not sure of the types... ignore
if (!toType || !tsType) {
Expand All @@ -208,7 +208,7 @@ interface TypeToStringMetadata {

export function typeToString(
column: ColumnType | undefined,
{ literal }: TypeToStringMetadata
{ literal }: TypeToStringMetadata,
): string | undefined {
// If unknown or literal, we don't suggest change
if (!column || column.columnType === 'other' || literal) {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/relationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function convertTypeToRelationType(arg: TSESTree.TypeNode): RelationType
name: '',
isArray: false,
nullable: false,
} as RelationType
} as RelationType,
);
}
default: {
Expand All @@ -51,7 +51,7 @@ export function convertTypeToRelationType(arg: TSESTree.TypeNode): RelationType

export function convertArgumentToRelationType(
relation: Relation,
args: TSESTree.CallExpressionArgument[] | undefined
args: TSESTree.CallExpressionArgument[] | undefined,
): RelationType | undefined {
if (!args) {
return undefined;
Expand All @@ -75,7 +75,7 @@ export function convertArgumentToRelationType(

export function isTypesEqual(
toType: RelationType | undefined,
tsType: RelationType | undefined
tsType: RelationType | undefined,
): boolean {
// If either is undefined, that means we are not sure of the types... ignore
if (!toType || !tsType) {
Expand All @@ -92,7 +92,7 @@ export function isTypesEqual(
// Relations are nullable by default which can be confusing, help with a custom message
export function isTypeMissingNullable(
toType: RelationType | undefined,
tsType: RelationType | undefined
tsType: RelationType | undefined,
): boolean {
// If either is undefined, that means we are not sure of the types... ignore
if (!toType || !tsType) {
Expand All @@ -105,7 +105,7 @@ export function isTypeMissingNullable(
// Relations are nullable by default which can be confusing, help with a custom message
export function isTypeMissingArray(
toType: RelationType | undefined,
tsType: RelationType | undefined
tsType: RelationType | undefined,
): boolean {
// If either is undefined, that means we are not sure of the types... ignore
if (!toType || !tsType) {
Expand Down
54 changes: 30 additions & 24 deletions src/utils/treeTraversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';

export function findDecoratorArguments(
decorators: TSESTree.Decorator[] | undefined,
name: string
name: string,
): TSESTree.CallExpressionArgument[] | undefined {
return decorators?.reduce((previous, decorator) => {
if (
decorator.expression.type === AST_NODE_TYPES.CallExpression &&
decorator.expression.callee.type === AST_NODE_TYPES.Identifier &&
decorator.expression.callee.name === name
) {
return decorator.expression.arguments;
}
return previous;
}, undefined as TSESTree.CallExpressionArgument[] | undefined);
return decorators?.reduce(
(previous, decorator) => {
if (
decorator.expression.type === AST_NODE_TYPES.CallExpression &&
decorator.expression.callee.type === AST_NODE_TYPES.Identifier &&
decorator.expression.callee.name === name
) {
return decorator.expression.arguments;
}
return previous;
},
undefined as TSESTree.CallExpressionArgument[] | undefined,
);
}

export function findParentClass(
node: TSESTree.PropertyDefinition
node: TSESTree.PropertyDefinition,
): TSESTree.ClassDeclaration | undefined {
let parentClass = node.parent;
while (parentClass) {
Expand All @@ -40,25 +43,28 @@ export function findReturnedValue(node: TSESTree.Node | undefined): string | und
}

export function findObjectArgument(
args: TSESTree.CallExpressionArgument[] | undefined = []
args: TSESTree.CallExpressionArgument[] | undefined = [],
): TSESTree.CallExpressionArgument | undefined {
return args.find((arg) => arg.type === AST_NODE_TYPES.ObjectExpression);
}

export function parseObjectLiteral(
objectLiteral: TSESTree.Node | undefined
objectLiteral: TSESTree.Node | undefined,
): Record<string, unknown> {
if (objectLiteral?.type === AST_NODE_TYPES.ObjectExpression) {
return objectLiteral.properties.reduce((parsedObject, prop) => {
if (
prop.type === AST_NODE_TYPES.Property &&
prop.key.type === AST_NODE_TYPES.Identifier &&
prop.value.type === AST_NODE_TYPES.Literal
) {
return { ...parsedObject, [prop.key.name]: prop.value.value };
}
return parsedObject;
}, {} as Record<string, unknown>);
return objectLiteral.properties.reduce(
(parsedObject, prop) => {
if (
prop.type === AST_NODE_TYPES.Property &&
prop.key.type === AST_NODE_TYPES.Identifier &&
prop.value.type === AST_NODE_TYPES.Literal
) {
return { ...parsedObject, [prop.key.name]: prop.value.value };
}
return parsedObject;
},
{} as Record<string, unknown>,
);
}
return {};
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "commonjs" /* Specify what module code is generated. */,
"module": "node16" /* Specify what module code is generated. */,
"rootDir": "./src" /* Specify the root folder within your source files. */,
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "node16", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
Expand Down

0 comments on commit 901b6ee

Please sign in to comment.