Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow condition statement to not require brace when they are single-line #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Aetherall
Copy link
Member

Will allow:

validateConfiguration(config: Configuration): void {
    if(!config) throw new Error('configuration object is required')
    if(!config.required) throw new Error('required property is required')
    if(!config.required) throw new Error('required property is required')
}

insteadof:

validateConfiguration(config: Configuration): void {
    if(!config) {
        throw new Error('configuration object is required')
    }
    if(!config.required) {
        throw new Error('required property is required')
    }
    if(!config.required) {
        throw new Error('required property is required')
    }
}

@pradel
Copy link
Member

pradel commented Mar 11, 2018

I personaly prefer with curly braces

@Aetherall
Copy link
Member Author

Okay @pradel, for simple cases like this it could reduce the number of lines while keeping the meaning clear, do you not agree ?

@pradel
Copy link
Member

pradel commented Mar 11, 2018

I agree for a simple use case like this but the problem is this will disallow the rule for all cases

@Aetherall
Copy link
Member Author

I mean, single-lined statements are quite often simple use cases IMO

private async useService( req: any, res: any): Promise <void> {

		const connectionInfo: ConnectionInformations = getConnectionInfo(req);

		// Identify the service
		const target: any = req.params;

		// Extract the action parameters
		const params: any = req.body;

		const { tokens, ...response } : any = await this.accountsServer.useService(target, params, connectionInfo)

		if(tokens) this.tokenTransport.setTokens(tokens, { req, res });

		this.send(res, response);
	}


public async middleware( req: any, res: any, next: () => void ): Promise <void> {

		// Retrieve access token
		const accessToken: string | null = this.tokenTransport.getAccessToken(req);
		
		if(!accessToken) return next() // If no accessToken from client => do nothing

		// If there is an accessToken provided by client => try to resume session
		const result: UserSafe | AccountsError = await this.accountsServer.resumeSession(accessToken);

		if(result instanceof AccountsError) return next();

		// Assign result of session resuming to request object 
		req.user = result;
		req.userId = result.id;

		next();
		
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants