Skip to content

Commit 61e123e

Browse files
committed
Use eslint
1 parent 173d90a commit 61e123e

File tree

9 files changed

+480
-234
lines changed

9 files changed

+480
-234
lines changed

.eslintrc.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"project": "./tsconfig.json"
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"standard",
9+
"prettier",
10+
"plugin:@typescript-eslint/recommended",
11+
"prettier/@typescript-eslint"
12+
],
13+
"plugins": ["@typescript-eslint"],
14+
"rules": {
15+
"no-empty": "off",
16+
"no-console": "off",
17+
"no-prototype-builtins": "off",
18+
"no-useless-constructor": "off",
19+
"@typescript-eslint/ban-types": "warn",
20+
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
21+
"@typescript-eslint/no-use-before-define": "off",
22+
"@typescript-eslint/no-namespace": "off",
23+
"@typescript-eslint/no-empty-interface": "off",
24+
"@typescript-eslint/no-empty-function": "off",
25+
"@typescript-eslint/no-var-requires": "off",
26+
"@typescript-eslint/no-explicit-any": "off",
27+
"@typescript-eslint/no-non-null-assertion": "off",
28+
"@typescript-eslint/explicit-function-return-type": "off",
29+
"@typescript-eslint/explicit-module-boundary-types": "off",
30+
"@typescript-eslint/ban-ts-ignore": "off",
31+
"@typescript-eslint/return-await": "error",
32+
"@typescript-eslint/naming-convention": "off",
33+
"camelcase": "off",
34+
"no-extend-native": "off",
35+
"no-useless-escape": "off"
36+
},
37+
"env": {
38+
"es6": true,
39+
"node": true
40+
},
41+
"overrides": [
42+
{
43+
"files": ["**/test/**/*.{ts,js}", "*.spec.ts"],
44+
"env": {
45+
"jest": true
46+
},
47+
"rules": {
48+
"@typescript-eslint/no-unused-vars": "off"
49+
}
50+
}
51+
],
52+
"ignorePatterns": ["dist", "node_modules", "examples", "website", "scripts"],
53+
"globals": {
54+
"BigInt": true
55+
}
56+
}

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
version: ${{ matrix.node_version }}
2525
- name: Install Dependencies using Yarn
2626
run: yarn install
27+
- name: Lint
28+
run: yarn lint
2729
- name: Test
2830
run: yarn test
2931

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"scripts": {
3333
"clean": "rm -rf dist",
3434
"prebuild": "yarn clean",
35+
"lint": "eslint --ext .ts \"./src/**/*.ts\"",
3536
"build": "bob build --single",
3637
"test": "jest --forceExit --no-watchman && yarn bundlesize",
3738
"prepare-release": "yarn build && yarn test",
@@ -44,23 +45,31 @@
4445
"@graphql-tools/schema": "6.0.1",
4546
"@types/jest": "25.2.3",
4647
"@types/node": "13.13.9",
48+
"@typescript-eslint/eslint-plugin": "3.0.1",
49+
"@typescript-eslint/parser": "3.0.1",
4750
"bob-the-bundler": "1.0.2",
51+
"eslint": "7.1.0",
52+
"eslint-config-prettier": "6.11.0",
53+
"eslint-config-standard": "14.1.1",
54+
"eslint-plugin-import": "2.20.2",
55+
"eslint-plugin-node": "11.1.0",
56+
"eslint-plugin-promise": "4.2.1",
57+
"eslint-plugin-standard": "4.0.1",
4858
"graphql": "15.0.0",
4959
"husky": "4.2.5",
5060
"jest": "26.0.1",
5161
"lint-staged": "10.2.6",
5262
"prettier": "2.0.5",
5363
"semver": "7.3.2",
5464
"ts-jest": "26.0.0",
55-
"tslint": "6.1.2",
5665
"typescript": "3.9.3"
5766
},
5867
"peerDependencies": {
5968
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
6069
},
6170
"lint-staged": {
6271
"*.{ts,tsx}": [
63-
"tslint --fix",
72+
"eslint --fix",
6473
"git add"
6574
],
6675
"*.{js,json,css,md,ts,tsx}": [

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as resolvers from './resolvers';
2+
import * as mocks from './mocks';
3+
14
export {
25
DateTime as DateTimeTypeDefinition,
36
EmailAddress as EmailAddressTypeDefinition,
@@ -111,9 +114,6 @@ export {
111114
ObjectID as GraphQLObjectID,
112115
} from './resolvers';
113116

114-
import * as resolvers from './resolvers';
115-
import * as mocks from './mocks';
116-
117117
export { resolvers };
118118

119119
export {

src/mocks.ts

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,76 @@ export const ObjectID = () => '5e5677d71bdc2ae76344968c';
1212
export const PositiveFloat = () => 123.45;
1313
export const PositiveInt = () => 123;
1414
export const PostalCode = () => '60031';
15-
const URLMock = () => {
16-
// tslint:disable-next-line: no-eval
17-
let URLCtor = typeof URL === 'undefined' ? eval(`require('url')`).URL : URL;
18-
return new URLCtor('http://www.test.com/');
19-
};
15+
const URLMock = () => new URL('http://www.test.com/');
2016
// https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
21-
export const GUID = () => { // Public Domain/MIT
22-
let d = new Date().getTime();
23-
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
24-
d += performance.now(); //use high-precision timer if available
25-
}
26-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
27-
// tslint:disable-next-line: no-bitwise
28-
const r = (d + Math.random() * 16) % 16 | 0;
29-
d = Math.floor(d / 16);
30-
// tslint:disable-next-line: no-bitwise
31-
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
32-
});
17+
export const GUID = () => {
18+
// Public Domain/MIT
19+
let d = new Date().getTime();
20+
if (
21+
typeof performance !== 'undefined' &&
22+
typeof performance.now === 'function'
23+
) {
24+
d += performance.now(); // use high-precision timer if available
25+
}
26+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
27+
// tslint:disable-next-line: no-bitwise
28+
const r = (d + Math.random() * 16) % 16 | 0;
29+
d = Math.floor(d / 16);
30+
// tslint:disable-next-line: no-bitwise
31+
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
32+
});
3333
};
34-
export const HexColorCode = () => '#' + Math.floor(Math.random() * 16777215).toString(16);
35-
export const Hexadecimal = () => Math.floor(Math.random() * 16777215).toString(16);
34+
export const HexColorCode = () =>
35+
'#' + Math.floor(Math.random() * 16777215).toString(16);
36+
export const Hexadecimal = () =>
37+
Math.floor(Math.random() * 16777215).toString(16);
3638

3739
const randomVal = (min: number, max: number) => {
38-
return Math.floor(Math.random() * (max - min) + 1) + min;
40+
return Math.floor(Math.random() * (max - min) + 1) + min;
3941
};
4042
// https://codepen.io/meowwwls/pen/jbEJRp
41-
export const HSL = () => `hsl(${randomVal(0, 360)}, ${randomVal(30, 95)}%, ${randomVal(30, 80)}%)`;
42-
export const HSLA = () => `hsla(${randomVal(0, 360)}, ${randomVal(30, 95)}%, ${randomVal(30, 80)}%, ${Math.random()})`;
43+
export const HSL = () =>
44+
`hsl(${randomVal(0, 360)}, ${randomVal(30, 95)}%, ${randomVal(30, 80)}%)`;
45+
export const HSLA = () =>
46+
`hsla(${randomVal(0, 360)}, ${randomVal(30, 95)}%, ${randomVal(
47+
30,
48+
80,
49+
)}%, ${Math.random()})`;
4350

4451
// https://stackoverflow.com/questions/43464519/creating-fake-ip-address-using-javascript
45-
export const IPv4 = () => (Math.floor(Math.random() * 255) + 1) + '.' + (Math.floor(Math.random() * 255) + 0) + '.' + (Math.floor(Math.random() * 255) + 0) + '.' + (Math.floor(Math.random() * 255) + 0);
52+
export const IPv4 = () =>
53+
Math.floor(Math.random() * 255) +
54+
1 +
55+
'.' +
56+
(Math.floor(Math.random() * 255) + 0) +
57+
'.' +
58+
(Math.floor(Math.random() * 255) + 0) +
59+
'.' +
60+
(Math.floor(Math.random() * 255) + 0);
4661
export const IPv6 = () => '2001:0db8:85a3:0000:0000:8a2e:0370:7334';
4762
// http://jsfiddle.net/guest271314/qhbC9/
48-
export const MAC = () => 'XX:XX:XX:XX:XX:XX'.replace(/X/g, () => '0123456789ABCDEF'.charAt(Math.floor(Math.random() * 16)));
63+
export const MAC = () =>
64+
'XX:XX:XX:XX:XX:XX'.replace(/X/g, () =>
65+
'0123456789ABCDEF'.charAt(Math.floor(Math.random() * 16)),
66+
);
4967
export const Port = () => randomVal(0, 65535);
50-
export const RGB = () => `rgb(${randomVal(0, 255)}, ${randomVal(0, 255)}, ${randomVal(0, 255)})`;
51-
export const RGBA = () => `rgba(${randomVal(0, 255)}, ${randomVal(0, 255)}, ${randomVal(0, 255)}, ${Math.random()})`;
68+
export const RGB = () =>
69+
`rgb(${randomVal(0, 255)}, ${randomVal(0, 255)}, ${randomVal(0, 255)})`;
70+
export const RGBA = () =>
71+
`rgba(${randomVal(0, 255)}, ${randomVal(0, 255)}, ${randomVal(
72+
0,
73+
255,
74+
)}, ${Math.random()})`;
5275
export const ISBN = () => `978-3-16-148410-0`;
5376
export const USCurrency = () => 1000;
5477
export const JSON = () => ({});
5578
export const JSONObject = () => ({});
5679
export const IBAN = () => 'NL55INGB4789170233';
5780

5881
export {
59-
URLMock as URL,
60-
NonNegativeInt as UnsignedInt,
61-
NonNegativeFloat as UnsignedFloat,
62-
BigIntMock as Long,
63-
BigIntMock as BigInt,
82+
URLMock as URL,
83+
NonNegativeInt as UnsignedInt,
84+
NonNegativeFloat as UnsignedFloat,
85+
BigIntMock as Long,
86+
BigIntMock as BigInt,
6487
};

0 commit comments

Comments
 (0)