Skip to content

Commit 6a3d9eb

Browse files
authored
Merge pull request Yoast#22832 from Yoast/2604-analysis-error-in-classic-editor
Excludes empty sentences from the analysis of consecutive sentences assessment
2 parents cd10e8f + 01b5a6a commit 6a3d9eb

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

packages/yoastseo/spec/languageProcessing/researches/getSentenceBeginningsSpec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ describe( "gets the sentence beginnings and the count of consecutive duplicates.
152152
expect( getSentenceBeginnings( mockPaper, researcher )[ 2 ].count ).toBe( 1 );
153153
} );
154154

155+
it( "excludes sentences that contains only shortcodes", function() {
156+
mockPaper = new Paper( "[shortcode]. [shortcode]. [shortcode]. First sentence.", { shortcodes: [ "shortcode" ] } );
157+
researcher = new EnglishResearcher( mockPaper );
158+
buildTree( mockPaper, researcher );
159+
const sentenceBeginnings = getSentenceBeginnings( mockPaper, researcher );
160+
expect( sentenceBeginnings ).toHaveLength( 1 );
161+
expect( getSentenceBeginnings( mockPaper, researcher )[ 0 ].word ).toBe( "first" );
162+
} );
163+
155164
it( "returns an object with English sentence beginnings with paragraph tags - it should match over paragraphs", function() {
156165
mockPaper = new Paper( "<p>Sentence 1. Sentence 2.</p><p>Sentence 3.</p>" );
157166
researcher = new EnglishResearcher( mockPaper );

packages/yoastseo/src/languageProcessing/researches/getSentenceBeginnings.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ export default ( paper, researcher ) => {
9797
let tree = cloneDeep( paper.getTree() );
9898
tree = filterTree( tree, additionalFilters );
9999

100-
// Get all sentences from the tree, and find their sentence beginnings.
101-
const sentences = getSentencesFromTree( tree );
100+
// Get all sentences from the tree that contain tokens.
101+
const sentences = getSentencesFromTree( tree ).filter( sentence => sentence.tokens.length > 0 );
102+
// Get the sentence beginnings.
102103
const sentenceBeginnings = sentences.map( sentence => getSentenceBeginning( sentence, firstWordExceptions, secondWordExceptions ) );
103104

104105
// Turn the sentence beginnings into an array that combines sentences beginning with the same word(s).

0 commit comments

Comments
 (0)