Fixed linting issues and comments.

This commit is contained in:
Dries Cruyskens 2020-05-30 03:20:50 +02:00
parent 136e83afc2
commit 43a3b57dd9
3 changed files with 24 additions and 18 deletions

View File

@ -156,7 +156,7 @@ describe('PostSlug', () => {
{ id: 'Bw' },
{ id: 'a' },
]
wrapper = await Wrapper()
})
@ -167,16 +167,16 @@ describe('PostSlug', () => {
it('are alphabetically ordered', async () => {
// Get all HcHastag components
let wrappers = wrapper.findAll(HcHashtag).wrappers
const wrappers = wrapper.findAll(HcHashtag).wrappers
// Exctract ID properties (tag names) from component.
let ids = []
const ids = []
wrappers.forEach((x) => {
ids.push({
id: x.props().id,
})
})
// Compare extracted IDs with solution.
let idsAlphabetically = [
const idsAlphabetically = [
{ id: '42' },
{ id: 'a' },
{ id: 'BQ' },

View File

@ -182,13 +182,16 @@ export default {
sortedTags() {
// Make sure the property is valid.
if (!this.post.tags || !this.post.tags.length) return false
// Sorting actually happens in place but that should not be a problem.
return this.post.tags.sort(function (a, b) {
// Converting to lowercase to make sort case insensitive.
const tagA = a.id.toLowerCase()
const tagB = b.id.toLowerCase()
return tagA < tagB ? -1 : tagA > tagB ? 1 : 0
})
/* Using .slice(0) to make a shallow copy. Otherwise a vue/no-side-effects-in-computed-properties error
would be thrown because sort() sorts in place. A shallow copy is fine because only first level objects are
affected by the sort, the original this.post.tags object remains unchanged.
*/
return this.post.tags.slice(0).sort(function (a, b) {
// Converting to lowercase to make sort case insensitive.
const tagA = a.id.toLowerCase()
const tagB = b.id.toLowerCase()
return tagA < tagB ? -1 : tagA > tagB ? 1 : 0
})
},
},
methods: {

View File

@ -65,13 +65,16 @@ export default {
sortedTags() {
// Make sure the property is valid.
if (!this.post.tags || !this.post.tags.length) return false
// Sorting actually happens in place but that should not be a problem.
return this.post.tags.sort(function (a, b) {
// Converting to lowercase to make sort case insensitive.
const tagA = a.id.toLowerCase()
const tagB = b.id.toLowerCase()
return tagA < tagB ? -1 : tagA > tagB ? 1 : 0
})
/* Using .slice(0) to make a shallow copy. Otherwise a vue/no-side-effects-in-computed-properties error
would be thrown because sort() sorts in place. A shallow copy is fine because only first level objects are
affected by the sort, the original this.post.tags object remains unchanged.
*/
return this.post.tags.slice(0).sort(function (a, b) {
// Converting to lowercase to make sort case insensitive.
const tagA = a.id.toLowerCase()
const tagB = b.id.toLowerCase()
return tagA < tagB ? -1 : tagA > tagB ? 1 : 0
})
},
},
methods: {