Skip to content

Commit

Permalink
Refactoring the code and Fixing Bug Risks (#10)
Browse files Browse the repository at this point in the history
* Delete locales/de.json

* Translated de.json

* ci: add .deepsource.toml

* refactor: replace template strings with regular string literals

Template literals are useful when you need:  1. [Interpolated strings](https://en.wikipedia.org/wiki/String_interpolation).

* refactor: replace short hand type conversions with function calls

Prefer using explicit casts by calling `Number`, `Boolean`, or `String` over using operators like `+`, `!!` or `"" +`. This is considered best practice as it improves readability.

* refactor: remove unnecessary boolean casts

In contexts such as an `if` statement's test where the result of the expression will already be coerced to a `Boolean`, casting to a `Boolean` via double negation (`!!`) or a `Boolean` call is unnecessary.

* refactor: fix explicit type declarations

Explicit types where they can be easily inferred may add unnecessary verbosity for variables or parameters initialized to a number, string, or boolean

* refactor: convert logical operator to optional chainining

The [optional chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) operator can be used to perform null checks before accessing a property, or calling a function.

* removed translations for de.json

* Delete .deepsource.toml

---------

Co-authored-by: deepsource-io[bot] <42547082+deepsource-io[bot]@users.noreply.github.com>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Felix <[email protected]>
Co-authored-by: Defelo <[email protected]>
  • Loading branch information
5 people authored Nov 8, 2023
1 parent 4da06c2 commit 210d1e8
Show file tree
Hide file tree
Showing 53 changed files with 150 additions and 150 deletions.
2 changes: 1 addition & 1 deletion app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
const dialog = useDialog();
function handleDialogOnBackdrop() {
return dialog.value && dialog.value.triggerPrimaryActionOnBackdropClick;
return dialog.value?.triggerPrimaryActionOnBackdropClick;
}
const user = useUser();
Expand Down
2 changes: 1 addition & 1 deletion components/Btn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default defineComponent({
? `secondary bg-transparent text-heading hover:bg-transparent border ${props.borderColor} hover:ring-4 md:hover:ring-8 hover:ring-tertiary`
: '',
props.tertiary
? `tertiary bg-transparent text-heading hover:bg-transparent hover:scale-105 border border-transparent hover:ring-4 md:hover:ring-8 hover:ring-transparent`
? "tertiary bg-transparent text-heading hover:bg-transparent hover:scale-105 border border-transparent hover:ring-4 md:hover:ring-8 hover:ring-transparent"
: '',
];
});
Expand Down
2 changes: 1 addition & 1 deletion components/Chip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default defineComponent({
'chip-color-12',
];
return !!props.color
return (props.color)
? props.color
: colors[getRandomNumber(0, colors.length - 1)];
});
Expand Down
2 changes: 1 addition & 1 deletion components/Reported-Tasks/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default {
const router = useRouter();
function onclickEditItem(item: any) {
if (!!!item || !!!item.id) return;
if (Boolean(!item) || Boolean(!item.id)) return;
const reportReason = useReportReason();
reportReason.value = item?.comment ?? "";
const reportSubtaskType = useReportSubtaskType();
Expand Down
2 changes: 1 addition & 1 deletion components/ScrollToBtn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default defineComponent({
},
setup(props) {
function onclickScrollUp() {
if (!!!props.scrollRef) return;
if (!props.scrollRef) return;
props.scrollRef.scrollIntoView({
block: "start",
behavior: "smooth",
Expand Down
6 changes: 3 additions & 3 deletions components/SectionTitle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export default defineComponent({
size: { type: String, default: 'md' },
center: { type: Boolean, default: false },
full: { type: Boolean, default: false },
heading: { type: String, default: `` },
subheading: { type: String, default: `` },
body: { type: String, default: `` },
heading: { type: String, default: "" },
subheading: { type: String, default: "" },
body: { type: String, default: "" },
sub: { type: Boolean, default: false },
noLink: { type: Boolean, default: false },
link: { default: { to: '', text: '' } },
Expand Down
2 changes: 1 addition & 1 deletion components/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default defineComponent({
function handleWindowResize() {
windowWidth.value = window?.innerWidth ?? 0;
if (
!!windowWidth.value &&
Boolean(windowWidth.value) &&
windowWidth.value > 0 &&
windowWidth.value <= 767
) {
Expand Down
2 changes: 1 addition & 1 deletion components/appUsers/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default defineComponent({
watch(
() => id.value,
async (newValue, oldValue) => {
if (!!newValue) {
if (newValue) {
const [balance, errorBalance] = await getBalanceOfThisUser(newValue);
totalCoins.value = balance?.coins ?? 0;
}
Expand Down
2 changes: 1 addition & 1 deletion components/appUsers/Progress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default defineComponent({
watch(
() => id.value,
async (newValue, oldValue) => {
if (!!newValue) {
if (newValue) {
loading.value = true;
const [success, error] = await getXPOfThisUser(newValue);
loading.value = false;
Expand Down
2 changes: 1 addition & 1 deletion components/appUsers/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export default {
const router = useRouter();
const appUser = useAppUser();
function onclickViewUser(user: any) {
if (!!!user || !!!user.id) return;
if (Boolean(!user) || Boolean(!user.id)) return;
appUser.value = user;
router.push(`/dashboard/users/${user.id}`);
Expand Down
2 changes: 1 addition & 1 deletion components/companies/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default {
const company = useCompany();
function onclickEditItem(item: any) {
if (!!!item || !!!item.id) return;
if (Boolean(!item) || Boolean(!item.id)) return;
company.value = item;
router.push(`/dashboard/companies/${item.id}`);
Expand Down
4 changes: 2 additions & 2 deletions components/form/Coins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export default defineComponent({
valid: false,
value: 0,
rules: [
(v: number) => !!v || 'Coins cannot be empty',
(v: number) => Boolean(v) || 'Coins cannot be empty',
(v: number) => v >= 0 || 'Coins cannot be less than 0',
],
},
description: {
valid: false,
value: '',
rules: [(v: number) => !!v || 'Description cannot be empty'],
rules: [(v: number) => Boolean(v) || 'Description cannot be empty'],
},
credit_note: {
valid: true,
Expand Down
8 changes: 4 additions & 4 deletions components/form/Company.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default defineComponent({
valid: false,
value: '',
rules: [
(v: string) => !!v || 'Error.InputEmpty_Inputs.CompanyName',
(v: string) => Boolean(v) || 'Error.InputEmpty_Inputs.CompanyName',
(v: string) => !v || v.length >= 3 || 'Error.InputMinLength_3',
(v: string) => v.length <= 255 || 'Error.InputMaxLength_255',
],
Expand Down Expand Up @@ -181,7 +181,7 @@ export default defineComponent({
watch(
() => props.data,
(newValue, oldValue) => {
if (!!!newValue) return;
if (!newValue) return;
form.name.value = newValue?.name ?? '';
form.description.value = newValue?.description ?? '';
form.website.value = newValue?.website ?? '';
Expand All @@ -196,7 +196,7 @@ export default defineComponent({
async function onclickSubmitForm() {
if (form.validate()) {
form.submitting = true;
const [success, error] = !!props.data
const [success, error] = (props.data)
? await editCompany(props.data.id, form.body())
: await createCompany(form.body());
form.submitting = false;
Expand All @@ -209,7 +209,7 @@ export default defineComponent({
const router = useRouter();
function successHandler(res: any) {
router.push(`/dashboard/companies`);
router.push("/dashboard/companies");
}
function errorHandler(res: any) {
Expand Down
16 changes: 8 additions & 8 deletions components/form/Job.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default defineComponent({
unit: 'MC',
per: 'task',
},
rules: [(v: any) => !!v || 'Error.InputEmpty_Inputs.ThisField'],
rules: [(v: any) => Boolean(v) || 'Error.InputEmpty_Inputs.ThisField'],
},
company_id: {
valid: true,
Expand All @@ -181,7 +181,7 @@ export default defineComponent({
valid: false,
value: '',
rules: [
(v: string) => !!v || 'Error.InputEmpty_Inputs.JobTitle',
(v: string) => Boolean(v) || 'Error.InputEmpty_Inputs.JobTitle',
(v: string) => !v || v.length >= 5 || 'Error.InputMinLength_5',
(v: string) => v.length <= 255 || 'Error.InputMaxLength_255',
],
Expand All @@ -190,7 +190,7 @@ export default defineComponent({
valid: false,
value: '',
rules: [
(v: string) => !!v || 'Error.InputEmpty_Inputs.Contact',
(v: string) => Boolean(v) || 'Error.InputEmpty_Inputs.Contact',
(v: string) => !v || v.length >= 5 || 'Error.InputMinLength_5',
(v: string) => v.length <= 255 || 'Error.InputMaxLength_255',
],
Expand All @@ -199,7 +199,7 @@ export default defineComponent({
valid: false,
value: '',
rules: [
(v: string) => !!v || 'Error.InputEmpty_Inputs.JobLocation',
(v: string) => Boolean(v) || 'Error.InputEmpty_Inputs.JobLocation',
(v: string) => v.length <= 255 || 'Error.InputMaxLength_255',
],
},
Expand Down Expand Up @@ -259,7 +259,7 @@ export default defineComponent({
valid: false,
value: '',
rules: [
(v: string) => !!v || 'Error.InputEmpty_Inputs.Description',
(v: string) => Boolean(v) || 'Error.InputEmpty_Inputs.Description',
(v: string) => v.length <= 2000 || 'Error.InputMaxLength_2000',
],
},
Expand All @@ -277,7 +277,7 @@ export default defineComponent({
value: {},
rules: [
(v: any) =>
!!form.skill_requirements.value ||
Boolean(form.skill_requirements.value) ||
'Error.InputEmpty_Inputs.SkillRequirements',
],
},
Expand Down Expand Up @@ -313,7 +313,7 @@ export default defineComponent({
watch(
() => props.data,
(newValue, oldValue) => {
if (!!!newValue) return;
if (!newValue) return;
form.company_id.value = newValue?.company?.id ?? '';
form.title.value = newValue?.title ?? '';
form.contact.value = newValue?.contact ?? '';
Expand Down Expand Up @@ -341,7 +341,7 @@ export default defineComponent({
async function onclickSubmitForm() {
if (form.validate()) {
form.submitting = true;
const [success, error] = !!props.data
const [success, error] = (props.data)
? await editJob(props.data.id, form.body())
: await createJob(form.body());
form.submitting = false;
Expand Down
12 changes: 6 additions & 6 deletions components/form/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ export default defineComponent({
valid: false,
value: '',
rules: [
(v: string) => !!v || 'Error.InputEmpty_Inputs.EmailOrUsername',
(v: string) => Boolean(v) || 'Error.InputEmpty_Inputs.EmailOrUsername',
],
},
password: {
valid: false,
value: '',
rules: [(v: string) => !!v || 'Error.InputEmpty_Inputs.Password'],
rules: [(v: string) => Boolean(v) || 'Error.InputEmpty_Inputs.Password'],
},
mfa_code: {
valid: true,
value: '',
rules: [
(v: string) => !!v || 'Error.InputEmpty_Inputs.MFACode',
(v: string) => Boolean(v) || 'Error.InputEmpty_Inputs.MFACode',
(v: string) => v.length >= 6 || 'Error.InputMinLength_6',
],
},
Expand Down Expand Up @@ -134,7 +134,7 @@ export default defineComponent({
form.submitting = false;
// checking is logged in user is admin or not
if (!!success && user.value.admin == false) {
if (Boolean(success) && user.value.admin == false) {
errorHandler({ detail: 'Error.NotAuthorized' });
setStates(null);
return;
Expand All @@ -147,7 +147,7 @@ export default defineComponent({
}
function successHandler(res: any) {
router.push(`/dashboard`);
router.push("/dashboard");
}
const needMFA = ref(false);
Expand All @@ -157,7 +157,7 @@ export default defineComponent({
let isMFA = msg == 'Error.InvalidCode';
if (!!isMFA && !!needMFA.value) {
if (Boolean(isMFA) && Boolean(needMFA.value)) {
openSnackbar('error', msg);
}
Expand Down
12 changes: 6 additions & 6 deletions components/form/Skill.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ export default defineComponent({
id: {
valid: false,
value: '',
rules: [(v: string) => !!v || 'Error.InputEmpty_Inputs.SkillID'],
rules: [(v: string) => Boolean(v) || 'Error.InputEmpty_Inputs.SkillID'],
},
name: {
valid: false,
value: '',
rules: [(v: string) => !!v || 'Error.InputEmpty_Inputs.SkillName'],
rules: [(v: string) => Boolean(v) || 'Error.InputEmpty_Inputs.SkillName'],
},
icon: {
valid: true,
Expand Down Expand Up @@ -139,10 +139,10 @@ export default defineComponent({
() => props.data,
(newValue, oldValue) => {
form.id.value = newValue?.id ?? '';
form.id.valid = !!form.id.value;
form.id.valid = Boolean(form.id.value);
form.name.value = newValue?.name ?? '';
form.name.valid = !!form.name.value;
form.name.valid = Boolean(form.name.value);
form.icon.value = newValue?.icon ?? '';
form.dependencies.value = newValue?.dependencies ?? [];
Expand All @@ -155,7 +155,7 @@ export default defineComponent({
async function onclickSubmitForm() {
if (form.validate()) {
form.submitting = true;
const [success, error] = !!props.data
const [success, error] = (props.data)
? await updateSkill(props.rootSkillID, props.subSkillID, {
...form.body(),
column: props.col,
Expand All @@ -178,7 +178,7 @@ export default defineComponent({
function onclickDeleteSkill() {
openDialog(
'warning',
`Delete Skill`,
"Delete Skill",
`Are you sure you want to delete ${
props.data?.name ?? 'this skill'
}. This action cannot be undone.`,
Expand Down
2 changes: 1 addition & 1 deletion components/form/XP.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default defineComponent({
valid: false,
value: props.subSkillXP,
rules: [
(v: number) => !!v || 'XP cannot be empty',
(v: number) => Boolean(v) || 'XP cannot be empty',
(v: number) => v >= 0 || 'XP cannot be less than 0',
],
},
Expand Down
2 changes: 1 addition & 1 deletion components/input/Btn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default defineComponent({
? `bg-transparent text-heading font-medium hover:bg-transparent border ${props.borderColor} hover:ring-8 hover:ring-tertiary`
: "",
props.tertiary
? `bg-transparent text-heading font-medium hover:bg-transparent hover:scale-105 border border-transparent hover:ring-8 hover:ring-transparent`
? "bg-transparent text-heading font-medium hover:bg-transparent hover:scale-105 border border-transparent hover:ring-8 hover:ring-transparent"
: "",
];
});
Expand Down
2 changes: 1 addition & 1 deletion components/input/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default defineComponent({
set(value) {
emit('update:modelValue', value);
error.value = value ? '' : 'This is required';
emit('valid', !!!error.value);
emit('valid', Boolean(!error.value));
},
});
Expand Down
2 changes: 1 addition & 1 deletion components/input/CheckboxGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default defineComponent({
let currentOption = props.modelValue.find(
(value) => option.value == value
);
return { ...option, selected: falseOnly ? false : !!currentOption };
return { ...option, selected: falseOnly ? false : Boolean(currentOption) };
});
Object.assign(mappedOptions, [...arr]);
}
Expand Down
6 changes: 3 additions & 3 deletions components/input/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default defineComponent({
value: '',
rules: [
(v: string) => {
if (!v && !!addToList.value) {
if (!v && Boolean(addToList.value)) {
return 'Cannot add empty string to list';
} else return true;
},
Expand All @@ -63,14 +63,14 @@ export default defineComponent({
function onclickAddToList() {
addToList.value = true;
if (!!!input.value) return;
if (!input.value) return;
let isSame = props.modelValue.find(
(item: string) =>
item.toLocaleLowerCase() == input.value.toLocaleLowerCase()
);
if (!!!isSame) {
if (!isSame) {
emit('update:modelValue', [...props.modelValue, input.value]);
}
Expand Down
Loading

0 comments on commit 210d1e8

Please sign in to comment.