src/quiz-generator.js
File quiz-generator.js
has 260 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
import debug from 'debug';
import _ from 'lodash';
import RegExpPresets from './constants/regexp-presets';
import wordDivider from './constants/word-divider';
import Source from './source';
Function parseQuestionSentence
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
parseQuestionSentence({ sentence, wordIndexes }) {
// Here we assume word divider is space.
// If you are dealing with a language it is not the case (e.g. Japanese),
// firstly you have to convert a text using a preprocessor.
const tokenRegExp = new RegExp(`(${this._wordRegExp.source})(\\s*)`, 'g');
Function findWordIndexesWithinLemmatizedSentence
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
findWordIndexesWithinLemmatizedSentence({ lemmatizedSentence, phrase }) {
const sentence = lemmatizedSentence;
const phraseRegExp = this.getPhraseRegExp(phrase);
const wordIndexes = [];
Function findSentenceIncludingPhrase
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async findSentenceIncludingPhrase({ src, phrase }) {
const text = await src.lemmatized.getText();
const phraseRegExp = this.getPhraseRegExp(phrase);
const matches = [];
Function quiz
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async quiz({ sections, size }) {
const [min = 0, max] = sections.split('-').map((num) => Number(num));
const phrasesToTest = _.shuffle(this._phrases.filter((phrase) =>
_.inRange(phrase.section, min, (max || min) + 1),
));
Function parseQuestionSentence
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
parseQuestionSentence({ sentence, wordIndexes }) {
// Here we assume word divider is space.
// If you are dealing with a language it is not the case (e.g. Japanese),
// firstly you have to convert a text using a preprocessor.
const tokenRegExp = new RegExp(`(${this._wordRegExp.source})(\\s*)`, 'g');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"