NewReadability creates a new `readability`-based rule.
(_ *core.Config, generic baseCheck, path string)
| 21 | |
| 22 | // NewReadability creates a new `readability`-based rule. |
| 23 | func NewReadability(_ *core.Config, generic baseCheck, path string) (Readability, error) { |
| 24 | rule := Readability{} |
| 25 | |
| 26 | err := decodeRule(generic, &rule) |
| 27 | if err != nil { |
| 28 | return rule, readStructureError(err, path) |
| 29 | } |
| 30 | |
| 31 | if core.AllStringsInSlice(rule.Metrics, readabilityMetrics) { |
| 32 | // NOTE: This is the only extension point that doesn't support scoping. |
| 33 | // The reason for this is that we need to split on sentences to |
| 34 | // calculate readability, which means that specifying a scope smaller |
| 35 | // than a paragraph or including non-block level content (i.e., |
| 36 | // headings, list items or table cells) doesn't make sense. |
| 37 | rule.Definition.Scope = []string{"summary"} |
| 38 | } |
| 39 | |
| 40 | return rule, nil |
| 41 | } |
| 42 | |
| 43 | // Run calculates the readability level of the given text. |
| 44 | func (o Readability) Run(blk nlp.Block, _ *core.File, _ *core.Config) ([]core.Alert, error) { |
no test coverage detected
searching dependent graphs…