Skip to content

Commit

Permalink
ci: Add lint rule for mandatory curly braces (#9348)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrezza authored Oct 16, 2024
1 parent 714acaa commit dfd5a8e
Show file tree
Hide file tree
Showing 22 changed files with 145 additions and 137 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"space-infix-ops": "error",
"no-useless-escape": "off",
"require-atomic-updates": "off",
"object-curly-spacing": ["error", "always"]
"object-curly-spacing": ["error", "always"],
"curly": ["error", "all"],
"block-spacing": ["error", "always"]
},
"globals": {
"Parse": true
Expand Down
2 changes: 1 addition & 1 deletion spec/support/MockLdapServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function newServer(port, dn, provokeSearchError = false, ssl = false) {

server.bind('o=example', function (req, res, next) {
if (req.dn.toString() !== dn || req.credentials !== 'secret')
return next(new ldapjs.InvalidCredentialsError());
{ return next(new ldapjs.InvalidCredentialsError()); }
res.end();
return next();
});
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/Auth/OAuth1Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ OAuth.nonce = function () {
var text = '';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

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

return text;
};
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/Auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ module.exports = function (authOptions = {}, enableAnonymousUsers = true) {
return { validator: undefined };
}
const authAdapter = loadAuthAdapter(provider, authOptions);
if (!authAdapter) return;
if (!authAdapter) { return; }
const { adapter, appIds, providerOptions } = authAdapter;
return { validator: authDataValidator(provider, adapter, appIds, providerOptions), adapter };
};
Expand Down
4 changes: 2 additions & 2 deletions src/Adapters/Auth/keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ const { Parse } = require('parse/node');
const httpsRequest = require('./httpsRequest');

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

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

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

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,11 @@ const findUsersWithAuthData = (config, authData) => {
};

const hasMutatedAuthData = (authData, userAuthData) => {
if (!userAuthData) return { hasMutatedAuthData: true, mutatedAuthData: authData };
if (!userAuthData) { return { hasMutatedAuthData: true, mutatedAuthData: authData }; }
const mutatedAuthData = {};
Object.keys(authData).forEach(provider => {
// Anonymous provider is not handled this way
if (provider === 'anonymous') return;
if (provider === 'anonymous') { return; }
const providerData = authData[provider];
const userProviderAuthData = userAuthData[provider];
if (!isDeepStrictEqual(providerData, userProviderAuthData)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class Config {
}

static validateCustomPages(customPages) {
if (!customPages) return;
if (!customPages) { return; }

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

static validateSchemaOptions(schema: SchemaOptions) {
if (!schema) return;
if (!schema) { return; }
if (Object.prototype.toString.call(schema) !== '[object Object]') {
throw 'Parse Server option schema must be an object.';
}
Expand Down
8 changes: 4 additions & 4 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const filterSensitiveData = (
object: any
) => {
let userId = null;
if (auth && auth.user) userId = auth.user.id;
if (auth && auth.user) { userId = auth.user.id; }

// replace protectedFields when using pointer-permissions
const perms =
Expand Down Expand Up @@ -1592,12 +1592,12 @@ class DatabaseController {
schema && schema.getClassLevelPermissions
? schema.getClassLevelPermissions(className)
: schema;
if (!perms) return null;
if (!perms) { return null; }

const protectedFields = perms.protectedFields;
if (!protectedFields) return null;
if (!protectedFields) { return null; }

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

// for queries where "keys" are set and do not include all 'userField':{field},
// we have to transparently include it, and then remove before returning to client
Expand Down
10 changes: 5 additions & 5 deletions src/Controllers/SchemaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,10 @@ const VolatileClassesSchemas = [
];

const dbTypeMatchesObjectType = (dbType: SchemaField | string, objectType: SchemaField) => {
if (dbType.type !== objectType.type) return false;
if (dbType.targetClass !== objectType.targetClass) return false;
if (dbType === objectType.type) return true;
if (dbType.type === objectType.type) return true;
if (dbType.type !== objectType.type) { return false; }
if (dbType.targetClass !== objectType.targetClass) { return false; }
if (dbType === objectType.type) { return true; }
if (dbType.type === objectType.type) { return true; }
return false;
};

Expand Down Expand Up @@ -1020,7 +1020,7 @@ export default class SchemaController {
}
const fieldType = fields[fieldName];
const error = fieldTypeIsInvalid(fieldType);
if (error) return { code: error.code, error: error.message };
if (error) { return { code: error.code, error: error.message }; }
if (fieldType.defaultValue !== undefined) {
let defaultValueType = getType(fieldType.defaultValue);
if (typeof defaultValueType === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class UserController extends AdaptableController {
if (expiresDate && expiresDate.__type == 'Date') {
expiresDate = new Date(expiresDate.iso);
}
if (expiresDate < new Date()) throw 'The password reset link has expired';
if (expiresDate < new Date()) { throw 'The password reset link has expired'; }
}
return results[0];
});
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL/loaders/parseClassMutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseG
mutateAndGetPayload: async (args, context, mutationInfo) => {
try {
let { fields } = deepcopy(args);
if (!fields) fields = {};
if (!fields) { fields = {}; }
const { config, auth, info } = context;

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

const globalIdObject = fromGlobalId(id);
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/loaders/parseClassTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ const load = (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLCla
description: `Use Inline Fragment on Array to get results: https://graphql.org/learn/queries/#inline-fragments`,
type: parseClass.fields[field].required ? new GraphQLNonNull(type) : type,
async resolve(source) {
if (!source[field]) return null;
if (!source[field]) { return null; }
return source[field].map(async elem => {
if (elem.className && elem.objectId && elem.__type === 'Object') {
return elem;
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQL/loaders/usersMutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const load = parseGraphQLSchema => {
'viewer.user.',
objectId
);
if (authDataResponse && viewer.user) viewer.user.authDataResponse = authDataResponse;
if (authDataResponse && viewer.user) { viewer.user.authDataResponse = authDataResponse; }
return {
viewer,
};
Expand Down Expand Up @@ -134,7 +134,7 @@ const load = parseGraphQLSchema => {
'viewer.user.',
objectId
);
if (authDataResponse && viewer.user) viewer.user.authDataResponse = authDataResponse;
if (authDataResponse && viewer.user) { viewer.user.authDataResponse = authDataResponse; }
return {
viewer,
};
Expand Down Expand Up @@ -198,7 +198,7 @@ const load = parseGraphQLSchema => {
'viewer.user.',
objectId
);
if (authDataResponse && viewer.user) viewer.user.authDataResponse = authDataResponse;
if (authDataResponse && viewer.user) { viewer.user.authDataResponse = authDataResponse; }
return {
viewer,
};
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/parseGraphQLUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const extractKeysAndInclude = selectedFields => {
selectedFields = selectedFields.filter(field => !field.includes('__typename'));
// Handles "id" field for both current and included objects
selectedFields = selectedFields.map(field => {
if (field === 'id') return 'objectId';
if (field === 'id') { return 'objectId'; }
return field.endsWith('.id')
? `${field.substring(0, field.lastIndexOf('.id'))}.objectId`
: field;
Expand Down
20 changes: 10 additions & 10 deletions src/GraphQL/transformers/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const transformTypes = async (
}
});
await Promise.all(promises);
if (fields.ACL) fields.ACL = transformers.ACL(fields.ACL);
if (fields.ACL) { fields.ACL = transformers.ACL(fields.ACL); }
}
return fields;
};
Expand Down Expand Up @@ -148,10 +148,10 @@ const transformers = {
{ config, auth, info }
) => {
if (Object.keys(value).length === 0)
throw new Parse.Error(
Parse.Error.INVALID_POINTER,
`You need to provide at least one operation on the relation mutation of field ${field}`
);
{ throw new Parse.Error(
Parse.Error.INVALID_POINTER,
`You need to provide at least one operation on the relation mutation of field ${field}`
); }

const op = {
__op: 'Batch',
Expand Down Expand Up @@ -180,7 +180,7 @@ const transformers = {
}

if (value.add || nestedObjectsToAdd.length > 0) {
if (!value.add) value.add = [];
if (!value.add) { value.add = []; }
value.add = value.add.map(input => {
const globalIdObject = fromGlobalId(input);
if (globalIdObject.type === targetClass) {
Expand Down Expand Up @@ -225,10 +225,10 @@ const transformers = {
{ config, auth, info }
) => {
if (Object.keys(value).length > 1 || Object.keys(value).length === 0)
throw new Parse.Error(
Parse.Error.INVALID_POINTER,
`You need to provide link OR createLink on the pointer mutation of field ${field}`
);
{ throw new Parse.Error(
Parse.Error.INVALID_POINTER,
`You need to provide link OR createLink on the pointer mutation of field ${field}`
); }

let nestedObjectToAdd;
if (value.createAndLink) {
Expand Down
2 changes: 1 addition & 1 deletion src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ParseServer {
if (!Object.prototype.hasOwnProperty.call(ref, key)) {
result.push(prefix + key);
} else {
if (ref[key] === '') continue;
if (ref[key] === '') { continue; }
let res = [];
if (Array.isArray(original[key]) && Array.isArray(ref[key])) {
const type = ref[key][0];
Expand Down
38 changes: 19 additions & 19 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ RestWrite.prototype.ensureUniqueAuthDataId = async function () {
key => this.data.authData[key] && this.data.authData[key].id
);

if (!hasAuthDataId) return;
if (!hasAuthDataId) { return; }

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

RestWrite.prototype._validatePasswordPolicy = function () {
if (!this.config.passwordPolicy) return Promise.resolve();
if (!this.config.passwordPolicy) { return Promise.resolve(); }
return this._validatePasswordRequirements().then(() => {
return this._validatePasswordHistory();
});
Expand Down Expand Up @@ -845,17 +845,17 @@ RestWrite.prototype._validatePasswordRequirements = function () {
if (this.data.username) {
// username is not passed during password reset
if (this.data.password.indexOf(this.data.username) >= 0)
return Promise.reject(new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError));
{ return Promise.reject(new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError)); }
} else {
// retrieve the User object using objectId during password reset
return this.config.database.find('_User', { objectId: this.objectId() }).then(results => {
if (results.length != 1) {
throw undefined;
}
if (this.data.password.indexOf(results[0].username) >= 0)
return Promise.reject(
new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError)
);
{ return Promise.reject(
new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError)
); }
return Promise.resolve();
});
}
Expand All @@ -880,18 +880,18 @@ RestWrite.prototype._validatePasswordHistory = function () {
const user = results[0];
let oldPasswords = [];
if (user._password_history)
oldPasswords = _.take(
user._password_history,
this.config.passwordPolicy.maxPasswordHistory - 1
);
{ oldPasswords = _.take(
user._password_history,
this.config.passwordPolicy.maxPasswordHistory - 1
); }
oldPasswords.push(user.password);
const newPassword = this.data.password;
// compare the new password hash with all old password hashes
const promises = oldPasswords.map(function (hash) {
return passwordCrypto.compare(newPassword, hash).then(result => {
if (result)
// reject if there is a match
return Promise.reject('REPEAT_PASSWORD');
// reject if there is a match
{ return Promise.reject('REPEAT_PASSWORD'); }
return Promise.resolve();
});
});
Expand All @@ -902,13 +902,13 @@ RestWrite.prototype._validatePasswordHistory = function () {
})
.catch(err => {
if (err === 'REPEAT_PASSWORD')
// a match was found
return Promise.reject(
new Parse.Error(
Parse.Error.VALIDATION_ERROR,
`New password should not be the same as last ${this.config.passwordPolicy.maxPasswordHistory} passwords.`
)
);
// a match was found
{ return Promise.reject(
new Parse.Error(
Parse.Error.VALIDATION_ERROR,
`New password should not be the same as last ${this.config.passwordPolicy.maxPasswordHistory} passwords.`
)
); }
throw err;
});
});
Expand Down
10 changes: 5 additions & 5 deletions src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ export class UsersRouter extends ClassesRouter {
changedAt.getTime() + 86400000 * req.config.passwordPolicy.maxPasswordAge
);
if (expiresAt < new Date())
// fail of current time is past password expiry time
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Your password has expired. Please reset your password.'
);
// fail of current time is past password expiry time
{ throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Your password has expired. Please reset your password.'
); }
}
}

Expand Down
Loading

0 comments on commit dfd5a8e

Please sign in to comment.