nodaguti/word-quiz-generator

View on GitHub

Showing 20 of 30 total issues

Function default has 125 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default async function (args) {
  const argv = minimist(args, {
    string: [
      'material',
      'sources',
Severity: Major
Found in src/commands/coverage.js - About 5 hrs to fix

    Function lemmatize has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    async function lemmatize(sentence) {
      const result = await processWithCoreNLP(sentence);
      const coreNLPToken = result.document.sentences.sentence.tokens.token;
      const tokens = Array.isArray(coreNLPToken) ? coreNLPToken : [coreNLPToken];
      const lemmatized = tokens.map((token, i) => {
    Severity: Minor
    Found in src/lemmatizers/en.js - About 3 hrs 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

    Function default has 86 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export default async function (args) {
      const argv = minimist(args, {
        string: [
          'material',
          'sources',
    Severity: Major
    Found in src/commands/generate.js - About 3 hrs to fix

      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 lemmatize has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        async function lemmatize(sentence) {
          const result = await processWithCoreNLP(sentence);
          const coreNLPToken = result.document.sentences.sentence.tokens.token;
          const tokens = Array.isArray(coreNLPToken) ? coreNLPToken : [coreNLPToken];
          const lemmatized = tokens.map((token, i) => {
        Severity: Minor
        Found in src/lemmatizers/en.js - About 2 hrs to fix

          Function default has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export default async function (args) {
            const argv = minimist(args, {
              string: [
                'src',
                'lang',
          Severity: Minor
          Found in src/commands/make.js - About 1 hr to fix

            Function lemmatized has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              const lemmatized = tokens.map((token, i) => {
                let shouldSpaced = true;
                let lemma;
            
                switch (token.POS) {
            Severity: Minor
            Found in src/lemmatizers/en.js - About 1 hr 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 default has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                Open

                export default async function (args) {
                  const argv = minimist(args, {
                    string: [
                      'material',
                      'sources',
                Severity: Minor
                Found in src/commands/coverage.js - About 1 hr 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

                Function showUsage has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                const showUsage = () => {
                  console.log(
                `word-quiz-generator coverage --help
                word-quiz-generator coverage --material=<path> --sources=<paths> [--lang]
                                             [--show-details] [--show-lemma]
                Severity: Minor
                Found in src/commands/coverage.js - About 1 hr to fix

                  Function showUsage has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  const showUsage = () => {
                    console.log(
                  `word-quiz-generator generate --help
                  word-quiz-generator generate --material=<path> --sources=<paths> --sections --size
                                               [--instruction] [--lang] [--sentenceSeparator=<RegExp>]
                  Severity: Minor
                  Found in src/commands/generate.js - About 1 hr to fix

                    Function default has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export default async function (text) {
                      // ---- Remove annotations
                      const textWithoutAnnotations = removeAnnotations(text);
                    
                      const emended = textWithoutAnnotations
                    Severity: Minor
                    Found in src/preprocessors/ojp.js - About 1 hr to fix

                      Function removeAnnotations has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function removeAnnotations(text) {
                        /**
                         * Remove a string between `left` and `right` using recursive RegExp.
                         * @param {string} str a target string
                         * @param {string} left left delimiter
                      Severity: Minor
                      Found in src/preprocessors/ojp.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 default has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                            export default async function (text) {
                              // ---- Remove annotations
                              const textWithoutAnnotations = removeAnnotations(text);
                            
                              const emended = textWithoutAnnotations
                            Severity: Minor
                            Found in src/preprocessors/ojp.js - About 1 hr 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

                            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

                              Function default has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                              Open

                              export default async function (text) {
                                const paragraphs = text.replace(/ /g, '').split(/\n/);
                              
                                const lemmatizedParagraphs = paragraphs.map((paragraph) => (async () => {
                                  const sentences = paragraph.split('。');
                              Severity: Minor
                              Found in src/lemmatizers/ojp.js - About 35 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

                              Function fetchFileList has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                              Open

                              export const fetchFileList = (paths, pattern = /(?:)/) =>
                                Promise.all(
                                  paths.split(',').map((p) => (async () => {
                                    const ap = path.resolve(p);
                                    const stat = await fs.statAsync(ap);
                              Severity: Minor
                              Found in src/utils.js - About 35 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

                              Severity
                              Category
                              Status
                              Source
                              Language