nodaguti/word-quiz-generator

View on GitHub
src/quiz-generator.js

Summary

Maintainability
C
1 day
Test Coverage

File quiz-generator.js has 260 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import debug from 'debug';
import _ from 'lodash';
import RegExpPresets from './constants/regexp-presets';
import wordDivider from './constants/word-divider';
import Source from './source';
Severity: Minor
Found in src/quiz-generator.js - About 2 hrs to fix

    Function parseQuestionSentence has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    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');
    Severity: Minor
    Found in src/quiz-generator.js - About 1 hr to fix

      Function findWordIndexesWithinLemmatizedSentence has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        findWordIndexesWithinLemmatizedSentence({ lemmatizedSentence, phrase }) {
          const sentence = lemmatizedSentence;
          const phraseRegExp = this.getPhraseRegExp(phrase);
          const wordIndexes = [];
      
      
      Severity: Minor
      Found in src/quiz-generator.js - About 1 hr to fix

        Function findSentenceIncludingPhrase has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          async findSentenceIncludingPhrase({ src, phrase }) {
            const text = await src.lemmatized.getText();
            const phraseRegExp = this.getPhraseRegExp(phrase);
            const matches = [];
        
        
        Severity: Minor
        Found in src/quiz-generator.js - About 1 hr to fix

          Function quiz has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          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),
              ));
          Severity: Minor
          Found in src/quiz-generator.js - About 1 hr to fix

            Function parseQuestionSentence has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            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');
            Severity: Minor
            Found in src/quiz-generator.js - About 45 mins to fix

            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"

            Further reading

            There are no issues that match your filters.

            Category
            Status