Skip to content

Commit

Permalink
Merge pull request #13 from JakeGinnivan/chore/convert-to-eslint
Browse files Browse the repository at this point in the history
chore: Convert to eslint
  • Loading branch information
JakeGinnivan authored Aug 29, 2019
2 parents 93e562e + 9d6c12f commit c40fff9
Show file tree
Hide file tree
Showing 13 changed files with 1,759 additions and 1,475 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["wanews-base"]
}
8 changes: 6 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"editor.formatOnSave": true
}
"editor.formatOnSave": true,
"eslint.validate": [
"javascript",
{ "language": "typescript", "autoFix": true }
]
}
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// eslint-disable-next-line no-undef
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
}
}
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "yarn build:esm && yarn build:cjs",
"build:esm": "tsc --module es2015 --target es5 --outDir dist/esm -p tsconfig.build.json",
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs -p tsconfig.build.json",
"lint": "yarn tslint --project .",
"lint": "eslint --ext .js,.ts .",
"test": "jest",
"verify": "yarn tsc -p tsconfig.json && yarn test && yarn lint"
},
Expand All @@ -19,16 +19,19 @@
"devDependencies": {
"@types/cross-spawn": "^6.0.0",
"@types/jest": "^24.0.18",
"@types/node": "^12.7.2",
"@types/mock-knex": "^0.4.1",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"cross-spawn": "^6.0.5",
"eslint": "^6.2.2",
"eslint-config-prettier": "^6.1.0",
"eslint-config-wanews-base": "^2.0.1",
"jest": "^24.9.0",
"knex": "^0.19.2",
"mock-knex": "^0.4.3",
"knex": "^0.19.3",
"mock-knex": "^0.4.6",
"ts-jest": "^24.0.2",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0",
"tslint-eslint-rules": "^5.4.0",
"typescript": "^3.5.3"
"typescript": "^3.6.2"
},
"peerDependencies": {
"knex": "^0.16.0",
Expand Down
12 changes: 6 additions & 6 deletions src/__snapshots__/type-safety.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Typescript: Typescript expected failures 1`] = `
"src/type-safety-fixtures/args-respected.ts(37,27): error TS7006: Parameter '_' implicitly has an 'any' type.
src/type-safety-fixtures/args-respected.ts(45,41): error TS2345: Argument of type '1' is not assignable to parameter of type 'object'.
src/type-safety-fixtures/args-respected.ts(46,41): error TS2345: Argument of type '1' is not assignable to parameter of type 'string'.
src/type-safety-fixtures/args-respected.ts(47,41): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ id: number; }'.
Property 'id' is missing in type '{}' but required in type '{ id: number; }'.
"src/type-safety-fixtures/args-respected.ts(38,27): error TS7006: Parameter '_' implicitly has an 'any' type.
src/type-safety-fixtures/args-respected.ts(46,41): error TS2345: Argument of type '1' is not assignable to parameter of type 'object'.
src/type-safety-fixtures/args-respected.ts(47,41): error TS2345: Argument of type '1' is not assignable to parameter of type 'string'.
src/type-safety-fixtures/args-respected.ts(48,41): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ id: number; }'.
Property 'id' is missing in type '{}' but required in type '{ id: number; }'.
src/type-safety-fixtures/args-respected.ts(50,11): error TS2554: Expected 2 arguments, but got 1.
src/type-safety-fixtures/args-respected.ts(49,41): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ id: number; }'.
Property 'id' is missing in type '{}' but required in type '{ id: number; }'.
src/type-safety-fixtures/args-respected.ts(51,25): error TS2554: Expected 2 arguments, but got 1.
src/type-safety-fixtures/create-query-helper.ts(17,20): error TS2339: Property 'wrongTable' does not exist on type 'TableNames<\\"testTable\\">'.
src/type-safety-fixtures/create-query-helper.ts(18,16): error TS2339: Property 'wrongTable' does not exist on type 'Tables<\\"testTable\\">'.
src/type-safety-fixtures/create-query-helper.ts(20,21): error TS2339: Property 'foo' does not exist on type '{ testArg: string; }'.
Expand Down
10 changes: 3 additions & 7 deletions src/mock-query-executor.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { MockQueryExecutor } from '.'

const tables = {
tableOne: 'table-one',
}

it('can mock query', async () => {
const queryExecutor = new MockQueryExecutor()
const exampleQuery = queryExecutor.createQuery<{}, number[]>(async ({}) => {
const exampleQuery = queryExecutor.createQuery<{}, number[]>(async () => {
throw new Error('Should not be called')
})

Expand All @@ -24,7 +20,7 @@ it('can mock query', async () => {
it('can match specific query args', async () => {
const queryExecutor = new MockQueryExecutor()
const exampleQuery = queryExecutor.createQuery<{ param: string }, number>(
async ({}) => {
async () => {
throw new Error('Should not be called')
},
)
Expand All @@ -40,7 +36,7 @@ it('can match specific query args', async () => {
// Execute the query as normal
const result = await queryExecutor.execute(exampleQuery, { param: 'first' })
const result2 = await queryExecutor.execute(exampleQuery, {
param: 'other'
param: 'other',
})

expect(result).toEqual(1)
Expand Down
7 changes: 4 additions & 3 deletions src/type-safety-fixtures/args-respected.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { ReadQueryExecutor } from '../'
import { createMockedKnex } from '../test-helpers/knex'

const testTables = {
tableOne: 'table-one'
tableOne: 'table-one',
}

export async function dontComplainAboutUnused() {
Expand All @@ -13,7 +14,7 @@ export async function dontComplainAboutUnused() {
queryBuilderWrapper: query => {
executedQuery = query.toString()
return query
}
},
})

const query2 = async (_: any, args: string) => {
Expand All @@ -31,7 +32,7 @@ export async function dontComplainAboutUnused() {
;(() => args)()
tables.tableOne()
return {}
}
},
)

const query4 = async (_, args: { id: number }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/type-safety-fixtures/create-query-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const queryExecutor = new ReadQueryExecutor(
},
)

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const exampleQuery = queryExecutor.createQuery<{ testArg: string }, string>(
// tslint:disable-next-line:no-shadowed-variable
async function exampleQuery({ tableNames, tables }, args) {
tableNames.wrongTable
tables.wrongTable()
Expand Down
2 changes: 1 addition & 1 deletion src/type-safety-fixtures/query-arguments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Knex from 'knex'
import { QueryExecutor, ReadQueryExecutor, Query } from '../'
import { ReadQueryExecutor, Query } from '../'

declare const knex: Knex

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es2015"],
"lib": ["es5", "es2015"],
"noEmit": true,
"strict": true,
"moduleResolution": "node",
Expand Down
15 changes: 0 additions & 15 deletions tslint.json

This file was deleted.

Loading

0 comments on commit c40fff9

Please sign in to comment.