Skip to content

Commit 0c87806

Browse files
committed
Add more info to messages
1 parent 806360a commit 0c87806

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

index.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var spacheFormula = require('spache-formula')
1515

1616
module.exports = readability
1717

18-
var source = 'retext-readability'
18+
var origin = 'retext-readability:readability'
1919
var defaultTargetAge = 16
2020
var defaultWordynessThreshold = 5
2121
var defaultThreshold = 4 / 7
@@ -149,6 +149,7 @@ function report(file, node, threshold, target, results) {
149149
var index = -1
150150
var failCount = 0
151151
var confidence
152+
var label
152153
var message
153154

154155
while (++index < length) {
@@ -157,17 +158,19 @@ function report(file, node, threshold, target, results) {
157158
}
158159
}
159160

160-
if (failCount / length >= threshold) {
161-
confidence = failCount + '/' + length
161+
confidence = failCount / length
162+
163+
if (confidence >= threshold) {
164+
label = failCount + '/' + length
162165

163166
message = file.message(
164-
'Hard to read sentence (confidence: ' + confidence + ')',
167+
'Hard to read sentence (confidence: ' + label + ')',
165168
node,
166-
source
169+
origin
167170
)
168-
message.confidence = confidence
169-
message.source = source
170171
message.actual = toString(node)
171-
message.expected = null
172+
message.expected = []
173+
message.confidence = confidence
174+
message.confidenceLabel = label
172175
}
173176
}

test.js

+39
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,45 @@ var retext = require('retext')
55
var readability = require('.')
66

77
test('readability', function(t) {
8+
retext()
9+
.use(readability)
10+
.process(
11+
[
12+
'Oberon, also designated Uranus IV, is the outermost ',
13+
'major moon of the planet Uranus and quite large',
14+
'and massive for a Uranian moon.',
15+
''
16+
].join('\n'),
17+
function(err, file) {
18+
t.deepEqual(
19+
[err].concat(file.messages),
20+
[
21+
null,
22+
{
23+
message: 'Hard to read sentence (confidence: 4/7)',
24+
name: '1:1-3:32',
25+
reason: 'Hard to read sentence (confidence: 4/7)',
26+
line: 1,
27+
column: 1,
28+
location: {
29+
start: {line: 1, column: 1, offset: 0},
30+
end: {line: 3, column: 32, offset: 132}
31+
},
32+
source: 'retext-readability',
33+
ruleId: 'readability',
34+
fatal: false,
35+
actual:
36+
'Oberon, also designated Uranus IV, is the outermost \nmajor moon of the planet Uranus and quite large\nand massive for a Uranian moon.',
37+
expected: [],
38+
confidence: 4 / 7,
39+
confidenceLabel: '4/7'
40+
}
41+
],
42+
'should emit messages'
43+
)
44+
}
45+
)
46+
847
retext()
948
.use(readability)
1049
.process('The cat sat on the mat', function(err, file) {

0 commit comments

Comments
 (0)