Skip to content

Commit 0ce26d1

Browse files
committed
Change to improve message
1 parent fb76652 commit 0ce26d1

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

lib/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default function retextReadability(options) {
6060
* Nothing.
6161
*/
6262
return function (tree, file) {
63-
visit(tree, 'SentenceNode', function (sentence) {
63+
visit(tree, 'SentenceNode', function (sentence, _, parent) {
6464
/** @type {Set<string>} */
6565
const familiarWords = new Set()
6666
/** @type {Set<string>} */
@@ -142,12 +142,13 @@ export default function retextReadability(options) {
142142

143143
if (confidence >= threshold) {
144144
const message = file.message(
145-
'Hard to read sentence (confidence: ' +
146-
nok +
147-
'/' +
145+
'Unexpected hard to read sentence, according to ' +
146+
(nok < scores.length ? nok + ' out of ' : 'all ') +
148147
scores.length +
149-
')',
148+
' algorithms',
150149
{
150+
/* c8 ignore next -- verbose to test */
151+
ancestors: parent ? [parent, sentence] : [sentence],
151152
place: sentence.position,
152153
ruleId: 'readability',
153154
source: 'retext-readability'

test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ test('retext-readability', async function (t) {
2828
ancestors: [],
2929
column: 1,
3030
fatal: false,
31-
message: 'Hard to read sentence (confidence: 4/7)',
31+
message:
32+
'Unexpected hard to read sentence, according to 4 out of 7 algorithms',
3233
line: 1,
3334
name: '1:1-3:32',
3435
place: {
3536
start: {line: 1, column: 1, offset: 0},
3637
end: {line: 3, column: 32, offset: 132}
3738
},
38-
reason: 'Hard to read sentence (confidence: 4/7)',
39+
reason:
40+
'Unexpected hard to read sentence, according to 4 out of 7 algorithms',
3941
ruleId: 'readability',
4042
source: 'retext-readability',
4143
actual:
@@ -72,7 +74,7 @@ test('retext-readability', async function (t) {
7274
)
7375

7476
assert.deepEqual(file.messages.map(String), [
75-
'1:1-3:32: Hard to read sentence (confidence: 4/7)'
77+
'1:1-3:32: Unexpected hard to read sentence, according to 4 out of 7 algorithms'
7678
])
7779
}
7880
)
@@ -125,7 +127,7 @@ test('retext-readability', async function (t) {
125127
)
126128

127129
assert.deepEqual(file.messages.map(String), [
128-
'1:1-3:32: Hard to read sentence (confidence: 5/7)'
130+
'1:1-3:32: Unexpected hard to read sentence, according to 5 out of 7 algorithms'
129131
])
130132
}
131133
)
@@ -145,7 +147,7 @@ test('retext-readability', async function (t) {
145147
)
146148

147149
assert.deepEqual(file.messages.map(String), [
148-
'1:1-3:46: Hard to read sentence (confidence: 5/7)'
150+
'1:1-3:46: Unexpected hard to read sentence, according to 5 out of 7 algorithms'
149151
])
150152
}
151153
)
@@ -154,7 +156,7 @@ test('retext-readability', async function (t) {
154156
'should warn when highly confident that a sentence is hard to read',
155157
async function () {
156158
const file = await retext()
157-
.use(retextReadability, {age: 14})
159+
.use(retextReadability, {age: 6})
158160
.process(
159161
[
160162
'Oberon, also designated Uranus IV, is the outermost ',
@@ -166,7 +168,7 @@ test('retext-readability', async function (t) {
166168
)
167169

168170
assert.deepEqual(file.messages.map(String), [
169-
'1:1-4:45: Hard to read sentence (confidence: 6/7)'
171+
'1:1-4:45: Unexpected hard to read sentence, according to all 7 algorithms'
170172
])
171173
}
172174
)
@@ -185,7 +187,7 @@ test('retext-readability', async function (t) {
185187
.process('Honorificabilitudinitatibus.')
186188

187189
assert.deepEqual(file.messages.map(String), [
188-
'1:1-1:29: Hard to read sentence (confidence: 4/7)'
190+
'1:1-1:29: Unexpected hard to read sentence, according to 4 out of 7 algorithms'
189191
])
190192
})
191193
})

0 commit comments

Comments
 (0)