1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 14:23:32 +00:00

[SM-265] Add eslint rule forbidding get().value (#3671)

This commit is contained in:
Oscar Hinton
2022-10-04 15:40:00 +02:00
committed by GitHub
parent 9ca877a7be
commit b153ed6d01
7 changed files with 25 additions and 23 deletions

View File

@@ -73,6 +73,10 @@
{ {
"message": "Calling `svgIcon` directly is not allowed", "message": "Calling `svgIcon` directly is not allowed",
"selector": "CallExpression[callee.name='svgIcon']" "selector": "CallExpression[callee.name='svgIcon']"
},
{
"message": "Accessing FormGroup using `get` is not allowed, use `.value` instead",
"selector": "ChainExpression[expression.object.callee.property.name='get'][expression.property.name='value']"
} }
], ],
"curly": ["error", "all"], "curly": ["error", "all"],

View File

@@ -135,7 +135,7 @@ export class LoginComponent extends BaseLoginComponent {
} }
async goAfterLogIn() { async goAfterLogIn() {
const masterPassword = this.formGroup.get("masterPassword")?.value; const masterPassword = this.formGroup.value.masterPassword;
// Check master password against policy // Check master password against policy
if (this.enforcedPasswordPolicyOptions != null) { if (this.enforcedPasswordPolicyOptions != null) {
@@ -170,7 +170,7 @@ export class LoginComponent extends BaseLoginComponent {
} }
async submit() { async submit() {
const rememberEmail = this.formGroup.get("rememberEmail")?.value; const rememberEmail = this.formGroup.value.rememberEmail;
await this.stateService.setRememberEmail(rememberEmail); await this.stateService.setRememberEmail(rememberEmail);
if (!rememberEmail) { if (!rememberEmail) {
@@ -192,7 +192,7 @@ export class LoginComponent extends BaseLoginComponent {
} }
private getPasswordStrengthUserInput() { private getPasswordStrengthUserInput() {
const email = this.formGroup.get("email")?.value; const email = this.formGroup.value.email;
let userInput: string[] = []; let userInput: string[] = [];
const atPosition = email.indexOf("@"); const atPosition = email.indexOf("@");
if (atPosition > -1) { if (atPosition > -1) {

View File

@@ -73,7 +73,7 @@ export class RegisterFormComponent extends BaseRegisterComponent {
this.enforcedPolicyOptions != null && this.enforcedPolicyOptions != null &&
!this.policyService.evaluateMasterPassword( !this.policyService.evaluateMasterPassword(
this.passwordStrengthResult.score, this.passwordStrengthResult.score,
this.formGroup.get("masterPassword")?.value, this.formGroup.value.masterPassword,
this.enforcedPolicyOptions this.enforcedPolicyOptions
) )
) { ) {

View File

@@ -57,8 +57,8 @@ export class BillingComponent extends OrganizationPlansComponent {
async ngOnInit() { async ngOnInit() {
const additionalSeats = this.product == ProductType.Families ? 0 : 1; const additionalSeats = this.product == ProductType.Families ? 0 : 1;
this.formGroup.patchValue({ this.formGroup.patchValue({
name: this.orgInfoForm.get("name")?.value, name: this.orgInfoForm.value.name,
billingEmail: this.orgInfoForm.get("email")?.value, billingEmail: this.orgInfoForm.value.email,
additionalSeats: additionalSeats, additionalSeats: additionalSeats,
plan: this.plan, plan: this.plan,
product: this.product, product: this.product,

View File

@@ -65,7 +65,7 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
} }
async ngOnInit() { async ngOnInit() {
let email = this.formGroup.get("email")?.value; let email = this.formGroup.value.email;
if (email == null || email === "") { if (email == null || email === "") {
email = await this.stateService.getRememberedEmail(); email = await this.stateService.getRememberedEmail();
this.formGroup.get("email")?.setValue(email); this.formGroup.get("email")?.setValue(email);
@@ -81,9 +81,7 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
} }
async submit(showToast = true) { async submit(showToast = true) {
const email = this.formGroup.get("email")?.value; const data = this.formGroup.value;
const masterPassword = this.formGroup.get("masterPassword")?.value;
const rememberEmail = this.formGroup.get("rememberEmail")?.value;
await this.setupCaptcha(); await this.setupCaptcha();
@@ -103,15 +101,15 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
try { try {
const credentials = new PasswordLogInCredentials( const credentials = new PasswordLogInCredentials(
email, data.email,
masterPassword, data.masterPassword,
this.captchaToken, this.captchaToken,
null null
); );
this.formPromise = this.authService.logIn(credentials); this.formPromise = this.authService.logIn(credentials);
const response = await this.formPromise; const response = await this.formPromise;
if (rememberEmail || this.alwaysRememberEmail) { if (data.rememberEmail || this.alwaysRememberEmail) {
await this.stateService.setRememberedEmail(email); await this.stateService.setRememberedEmail(data.email);
} else { } else {
await this.stateService.setRememberedEmail(null); await this.stateService.setRememberedEmail(null);
} }
@@ -216,7 +214,7 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
} }
protected focusInput() { protected focusInput() {
const email = this.formGroup.get("email")?.value; const email = this.formGroup.value.email;
document.getElementById(email == null || email === "" ? "email" : "masterPassword").focus(); document.getElementById(email == null || email === "" ? "email" : "masterPassword").focus();
} }
} }

View File

@@ -96,11 +96,11 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
} }
async submit(showToast = true) { async submit(showToast = true) {
let email = this.formGroup.get("email")?.value; let email = this.formGroup.value.email;
email = email.trim().toLowerCase(); email = email.trim().toLowerCase();
let name = this.formGroup.get("name")?.value; let name = this.formGroup.value.name;
name = name === "" ? null : name; // Why do we do this? name = name === "" ? null : name; // Why do we do this?
const masterPassword = this.formGroup.get("masterPassword")?.value; const masterPassword = this.formGroup.value.masterPassword;
try { try {
if (!this.accountCreated) { if (!this.accountCreated) {
const registerResponse = await this.registerAccount( const registerResponse = await this.registerAccount(
@@ -125,7 +125,7 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
if (loginResponse.captchaRequired) { if (loginResponse.captchaRequired) {
return; return;
} }
this.createdAccount.emit(this.formGroup.get("email")?.value); this.createdAccount.emit(this.formGroup.value.email);
} else { } else {
this.platformUtilsService.showToast( this.platformUtilsService.showToast(
"success", "success",
@@ -232,7 +232,7 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
masterPassword: string, masterPassword: string,
name: string name: string
): Promise<RegisterRequest> { ): Promise<RegisterRequest> {
const hint = this.formGroup.get("hint")?.value; const hint = this.formGroup.value.hint;
const kdf = DEFAULT_KDF_TYPE; const kdf = DEFAULT_KDF_TYPE;
const kdfIterations = DEFAULT_KDF_ITERATIONS; const kdfIterations = DEFAULT_KDF_ITERATIONS;
const key = await this.cryptoService.makeKey(masterPassword, email, kdf, kdfIterations); const key = await this.cryptoService.makeKey(masterPassword, email, kdf, kdfIterations);

View File

@@ -2,7 +2,7 @@ import { Directive, Input, OnInit } from "@angular/core";
import { import {
AbstractControl, AbstractControl,
ControlValueAccessor, ControlValueAccessor,
UntypedFormBuilder, FormBuilder,
ValidationErrors, ValidationErrors,
Validator, Validator,
} from "@angular/forms"; } from "@angular/forms";
@@ -44,7 +44,7 @@ export class VaultTimeoutInputComponent implements ControlValueAccessor, Validat
private validatorChange: () => void; private validatorChange: () => void;
constructor( constructor(
private formBuilder: UntypedFormBuilder, private formBuilder: FormBuilder,
private policyService: PolicyService, private policyService: PolicyService,
private i18nService: I18nService private i18nService: I18nService
) {} ) {}
@@ -152,6 +152,6 @@ export class VaultTimeoutInputComponent implements ControlValueAccessor, Validat
} }
private customTimeInMinutes() { private customTimeInMinutes() {
return this.form.get("custom.hours")?.value * 60 + this.form.get("custom.minutes")?.value; return this.form.value.custom.hours * 60 + this.form.value.custom.minutes;
} }
} }