Skip to content

Commit 0f63c63

Browse files
author
Lionel Bijaoui
committed
Improve Codacy score
1 parent ac27bf3 commit 0f63c63

File tree

7 files changed

+59
-40
lines changed

7 files changed

+59
-40
lines changed

dev/projects/full/app.vue

+12-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export default {
8484
8585
computed: {
8686
validationErrors() {
87-
if (this.$refs.form && this.$refs.form.errors) return this.$refs.form.errors;
87+
if (this.$refs.form && this.$refs.form.errors) {
88+
return this.$refs.form.errors;
89+
}
8890
8991
return [];
9092
}
@@ -187,7 +189,9 @@ export default {
187189
let id = 0;
188190
189191
each(this.rows, (row) => {
190-
if (row.id > id) id = row.id;
192+
if (row.id > id) {
193+
id = row.id;
194+
}
191195
});
192196
193197
return ++id;
@@ -206,8 +210,12 @@ export default {
206210
getLocation(model) {
207211
if (navigator.geolocation) {
208212
navigator.geolocation.getCurrentPosition((pos) => {
209-
if (!model.address) model.address = {};
210-
if (!model.address.geo) model.address.geo = {};
213+
if (!model.address) {
214+
model.address = {};
215+
}
216+
if (!model.address.geo) {
217+
model.address.geo = {};
218+
}
211219
model.address.geo.latitude = pos.coords.latitude.toFixed(5);
212220
model.address.geo.longitude = pos.coords.longitude.toFixed(5);
213221
});

dev/projects/full/data.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import fecha from "fecha";
33

44
let fakerator = new Fakerator();
55

6-
let roles = [{ id: "admin", name: "Administrator" }, { id: "moderator", name: "Moderator" }, { id: "user", name: "Registered User" }, { id: "visitor", name: "Visitor" }];
6+
let roles = [
7+
{ id: "admin", name: "Administrator" },
8+
{ id: "moderator", name: "Moderator" },
9+
{ id: "user", name: "Registered User" },
10+
{ id: "visitor", name: "Visitor" }
11+
];
712

813
let skills = ["HTML5", "Javascript", "CSS3", "CoffeeScript", "AngularJS", "ReactJS", "VueJS"];
914

@@ -34,7 +39,9 @@ let users = (function() {
3439
user.favoriteColor = "#" + fakerator.internet.color();
3540
user.color = "#" + fakerator.internet.color();
3641

37-
if (user.type === "business") user.company = fakerator.entity.company();
42+
if (user.type === "business") {
43+
user.company = fakerator.entity.company();
44+
}
3845

3946
user.income = [fakerator.random.number(50000), fakerator.random.number(50000, 100000)];
4047

dev/projects/full/schema.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export default {
5151
console.log(`Model's name changed from ${oldVal} to ${newVal}. Model:`, model);
5252
},
5353
onValidated(model, errors) {
54-
if (errors.length > 0) console.warn("Validation error in Name field! Errors:", errors);
54+
if (errors.length > 0) {
55+
console.warn("Validation error in Name field! Errors:", errors);
56+
}
5557
}
5658
},
5759
{
@@ -434,25 +436,29 @@ export default {
434436
let values = val.split(",");
435437
if (!model.address) model.address = {};
436438
if (!model.address.geo) model.address.geo = {};
437-
if (values.length > 0 && values[0].trim() !== "")
439+
if (values.length > 0 && values[0].trim() !== "") {
438440
model.address.geo.latitude = parseFloat(values[0].trim());
439-
else model.address.geo.latitude = 0;
440-
if (values.length > 1 && values[1].trim() !== "")
441+
} else {
442+
model.address.geo.latitude = 0;
443+
}
444+
if (values.length > 1 && values[1].trim() !== "") {
441445
model.address.geo.longitude = parseFloat(values[1].trim());
442-
else model.address.geo.longitude = 0;
446+
} else {
447+
model.address.geo.longitude = 0;
448+
}
443449
},
444450
buttons: [
445451
{
446452
classes: "btn-location",
447453
label: "Current location",
448-
onclick: function(model) {
454+
onclick(model) {
449455
return this.$parent.getLocation(model);
450456
}
451457
},
452458
{
453459
classes: "btn-clear",
454460
label: "Clear",
455-
onclick: function(model) {
461+
onclick(model) {
456462
model.address.geo = {
457463
latitude: 0,
458464
longitude: 0

src/formElement.vue

+7-16
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,15 @@ export default {
6565
},
6666
// Should field type have a label?
6767
fieldTypeHasLabel() {
68-
if (isNil(this.field.label)) return false;
69-
70-
let relevantType = "";
71-
let fieldOptions = this.getValueFromOption(this.field, "fieldOptions");
72-
if (this.field.type === "input" && !isNil(fieldOptions)) {
73-
relevantType = fieldOptions.inputType;
74-
} else {
75-
relevantType = this.field.type;
68+
if (isNil(this.field.label)) {
69+
return false;
7670
}
71+
let fieldOptions = this.getValueFromOption(this.field, "fieldOptions");
72+
let condition = this.field.type === "input" && !isNil(fieldOptions);
73+
let relevantType = condition ? fieldOptions.inputType : this.field.type;
74+
const typeWithoutLabel = ["button", "submit", "reset"];
7775
78-
switch (relevantType) {
79-
case "button":
80-
case "submit":
81-
case "reset":
82-
return false;
83-
default:
84-
return true;
85-
}
76+
return !typeWithoutLabel.includes(relevantType);
8677
},
8778
fieldHasHint() {
8879
return !isNil(this.field.hint);

src/formGenerator.vue

+7-6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default {
7878
tag: {
7979
type: String,
8080
default: "fieldset",
81-
validator: function(value) {
81+
validator(value) {
8282
return value.length > 0;
8383
}
8484
}
@@ -87,7 +87,7 @@ export default {
8787
data() {
8888
const eventBus = new Vue();
8989
return {
90-
eventBus: eventBus,
90+
eventBus,
9191
totalNumberOfFields: 0,
9292
errors: [] // Validation errors
9393
};
@@ -105,9 +105,10 @@ export default {
105105
// new model loaded
106106
model: {
107107
handler(newModel, oldModel) {
108-
if (oldModel === newModel)
108+
if (oldModel === newModel) {
109109
// model property changed, skip
110110
return;
111+
}
111112
112113
if (newModel != null) {
113114
this.$nextTick(() => {
@@ -131,8 +132,8 @@ export default {
131132
if (isArray(fieldErrors) && fieldErrors.length > 0) {
132133
fieldErrors.forEach((error) => {
133134
errors.push({
134-
uid: uid,
135-
error: error
135+
uid,
136+
error
136137
});
137138
});
138139
}
@@ -163,7 +164,7 @@ export default {
163164
let formErrors = [];
164165
165166
this.eventBus.$on("field-deregistering", () => {
166-
console.warn("Fields were deleted during validation process");
167+
// console.warn("Fields were deleted during validation process");
167168
this.eventBus.$emit("fields-validation-terminated", formErrors);
168169
reject(formErrors);
169170
});

src/formGroup.vue

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
tag: {
3232
type: String,
3333
default: "fieldset",
34-
validator: function(value) {
34+
validator(value) {
3535
return value.length > 0;
3636
}
3737
},
@@ -74,9 +74,13 @@ export default {
7474
methods: {
7575
// Get visible prop of field
7676
fieldVisible(field) {
77-
if (isFunction(field.visible)) return field.visible.call(this, this.model, field, this);
77+
if (isFunction(field.visible)) {
78+
return field.visible.call(this, this.model, field, this);
79+
}
7880
79-
if (isNil(field.visible)) return true;
81+
if (isNil(field.visible)) {
82+
return true;
83+
}
8084
8185
return field.visible;
8286
},

src/utils/validators.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ const validators = {
6363

6464
number(value, field, model, messages = resources) {
6565
let res = checkEmpty(value, field.required, messages);
66-
if (res != null) return res;
66+
if (res != null) {
67+
return res;
68+
}
6769

6870
let err = [];
6971
if (isNumber(value)) {
@@ -226,7 +228,7 @@ const validators = {
226228
if (shouldDouble) {
227229
tmpNum *= 2;
228230
if (tmpNum >= 10) {
229-
sum += tmpNum % 10 + 1;
231+
sum += (tmpNum % 10) + 1;
230232
} else {
231233
sum += tmpNum;
232234
}

0 commit comments

Comments
 (0)