Skip to content

Commit dfd5a8e

Browse files
authored
ci: Add lint rule for mandatory curly braces (#9348)
1 parent 714acaa commit dfd5a8e

22 files changed

+145
-137
lines changed

.eslintrc.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"space-infix-ops": "error",
2626
"no-useless-escape": "off",
2727
"require-atomic-updates": "off",
28-
"object-curly-spacing": ["error", "always"]
28+
"object-curly-spacing": ["error", "always"],
29+
"curly": ["error", "all"],
30+
"block-spacing": ["error", "always"]
2931
},
3032
"globals": {
3133
"Parse": true

spec/support/MockLdapServer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function newServer(port, dn, provokeSearchError = false, ssl = false) {
1111

1212
server.bind('o=example', function (req, res, next) {
1313
if (req.dn.toString() !== dn || req.credentials !== 'secret')
14-
return next(new ldapjs.InvalidCredentialsError());
14+
{ return next(new ldapjs.InvalidCredentialsError()); }
1515
res.end();
1616
return next();
1717
});

src/Adapters/Auth/OAuth1Client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ OAuth.nonce = function () {
122122
var text = '';
123123
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
124124

125-
for (var i = 0; i < 30; i++) text += possible.charAt(Math.floor(Math.random() * possible.length));
125+
for (var i = 0; i < 30; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); }
126126

127127
return text;
128128
};

src/Adapters/Auth/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ module.exports = function (authOptions = {}, enableAnonymousUsers = true) {
215215
return { validator: undefined };
216216
}
217217
const authAdapter = loadAuthAdapter(provider, authOptions);
218-
if (!authAdapter) return;
218+
if (!authAdapter) { return; }
219219
const { adapter, appIds, providerOptions } = authAdapter;
220220
return { validator: authDataValidator(provider, adapter, appIds, providerOptions), adapter };
221221
};

src/Adapters/Auth/keycloak.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ const { Parse } = require('parse/node');
3737
const httpsRequest = require('./httpsRequest');
3838

3939
const arraysEqual = (_arr1, _arr2) => {
40-
if (!Array.isArray(_arr1) || !Array.isArray(_arr2) || _arr1.length !== _arr2.length) return false;
40+
if (!Array.isArray(_arr1) || !Array.isArray(_arr2) || _arr1.length !== _arr2.length) { return false; }
4141

4242
var arr1 = _arr1.concat().sort();
4343
var arr2 = _arr2.concat().sort();
4444

4545
for (var i = 0; i < arr1.length; i++) {
46-
if (arr1[i] !== arr2[i]) return false;
46+
if (arr1[i] !== arr2[i]) { return false; }
4747
}
4848

4949
return true;

src/Auth.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,11 @@ const findUsersWithAuthData = (config, authData) => {
434434
};
435435

436436
const hasMutatedAuthData = (authData, userAuthData) => {
437-
if (!userAuthData) return { hasMutatedAuthData: true, mutatedAuthData: authData };
437+
if (!userAuthData) { return { hasMutatedAuthData: true, mutatedAuthData: authData }; }
438438
const mutatedAuthData = {};
439439
Object.keys(authData).forEach(provider => {
440440
// Anonymous provider is not handled this way
441-
if (provider === 'anonymous') return;
441+
if (provider === 'anonymous') { return; }
442442
const providerData = authData[provider];
443443
const userProviderAuthData = userAuthData[provider];
444444
if (!isDeepStrictEqual(providerData, userProviderAuthData)) {

src/Config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class Config {
139139
}
140140

141141
static validateCustomPages(customPages) {
142-
if (!customPages) return;
142+
if (!customPages) { return; }
143143

144144
if (Object.prototype.toString.call(customPages) !== '[object Object]') {
145145
throw Error('Parse Server option customPages must be an object.');
@@ -209,7 +209,7 @@ export class Config {
209209
}
210210

211211
static validateSchemaOptions(schema: SchemaOptions) {
212-
if (!schema) return;
212+
if (!schema) { return; }
213213
if (Object.prototype.toString.call(schema) !== '[object Object]') {
214214
throw 'Parse Server option schema must be an object.';
215215
}

src/Controllers/DatabaseController.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const filterSensitiveData = (
142142
object: any
143143
) => {
144144
let userId = null;
145-
if (auth && auth.user) userId = auth.user.id;
145+
if (auth && auth.user) { userId = auth.user.id; }
146146

147147
// replace protectedFields when using pointer-permissions
148148
const perms =
@@ -1592,12 +1592,12 @@ class DatabaseController {
15921592
schema && schema.getClassLevelPermissions
15931593
? schema.getClassLevelPermissions(className)
15941594
: schema;
1595-
if (!perms) return null;
1595+
if (!perms) { return null; }
15961596

15971597
const protectedFields = perms.protectedFields;
1598-
if (!protectedFields) return null;
1598+
if (!protectedFields) { return null; }
15991599

1600-
if (aclGroup.indexOf(query.objectId) > -1) return null;
1600+
if (aclGroup.indexOf(query.objectId) > -1) { return null; }
16011601

16021602
// for queries where "keys" are set and do not include all 'userField':{field},
16031603
// we have to transparently include it, and then remove before returning to client

src/Controllers/SchemaController.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,10 @@ const VolatileClassesSchemas = [
666666
];
667667

668668
const dbTypeMatchesObjectType = (dbType: SchemaField | string, objectType: SchemaField) => {
669-
if (dbType.type !== objectType.type) return false;
670-
if (dbType.targetClass !== objectType.targetClass) return false;
671-
if (dbType === objectType.type) return true;
672-
if (dbType.type === objectType.type) return true;
669+
if (dbType.type !== objectType.type) { return false; }
670+
if (dbType.targetClass !== objectType.targetClass) { return false; }
671+
if (dbType === objectType.type) { return true; }
672+
if (dbType.type === objectType.type) { return true; }
673673
return false;
674674
};
675675

@@ -1020,7 +1020,7 @@ export default class SchemaController {
10201020
}
10211021
const fieldType = fields[fieldName];
10221022
const error = fieldTypeIsInvalid(fieldType);
1023-
if (error) return { code: error.code, error: error.message };
1023+
if (error) { return { code: error.code, error: error.message }; }
10241024
if (fieldType.defaultValue !== undefined) {
10251025
let defaultValueType = getType(fieldType.defaultValue);
10261026
if (typeof defaultValueType === 'string') {

src/Controllers/UserController.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class UserController extends AdaptableController {
122122
if (expiresDate && expiresDate.__type == 'Date') {
123123
expiresDate = new Date(expiresDate.iso);
124124
}
125-
if (expiresDate < new Date()) throw 'The password reset link has expired';
125+
if (expiresDate < new Date()) { throw 'The password reset link has expired'; }
126126
}
127127
return results[0];
128128
});

src/GraphQL/loaders/parseClassMutations.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseG
7676
mutateAndGetPayload: async (args, context, mutationInfo) => {
7777
try {
7878
let { fields } = deepcopy(args);
79-
if (!fields) fields = {};
79+
if (!fields) { fields = {}; }
8080
const { config, auth, info } = context;
8181

8282
const parseFields = await transformTypes('create', fields, {
@@ -179,7 +179,7 @@ const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseG
179179
mutateAndGetPayload: async (args, context, mutationInfo) => {
180180
try {
181181
let { id, fields } = deepcopy(args);
182-
if (!fields) fields = {};
182+
if (!fields) { fields = {}; }
183183
const { config, auth, info } = context;
184184

185185
const globalIdObject = fromGlobalId(id);

src/GraphQL/loaders/parseClassTypes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ const load = (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLCla
453453
description: `Use Inline Fragment on Array to get results: https://graphql.org/learn/queries/#inline-fragments`,
454454
type: parseClass.fields[field].required ? new GraphQLNonNull(type) : type,
455455
async resolve(source) {
456-
if (!source[field]) return null;
456+
if (!source[field]) { return null; }
457457
return source[field].map(async elem => {
458458
if (elem.className && elem.objectId && elem.__type === 'Object') {
459459
return elem;

src/GraphQL/loaders/usersMutations.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const load = parseGraphQLSchema => {
5757
'viewer.user.',
5858
objectId
5959
);
60-
if (authDataResponse && viewer.user) viewer.user.authDataResponse = authDataResponse;
60+
if (authDataResponse && viewer.user) { viewer.user.authDataResponse = authDataResponse; }
6161
return {
6262
viewer,
6363
};
@@ -134,7 +134,7 @@ const load = parseGraphQLSchema => {
134134
'viewer.user.',
135135
objectId
136136
);
137-
if (authDataResponse && viewer.user) viewer.user.authDataResponse = authDataResponse;
137+
if (authDataResponse && viewer.user) { viewer.user.authDataResponse = authDataResponse; }
138138
return {
139139
viewer,
140140
};
@@ -198,7 +198,7 @@ const load = parseGraphQLSchema => {
198198
'viewer.user.',
199199
objectId
200200
);
201-
if (authDataResponse && viewer.user) viewer.user.authDataResponse = authDataResponse;
201+
if (authDataResponse && viewer.user) { viewer.user.authDataResponse = authDataResponse; }
202202
return {
203203
viewer,
204204
};

src/GraphQL/parseGraphQLUtils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const extractKeysAndInclude = selectedFields => {
2323
selectedFields = selectedFields.filter(field => !field.includes('__typename'));
2424
// Handles "id" field for both current and included objects
2525
selectedFields = selectedFields.map(field => {
26-
if (field === 'id') return 'objectId';
26+
if (field === 'id') { return 'objectId'; }
2727
return field.endsWith('.id')
2828
? `${field.substring(0, field.lastIndexOf('.id'))}.objectId`
2929
: field;

src/GraphQL/transformers/mutation.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const transformTypes = async (
8282
}
8383
});
8484
await Promise.all(promises);
85-
if (fields.ACL) fields.ACL = transformers.ACL(fields.ACL);
85+
if (fields.ACL) { fields.ACL = transformers.ACL(fields.ACL); }
8686
}
8787
return fields;
8888
};
@@ -148,10 +148,10 @@ const transformers = {
148148
{ config, auth, info }
149149
) => {
150150
if (Object.keys(value).length === 0)
151-
throw new Parse.Error(
152-
Parse.Error.INVALID_POINTER,
153-
`You need to provide at least one operation on the relation mutation of field ${field}`
154-
);
151+
{ throw new Parse.Error(
152+
Parse.Error.INVALID_POINTER,
153+
`You need to provide at least one operation on the relation mutation of field ${field}`
154+
); }
155155

156156
const op = {
157157
__op: 'Batch',
@@ -180,7 +180,7 @@ const transformers = {
180180
}
181181

182182
if (value.add || nestedObjectsToAdd.length > 0) {
183-
if (!value.add) value.add = [];
183+
if (!value.add) { value.add = []; }
184184
value.add = value.add.map(input => {
185185
const globalIdObject = fromGlobalId(input);
186186
if (globalIdObject.type === targetClass) {
@@ -225,10 +225,10 @@ const transformers = {
225225
{ config, auth, info }
226226
) => {
227227
if (Object.keys(value).length > 1 || Object.keys(value).length === 0)
228-
throw new Parse.Error(
229-
Parse.Error.INVALID_POINTER,
230-
`You need to provide link OR createLink on the pointer mutation of field ${field}`
231-
);
228+
{ throw new Parse.Error(
229+
Parse.Error.INVALID_POINTER,
230+
`You need to provide link OR createLink on the pointer mutation of field ${field}`
231+
); }
232232

233233
let nestedObjectToAdd;
234234
if (value.createAndLink) {

src/ParseServer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ParseServer {
8888
if (!Object.prototype.hasOwnProperty.call(ref, key)) {
8989
result.push(prefix + key);
9090
} else {
91-
if (ref[key] === '') continue;
91+
if (ref[key] === '') { continue; }
9292
let res = [];
9393
if (Array.isArray(original[key]) && Array.isArray(ref[key])) {
9494
const type = ref[key][0];

src/RestWrite.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ RestWrite.prototype.ensureUniqueAuthDataId = async function () {
505505
key => this.data.authData[key] && this.data.authData[key].id
506506
);
507507

508-
if (!hasAuthDataId) return;
508+
if (!hasAuthDataId) { return; }
509509

510510
const r = await Auth.findUsersWithAuthData(this.config, this.data.authData);
511511
const results = this.filteredObjectsByACL(r);
@@ -810,7 +810,7 @@ RestWrite.prototype._validateEmail = function () {
810810
};
811811

812812
RestWrite.prototype._validatePasswordPolicy = function () {
813-
if (!this.config.passwordPolicy) return Promise.resolve();
813+
if (!this.config.passwordPolicy) { return Promise.resolve(); }
814814
return this._validatePasswordRequirements().then(() => {
815815
return this._validatePasswordHistory();
816816
});
@@ -845,17 +845,17 @@ RestWrite.prototype._validatePasswordRequirements = function () {
845845
if (this.data.username) {
846846
// username is not passed during password reset
847847
if (this.data.password.indexOf(this.data.username) >= 0)
848-
return Promise.reject(new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError));
848+
{ return Promise.reject(new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError)); }
849849
} else {
850850
// retrieve the User object using objectId during password reset
851851
return this.config.database.find('_User', { objectId: this.objectId() }).then(results => {
852852
if (results.length != 1) {
853853
throw undefined;
854854
}
855855
if (this.data.password.indexOf(results[0].username) >= 0)
856-
return Promise.reject(
857-
new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError)
858-
);
856+
{ return Promise.reject(
857+
new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError)
858+
); }
859859
return Promise.resolve();
860860
});
861861
}
@@ -880,18 +880,18 @@ RestWrite.prototype._validatePasswordHistory = function () {
880880
const user = results[0];
881881
let oldPasswords = [];
882882
if (user._password_history)
883-
oldPasswords = _.take(
884-
user._password_history,
885-
this.config.passwordPolicy.maxPasswordHistory - 1
886-
);
883+
{ oldPasswords = _.take(
884+
user._password_history,
885+
this.config.passwordPolicy.maxPasswordHistory - 1
886+
); }
887887
oldPasswords.push(user.password);
888888
const newPassword = this.data.password;
889889
// compare the new password hash with all old password hashes
890890
const promises = oldPasswords.map(function (hash) {
891891
return passwordCrypto.compare(newPassword, hash).then(result => {
892892
if (result)
893-
// reject if there is a match
894-
return Promise.reject('REPEAT_PASSWORD');
893+
// reject if there is a match
894+
{ return Promise.reject('REPEAT_PASSWORD'); }
895895
return Promise.resolve();
896896
});
897897
});
@@ -902,13 +902,13 @@ RestWrite.prototype._validatePasswordHistory = function () {
902902
})
903903
.catch(err => {
904904
if (err === 'REPEAT_PASSWORD')
905-
// a match was found
906-
return Promise.reject(
907-
new Parse.Error(
908-
Parse.Error.VALIDATION_ERROR,
909-
`New password should not be the same as last ${this.config.passwordPolicy.maxPasswordHistory} passwords.`
910-
)
911-
);
905+
// a match was found
906+
{ return Promise.reject(
907+
new Parse.Error(
908+
Parse.Error.VALIDATION_ERROR,
909+
`New password should not be the same as last ${this.config.passwordPolicy.maxPasswordHistory} passwords.`
910+
)
911+
); }
912912
throw err;
913913
});
914914
});

src/Routers/UsersRouter.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ export class UsersRouter extends ClassesRouter {
253253
changedAt.getTime() + 86400000 * req.config.passwordPolicy.maxPasswordAge
254254
);
255255
if (expiresAt < new Date())
256-
// fail of current time is past password expiry time
257-
throw new Parse.Error(
258-
Parse.Error.OBJECT_NOT_FOUND,
259-
'Your password has expired. Please reset your password.'
260-
);
256+
// fail of current time is past password expiry time
257+
{ throw new Parse.Error(
258+
Parse.Error.OBJECT_NOT_FOUND,
259+
'Your password has expired. Please reset your password.'
260+
); }
261261
}
262262
}
263263

0 commit comments

Comments
 (0)