Skip to content

Commit

Permalink
feat: add complexity sort
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Feb 13, 2025
1 parent bf19155 commit 224ea18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions website/src/catalog/RuleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const ruleMetaData = computed(() => getRuleMetaData(props.filter, sortBy.value))
<select v-model="sortBy">
<option value="name">Name</option>
<option value="lang">Lang</option>
<option value="complexity">Complexity</option>
</select>
<IconDown/>
</label>
Expand Down
8 changes: 7 additions & 1 deletion website/src/catalog/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ export function getRuleMetaData(filter: Filter, sortBy = 'name') {
}).toSorted((a, b) => {
if (sortBy === 'name') {
return a.name.localeCompare(b.name)
} else {
} else if (sortBy === 'lang') {
return a.language.localeCompare(b.language)
} else if (sortBy === 'complexity') {
const complexityA = a.rules.length + a.features.length
const complexityB = b.rules.length + b.features.length
return complexityA - complexityB
} else {
return 0
}
})
}
Expand Down

0 comments on commit 224ea18

Please sign in to comment.