Skip to content

Commit 7906297

Browse files
committed
Adding tslint
1 parent 66f862d commit 7906297

File tree

6 files changed

+115
-21
lines changed

6 files changed

+115
-21
lines changed

package-lock.json

Lines changed: 77 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apollo-cache-lite",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "A lightweight cache implementation for Apollo Client.",
55
"license": "GPL-3.0-or-later",
66
"repository": "thedevcore/apollo-cache-lite",
@@ -17,7 +17,9 @@
1717
"scripts": {
1818
"test": "jest --runInBand --colors --testPathPattern",
1919
"test:dev": "jest --runInBand --colors --watch --testPathPattern",
20-
"build": "cross-env NODE_ENV=production tsc"
20+
"lint": "tslint src/**/*.ts",
21+
"build": "cross-env NODE_ENV=production tsc",
22+
"prepublish": "npm run lint && npm run test && npm run build"
2123
},
2224
"dependencies": {
2325
"apollo-cache": "1.3.2",
@@ -35,6 +37,7 @@
3537
"graphql-tools": "4.0.5",
3638
"jest": "24.9.0",
3739
"ts-jest": "24.1.0",
40+
"tslint": "5.20.0",
3841
"typescript": "3.6.3"
3942
}
4043
}

src/ApolloCacheLite.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { ApolloCache, DataProxy, Cache } from 'apollo-cache';
1+
import { ApolloCache, Cache, DataProxy, Transaction } from 'apollo-cache';
22
import { addTypenameToDocument } from 'apollo-utilities';
3-
import { DocumentNode } from 'graphql';
43
import * as deepmerge from 'deepmerge';
4+
import { DocumentNode } from 'graphql';
55

6-
import { CacheStore, SerialisedState, QueryStore} from './cache-interfaces';
6+
import { CacheStore, QueryStore, SerialisedState } from './cache-interfaces';
77
import { getCacheableNodes, getDefaultIdFromNode, getHashForQuery } from './utils';
88

99
export interface ApolloCacheLiteOptions {
@@ -28,8 +28,8 @@ export class ApolloCacheLite extends ApolloCache<SerialisedState> {
2828
const result = this.read(query as Cache.ReadOptions<any>);
2929

3030
return {
31-
result,
32-
complete: !!result
31+
complete: !!result,
32+
result
3333
};
3434
}
3535

@@ -64,7 +64,7 @@ export class ApolloCacheLite extends ApolloCache<SerialisedState> {
6464
const [type, id] = options.id.split(':');
6565
return this.store[type][id] as T;
6666

67-
} catch (o_O) {
67+
} catch (e) {
6868
return;
6969
}
7070
}
@@ -88,7 +88,7 @@ export class ApolloCacheLite extends ApolloCache<SerialisedState> {
8888
queries: this.queries,
8989
store: this.store
9090
};
91-
} catch (o_O) {}
91+
} catch (e) {}
9292

9393
return this;
9494
}
@@ -105,15 +105,18 @@ export class ApolloCacheLite extends ApolloCache<SerialisedState> {
105105

106106
// @TODO
107107
evict<TVariables = any>(query: Cache.EvictOptions<TVariables>): Cache.EvictionResult {
108-
throw new Error("Method not implemented.");
108+
throw new Error('[apollo-cache-lite] Method not implemented!');
109109
}
110+
110111
removeOptimistic(id: string): void {
111-
throw new Error("Method not implemented.");
112+
throw new Error('[apollo-cache-lite] Method not implemented!');
112113
}
113-
performTransaction(transaction: import("apollo-cache").Transaction<SerialisedState>): void {
114-
throw new Error("Method not implemented.");
114+
115+
performTransaction(transaction: Transaction<SerialisedState>): void {
116+
throw new Error('[apollo-cache-lite] Method not implemented!');
115117
}
116-
recordOptimisticTransaction(transaction: import("apollo-cache").Transaction<SerialisedState>, id: string): void {
117-
throw new Error("Method not implemented.");
118+
119+
recordOptimisticTransaction(transaction: Transaction<SerialisedState>, id: string): void {
120+
throw new Error('[apollo-cache-lite] Method not implemented!');
118121
}
119122
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './ApolloCacheLite';
2-
export * from './cache-interfaces'
2+
export * from './cache-interfaces';
33
export * from './utils';

src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as deepmerge from 'deepmerge';
21
import { Cache } from 'apollo-cache';
2+
import * as deepmerge from 'deepmerge';
33

44
import { CacheStore } from './cache-interfaces';
55

@@ -13,7 +13,9 @@ export function getHash(s: any): string {
1313

1414
for (let i = 0; i < str.length; i++) {
1515
const char = str.charCodeAt(i);
16+
// tslint:disable-next-line:no-bitwise
1617
hash = ((hash << 5) - hash) + char;
18+
// tslint:disable-next-line:no-bitwise
1719
hash = hash & hash;
1820
}
1921

@@ -27,7 +29,7 @@ export function getHashForQuery(query: Cache.ReadOptions): string {
2729
export function getCacheableNodes(obj: any, getIdFromNode: (o: any) => string): CacheStore {
2830
let nodes: CacheStore = {};
2931

30-
for (const key in obj) {
32+
for (const key of Object.keys(obj)) {
3133
const value = obj[key];
3234

3335
if (key === '__typename') {

tslint.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "tslint:recommended",
3+
"rules": {
4+
"arrow-parens": [true, "ban-single-arg-parens"],
5+
"forin": false,
6+
"interface-name": [true, "never-prefix"],
7+
"member-access": [true, "no-public"],
8+
"no-empty": [true, "allow-empty-catch"],
9+
"quotemark": [true, "single"],
10+
"trailing-comma": [true, { "multiline": "never", "singleline": "never"}]
11+
}
12+
}

0 commit comments

Comments
 (0)