Skip to content

Commit 05a9019

Browse files
committed
chore(Prettier): Add prettier and fix code style
1 parent 02279f8 commit 05a9019

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+708
-834
lines changed

.eslintrc

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
11
{
2-
"extends": "airbnb-base",
2+
"extends": [
3+
"airbnb-base",
4+
"prettier"
5+
],
36
"parser": "babel-eslint",
47
"rules": {
58
"no-underscore-dangle": 0,
6-
"no-unused-expressions": 0,
79
"arrow-body-style": 0,
8-
"arrow-parens": 0,
9-
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
10+
"no-unused-expressions": 0,
11+
"no-plusplus": 0,
12+
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*-test.js", "**/__mocks__/**"]}],
13+
"no-prototype-builtins": 0,
14+
"no-restricted-syntax": 0,
15+
"no-mixed-operators": 0,
1016
"comma-dangle": ["error", {
1117
"arrays": "always-multiline",
1218
"objects": "always-multiline",
1319
"imports": "always-multiline",
1420
"exports": "always-multiline",
1521
"functions": "ignore",
16-
}]
22+
}],
23+
"prettier/prettier": ["error", {
24+
"printWidth": 100,
25+
"singleQuote": true,
26+
"trailingComma": "es5",
27+
}],
28+
"import/prefer-default-export": 0,
29+
"arrow-parens": 0
1730
},
1831
"env": {
1932
"jasmine": true,
20-
"jest": true,
33+
"jest": true
2134
},
2235
"plugins": [
23-
"flowtype"
24-
]
36+
"flowtype",
37+
"prettier"
38+
],
39+
"globals": {
40+
"Class": true,
41+
"Iterator": true,
42+
"$Shape": true,
43+
}
2544
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242
"cz-conventional-changelog": "^2.0.0",
4343
"eslint": "^3.19.0",
4444
"eslint-config-airbnb-base": "^11.2.0",
45+
"eslint-config-prettier": "^2.1.1",
4546
"eslint-plugin-flowtype": "^2.34.0",
4647
"eslint-plugin-import": "^2.3.0",
48+
"eslint-plugin-prettier": "^2.1.1",
4749
"flow-bin": "^0.47.0",
4850
"graphql": "^0.10.1",
4951
"graphql-compose": "^1.19.3",
@@ -52,6 +54,7 @@
5254
"jest-babel": "^1.0.1",
5355
"mongodb-memory-server": "^1.1.1",
5456
"mongoose": "^4.10.4",
57+
"prettier": "^1.4.2",
5558
"rimraf": "^2.6.1",
5659
"semantic-release": "^6.3.6"
5760
},

src/__mocks__/contactsSchema.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { Schema } from './mongooseCommon';
22

3-
const ContactsSchema = new Schema(
4-
{
5-
phones: [String],
6-
email: String,
7-
skype: String,
8-
locationId: Schema.Types.ObjectId,
9-
}
10-
);
3+
const ContactsSchema = new Schema({
4+
phones: [String],
5+
email: String,
6+
skype: String,
7+
locationId: Schema.Types.ObjectId,
8+
});
119

1210
export default ContactsSchema;

src/__mocks__/languageSchema.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ const enumLanguageSkill = {
1515
native: { description: 'since birth' },
1616
};
1717

18-
const LanguageSchema = new Schema(
19-
{
20-
ln: {
21-
type: String,
22-
description: 'Language names (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)',
23-
enum: Object.keys(enumLanguageName),
24-
},
25-
sk: {
26-
type: String,
27-
description: 'Language skills',
28-
enum: Object.keys(enumLanguageSkill),
29-
},
30-
}
31-
);
18+
const LanguageSchema = new Schema({
19+
ln: {
20+
type: String,
21+
description: 'Language names (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)',
22+
enum: Object.keys(enumLanguageName),
23+
},
24+
sk: {
25+
type: String,
26+
description: 'Language skills',
27+
enum: Object.keys(enumLanguageSkill),
28+
},
29+
});
3230

3331
export default LanguageSchema;
3432

src/__mocks__/mongooseCommon.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/* eslint-disable no-param-reassign, no-console */
22
import mongoose, { Schema } from 'mongoose';
3-
import MongodbMemoryServer from 'mongodb-memory-server';
3+
import MongodbMemoryServer from 'mongodb-memory-server'; // eslint-disable
44

55
mongoose.Promise = Promise;
66

77
const mongoServer = new MongodbMemoryServer();
88

9-
mongoServer.getConnectionString().then((mongoUri) => {
9+
mongoServer.getConnectionString().then(mongoUri => {
1010
mongoose.connect(mongoUri);
1111

12-
mongoose.connection.on('error', (e) => {
12+
mongoose.connection.on('error', e => {
1313
if (e.message.code === 'ETIMEDOUT') {
1414
console.error(e);
1515
mongoose.connect(mongoUri);
@@ -23,7 +23,4 @@ mongoServer.getConnectionString().then((mongoUri) => {
2323
});
2424
});
2525

26-
export {
27-
mongoose,
28-
Schema,
29-
};
26+
export { mongoose, Schema };

src/__mocks__/postModel.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
import { mongoose, Schema } from './mongooseCommon';
22

3-
const PostSchema = new Schema(
4-
{
5-
_id: {
6-
type: Number,
7-
unique: true,
8-
},
9-
title: {
10-
type: String,
11-
description: 'Post title',
12-
},
3+
const PostSchema = new Schema({
4+
_id: {
5+
type: Number,
6+
unique: true,
7+
},
8+
title: {
9+
type: String,
10+
description: 'Post title',
11+
},
1312

14-
// createdAt, created via option `timastamp: true` (see bottom)
15-
// updatedAt, created via option `timastamp: true` (see bottom)
16-
}
17-
);
13+
// createdAt, created via option `timastamp: true` (see bottom)
14+
// updatedAt, created via option `timastamp: true` (see bottom)
15+
});
1816

1917
const PostModel = mongoose.model('Post', PostSchema);
2018

21-
export {
22-
PostSchema,
23-
PostModel,
24-
};
19+
export { PostSchema, PostModel };

src/__mocks__/userModel.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ const UserSchema = new Schema(
4545
},
4646

4747
employment: {
48-
type: [{
49-
type: String,
50-
enum: Object.keys(enumEmployment),
51-
}],
48+
type: [
49+
{
50+
type: String,
51+
enum: Object.keys(enumEmployment),
52+
},
53+
],
5254
description: 'List of desired employment types',
5355
index: true,
5456
},
@@ -76,7 +78,7 @@ const UserSchema = new Schema(
7678

7779
someDynamic: {
7880
type: Schema.Types.Mixed,
79-
description: 'Some mixed value, that served with @taion\'s `graphql-type-json`',
81+
description: "Some mixed value, that served with @taion's `graphql-type-json`",
8082
},
8183

8284
// createdAt, created via option `timastamp: true` (see bottom)
@@ -96,10 +98,6 @@ UserSchema.virtual('nameVirtual').get(function () { // eslint-disable-line
9698
return `VirtualFieldValue${this._id}`;
9799
});
98100

99-
100101
const UserModel = mongoose.model('User', UserSchema);
101102

102-
export {
103-
UserSchema,
104-
UserModel,
105-
};
103+
export { UserSchema, UserModel };

src/__tests__/composeWithMongoose-test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ describe('composeWithMongoose ->', () => {
3333

3434
it('should get fields from mongoose model', () => {
3535
const tc = composeWithMongoose(UserModel);
36-
expect(tc.getFieldNames()).toEqual(expect.arrayContaining(['_id', 'name', 'gender', 'age']));
36+
expect(tc.getFieldNames()).toEqual(
37+
expect.arrayContaining(['_id', 'name', 'gender', 'age'])
38+
);
3739
});
3840
});
3941

@@ -150,7 +152,9 @@ describe('composeWithMongoose ->', () => {
150152
});
151153
const resolverKeys = Array.from(tc2.getResolvers().keys());
152154
expect(resolverKeys).not.toContain('removeById');
153-
expect(resolverKeys).toEqual(expect.arrayContaining(['findMany', 'updateOne', 'updateMany']));
155+
expect(resolverKeys).toEqual(
156+
expect.arrayContaining(['findMany', 'updateOne', 'updateMany'])
157+
);
154158
});
155159
});
156160
});
@@ -179,7 +183,9 @@ describe('composeWithMongoose ->', () => {
179183
});
180184
const PersonModel = mongoose.model('Person', PersonSchema);
181185
const tc = composeWithMongoose(PersonModel);
182-
expect(tc.getFieldNames()).toEqual(expect.arrayContaining(['_id', 'name', 'spouse', 'friends']));
186+
expect(tc.getFieldNames()).toEqual(
187+
expect.arrayContaining(['_id', 'name', 'spouse', 'friends'])
188+
);
183189
});
184190
});
185191
});

src/__tests__/fieldConverter-test.js

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
/* eslint-disable no-unused-expressions, no-template-curly-in-string */
22

3-
import { GraphQLString, GraphQLFloat, GraphQLBoolean, GraphQLList, GraphQLEnumType, GraphQLSchema, GraphQLObjectType, graphql } from 'graphql';
43
import {
5-
GraphQLDate,
6-
GraphQLBuffer,
7-
GraphQLGeneric,
8-
GraphQLJSON,
9-
} from 'graphql-compose';
4+
GraphQLString,
5+
GraphQLFloat,
6+
GraphQLBoolean,
7+
GraphQLList,
8+
GraphQLEnumType,
9+
GraphQLSchema,
10+
GraphQLObjectType,
11+
graphql,
12+
} from 'graphql';
13+
import { GraphQLDate, GraphQLBuffer, GraphQLGeneric, GraphQLJSON } from 'graphql-compose';
1014
import { UserModel } from '../__mocks__/userModel';
1115
import {
1216
deriveComplexType,
@@ -39,19 +43,33 @@ describe('fieldConverter', () => {
3943
});
4044

4145
it('should throw Exception, if model does `schema.path` property', () => {
42-
expect(() => { getFieldsFromModel({ a: 1 }); }).toThrowError(/incorrect mongoose model/);
43-
expect(() => { getFieldsFromModel({ schema: {} }); }).toThrowError(/incorrect mongoose model/);
46+
expect(() => {
47+
getFieldsFromModel({ a: 1 });
48+
}).toThrowError(/incorrect mongoose model/);
49+
expect(() => {
50+
getFieldsFromModel({ schema: {} });
51+
}).toThrowError(/incorrect mongoose model/);
4452
});
4553
});
4654

4755
describe('deriveComplexType()', () => {
4856
it('should throw error on incorrect mongoose field', () => {
4957
const err = /incorrect mongoose field/;
50-
expect(() => { deriveComplexType(); }).toThrowError(err);
51-
expect(() => { deriveComplexType(123); }).toThrowError(err);
52-
expect(() => { deriveComplexType({ a: 1 }); }).toThrowError(err);
53-
expect(() => { deriveComplexType({ path: 'name' }); }).toThrowError(err);
54-
expect(() => { deriveComplexType({ path: 'name', instance: 'Abc' }); }).not.toThrowError(err);
58+
expect(() => {
59+
deriveComplexType();
60+
}).toThrowError(err);
61+
expect(() => {
62+
deriveComplexType(123);
63+
}).toThrowError(err);
64+
expect(() => {
65+
deriveComplexType({ a: 1 });
66+
}).toThrowError(err);
67+
expect(() => {
68+
deriveComplexType({ path: 'name' });
69+
}).toThrowError(err);
70+
expect(() => {
71+
deriveComplexType({ path: 'name', instance: 'Abc' });
72+
}).not.toThrowError(err);
5573
});
5674

5775
it('should derive DOCUMENT_ARRAY', () => {
@@ -174,12 +192,13 @@ describe('fieldConverter', () => {
174192
}),
175193
});
176194

177-
178195
const user = new UserModel({
179196
name: 'Test empty subDoc',
180197
});
181198
await user.save();
182-
const result = await graphql(schema, `{
199+
const result = await graphql(
200+
schema,
201+
`{
183202
user(_id: "${user._id}") {
184203
name
185204
subDoc {
@@ -189,7 +208,8 @@ describe('fieldConverter', () => {
189208
}
190209
}
191210
}
192-
}`);
211+
}`
212+
);
193213
expect(result.data.user).toEqual({
194214
name: 'Test empty subDoc',
195215
subDoc: null,
@@ -218,7 +238,9 @@ describe('fieldConverter', () => {
218238
subDoc: { field2: { field21: 'ok' } },
219239
});
220240
await user2.save();
221-
const result2 = await graphql(schema, `{
241+
const result2 = await graphql(
242+
schema,
243+
`{
222244
user(_id: "${user2._id}") {
223245
name
224246
subDoc {
@@ -228,7 +250,8 @@ describe('fieldConverter', () => {
228250
}
229251
}
230252
}
231-
}`);
253+
}`
254+
);
232255
expect(result2.data.user).toEqual({
233256
name: 'Test non empty subDoc',
234257
subDoc: {

0 commit comments

Comments
 (0)