Skip to content

Commit

Permalink
feat(): migrate to eslint, add commilint, release-it
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Feb 21, 2020
1 parent af7a855 commit 8b7460a
Show file tree
Hide file tree
Showing 20 changed files with 3,712 additions and 163 deletions.
28 changes: 28 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": ["@commitlint/config-angular"],
"rules": {
"subject-case": [
2,
"always",
["sentence-case", "start-case", "pascal-case", "upper-case", "lower-case"]
],
"type-enum": [
2,
"always",
[
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"style",
"test",
"sample"
]
]
}
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/**
26 changes: 26 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
};
11 changes: 9 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# source
lib
tests

index.ts
package-lock.json
tslint.json
tsconfig.json
.prettierrc

# misc
.commitlintrc.json
.release-it.json
.eslintignore
.eslintrc.js
renovate.json
.prettierignore
.prettierrc
8 changes: 8 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"git": {
"commitMessage": "chore(): release v${version}"
},
"github": {
"release": true
}
}
1 change: 1 addition & 0 deletions lib/decorators/args.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { addPipesMetadata } from './param.utils';

let TypeGqlArg, TypeGqlArgs;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const TypeGql = require('type-graphql');
TypeGqlArg = TypeGql.Arg;
TypeGqlArgs = TypeGql.Args;
Expand Down
2 changes: 1 addition & 1 deletion lib/decorators/mutation.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function Mutation(
options?: AdvancedOptions,
): MethodDecorator {
return (
target: Object | Function,
target: Record<string, any> | Function,
key?: string | symbol,
descriptor?: any,
) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/decorators/param.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const addPipesMetadata = (
paramtype: GqlParamtype,
data: any,
pipes: (Type<PipeTransform> | PipeTransform)[],
target: Object,
target: Record<string, any>,
key: string | symbol,
index: number,
) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/decorators/query.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function Query(
options?: AdvancedOptions,
): MethodDecorator {
return (
target: Object | Function,
target: Record<string, any> | Function,
key?: string | symbol,
descriptor?: any,
) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/decorators/resolver.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function Resolver(
options?: ResolverClassOptions,
) {
return (
target: Object | Function,
target: Record<string, any> | Function,
key?: string | symbol,
descriptor?: any,
) => {
Expand Down
7 changes: 4 additions & 3 deletions lib/decorators/resolvers.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ try {
export function addResolverMetadata(
resolver: Resolvers | string | undefined,
name: string | undefined,
target?: Object | Function,
target?: Record<string, any> | Function,
key?: string | symbol,
descriptor?: any,
) {
Expand All @@ -52,10 +52,11 @@ export function createPropertyDecorator(
advancedOptions?: AdvancedOptions,
): MethodDecorator {
return (
target: Function | Object,
target: Function | Record<string, any>,
key?: string | symbol,
descriptor?: any,
) => {
// eslint-disable-next-line prefer-const
let [propertyName, typeFunc, options] = isFunction(propertyNameOrFunc)
? typeFuncOrOptions && typeFuncOrOptions.name
? [typeFuncOrOptions.name, propertyNameOrFunc, typeFuncOrOptions]
Expand Down Expand Up @@ -89,7 +90,7 @@ export function createDelegateDecorator(
options?: AdvancedOptions,
): MethodDecorator {
return (
target: Function | Object,
target: Function | Record<string, any>,
key?: string | symbol,
descriptor?: any,
) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/decorators/subscription.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function Subscription(
options: AdvancedOptions & SubscriptionOptions = {},
): MethodDecorator {
return (
target: Object | Function,
target: Record<string, any> | Function,
key?: string | symbol,
descriptor?: any,
) => {
Expand Down
1 change: 1 addition & 0 deletions lib/graphql-types.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as fs from 'fs';
import { flatten } from 'lodash';
import { mergeTypes } from 'merge-graphql-schemas';
import * as util from 'util';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const normalize = require('normalize-path');

const readFile = util.promisify(fs.readFile);
Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/resolver-metadata.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export interface ResolverMetadata {
name: string;
type: string;
methodName: string;
callback?: Function | Object;
callback?: Function | Record<string, any>;
}
1 change: 1 addition & 0 deletions lib/services/delegates-explorer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class DelegatesExplorerService extends BaseExplorerService {
curryDelegates(delegates): (mergeInfo: any) => any {
return mergeInfo =>
mapValues(delegates, parent =>
// eslint-disable-next-line @typescript-eslint/no-unused-vars
mapValues(parent, (propertyFn, key) => propertyFn()(mergeInfo)),
);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/services/resolvers-explorer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class ResolversExplorerService extends BaseExplorerService {
});
}

createContextCallback<T extends Object>(
createContextCallback<T extends Record<string, any>>(
instance: T,
prototype: any,
wrapper: InstanceWrapper,
Expand Down Expand Up @@ -205,7 +205,7 @@ export class ResolversExplorerService extends BaseExplorerService {
createSubscribeContext: Function,
subscriptionOptions: SubscriptionOptions,
resolverMetadata: ResolverMetadata,
instanceRef: Object,
instanceRef: Record<string, any>,
) {
const resolveFunc =
subscriptionOptions &&
Expand Down Expand Up @@ -253,9 +253,11 @@ export class ResolversExplorerService extends BaseExplorerService {
private registerContextProvider<T = any>(request: T, contextId: ContextId) {
const coreModuleArray = [...this.modulesContainer.entries()]
.filter(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
([key, { metatype }]) =>
metatype && metatype.name === InternalCoreModule.name,
)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.map(([key, value]) => value);

const coreModuleRef = head(coreModuleArray);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/extract-metadata.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { ResolverMetadata } from '../interfaces/resolver-metadata.interface';

export function extractMetadata(
instance: Object,
instance: Record<string, any>,
prototype: any,
methodName: string,
filterPredicate: (
Expand Down
Loading

0 comments on commit 8b7460a

Please sign in to comment.