Skip to content

Commit

Permalink
feat: Readability score is not out of 100 (#32)
Browse files Browse the repository at this point in the history
* Do not show score / 100 in comments

* Remove /100 from playground

* Add space in readme so that the text is bold

* Fix capitalization

---------

Co-authored-by: Chris <85164331+noon-dawg@users.noreply.github.com>
  • Loading branch information
Weetbix and noon-dawg committed Jul 26, 2023
1 parent a1feb77 commit 9c30a52
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 21 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Report a readability score for Markdown files in your pull requests, allowing yo

<details>
<summary>See example pull request comment</summary>
**Overall readability score:** 20.18/100 (🟢 +0.97)

**Overall readability score:** 20.18 (🟢 +0.97)

File | Readability
--- | ---
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

58 changes: 43 additions & 15 deletions playground/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,33 @@ const processedText = computed(() => {
return preprocessMarkdown(input.value);
});
const rawScores = computed(() => calculateReadabilityOfText(input.value));
const scores = computed(() => {
const rawScores = calculateReadabilityOfText(input.value);
return Object.entries(rawScores).map(([name, value]) => {
const {min, max} = METRIC_RANGES[name as keyof typeof METRIC_RANGES];
return {
// convert from namesLikeThis to Names Like This
name: name
.replace(/([A-Z])/g, ' $1')
.replace(/^./, (str) => str.toUpperCase()),
min,
max,
value,
description:
metricToDescription[name as keyof typeof metricToDescription],
};
});
return Object.entries(rawScores.value)
.filter(([name]) => name !== 'readabilityScore')
.map(([name, value]) => {
const {min, max} =
METRIC_RANGES[name as keyof typeof METRIC_RANGES];
return {
// convert from namesLikeThis to Names Like This
name: name
.replace(/([A-Z])/g, ' $1')
.replace(/^./, (str) => str.toUpperCase()),
min,
max,
value,
description:
metricToDescription[
name as keyof typeof metricToDescription
],
};
});
});
const readabilityScore = computed(() =>
rawScores.value.readabilityScore.toFixed(2)
);
</script>

<template>
Expand Down Expand Up @@ -70,6 +79,10 @@ const scores = computed(() => {
</div>
<div class="column size-30 auto-margin">
<div class="scores">
<div class="readability-score">
<h3>Readability score</h3>
<span>{{ readabilityScore }}</span>
</div>
<SingleScore
v-for="score in scores"
:key="score.name"
Expand Down Expand Up @@ -100,5 +113,20 @@ const scores = computed(() => {
.scores > * {
margin-bottom: 16px;
font-weight: 300;
}
.readability-score {
text-align: center;
margin-bottom: 32px;
font-weight: 100;
> h3 {
margin-bottom: 0;
}
> span {
font-size: 2rem;
}
}
</style>
3 changes: 2 additions & 1 deletion playground/src/components/SingleScore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const progress = computed(() => {
.r-icon {
margin-left: 6px;
margin-top: 3px;
width: 16px;
fill: rgba(255, 255, 255, 0.87);
fill: rgba(255, 255, 255, 0.60);
}
</style>
2 changes: 1 addition & 1 deletion src/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('reportToComment', () => {

expect(reportToComment(report)).toMatchInlineSnapshot(`
"
**Overall readability score:** 1/100 (🟢 +1)
**Overall readability score:** 1 (🟢 +1)
File | Readability
--- | ---
Expand Down
2 changes: 1 addition & 1 deletion src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const reportToComment = (
);

return `
**Overall readability score:** ${averageReadability}/100 (${averageReadabilityDiff})
**Overall readability score:** ${averageReadability} (${averageReadabilityDiff})
${readabilityTable}
Expand Down

0 comments on commit 9c30a52

Please sign in to comment.