haroldtreen/epub-press

View on GitHub

Showing 62 of 62 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    static updateSectionsHtml(book) {
        tracker.setStatus(book.getId(), STATUS_TYPES.FETCHING_HTML);
        const sections = book.getSections();
        return new Promise((resolve) => {
            Promise.all(sections.map((section) => BookServices.updateSectionHtml(section)))
Severity: Major
Found in lib/book-services.js and 1 other location - About 4 hrs to fix
lib/book-services.js on lines 195..203

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 123.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    static convertSectionsContent(book) {
        tracker.setStatus(book.getId(), STATUS_TYPES.FORMATTING_HTML);
        const sections = book.getSections();
        return new Promise((resolve) => {
            Promise.all(sections.map((section) => BookServices.convertSectionContent(section)))
Severity: Major
Found in lib/book-services.js and 1 other location - About 4 hrs to fix
lib/book-services.js on lines 68..76

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 123.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Book has 30 functions (exceeds 20 allowed). Consider refactoring.
Open

class Book {
    static find(id, filetype) {
        return new Promise((resolve, reject) => {
            BookModel.findOne({ where: { uid: id } }).then((bookModel) => {
                if (!bookModel) {
Severity: Minor
Found in lib/book.js - About 3 hrs to fix

    HtmlProcessor has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class HtmlProcessor {
        /*
         *   Image extraction
         */
    
    
    Severity: Minor
    Found in lib/html-processor.js - About 3 hrs to fix

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

                          if (isEmail) {
                              const mailerFn = isMobi ? Mailer.sendMobi : Mailer.sendEpub;
                              return mailerFn(req.query.email, book).catch((error) => {
                                  log.warn('Book delivery failed', req.query, error);
                                  res.status(500).send('Email failed');
      Severity: Major
      Found in routes/api/books-beta.js and 1 other location - About 2 hrs to fix
      routes/api/books-beta.js on lines 168..174

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 90.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

                      .then((book) => {
                          const mailerFn = isMobi ? Mailer.sendMobi : Mailer.sendEpub;
                          return mailerFn(req.query.email, book).catch((error) => {
                              log.warn('Book delivery failed', req.query, error);
                              res.status(500).send('Email failed');
      Severity: Major
      Found in routes/api/books-beta.js and 1 other location - About 2 hrs to fix
      routes/api/books-beta.js on lines 118..124

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 90.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      File html-processor.js has 267 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      const path = require('path');
      const Url = require('url');
      
      const cheerio = require('cheerio');
      const stringDirection = require('string-direction');
      Severity: Minor
      Found in lib/html-processor.js - About 2 hrs to fix

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

        'use strict';
        
        const fs = require('fs');
        
        const shortid = require('shortid');
        Severity: Minor
        Found in lib/book.js - About 2 hrs to fix

          File book-services.js has 253 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          'use strict';
          
          const { exec } = require('child_process');
          const request = require('request-promise').defaults({ gzip: true });
          const { tidy } = require('htmltidy2');
          Severity: Minor
          Found in lib/book-services.js - About 2 hrs to fix

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                static sendMobi(email, book) {
                    const mailOptions = getMailOptions(email, book);
                    mailOptions.attachments = [{ filename: 'EpubPress.mobi', path: book.getMobiPath() }];
                    return Mailer.sendMail(mailOptions);
                }
            Severity: Major
            Found in lib/mailer.js and 1 other location - About 1 hr to fix
            lib/mailer.js on lines 44..48

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 64.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                static sendEpub(email, book) {
                    const mailOptions = getMailOptions(email, book);
                    mailOptions.attachments = [{ filename: 'EpubPress.epub', path: book.getEpubPath() }];
                    return Mailer.sendMail(mailOptions);
                }
            Severity: Major
            Found in lib/mailer.js and 1 other location - About 1 hr to fix
            lib/mailer.js on lines 38..42

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 64.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                static preprocess(html) {
                    return new Promise((resolve) => {
                        const operations = ContentExtractor.preprocess.OPERATIONS;
            
                        const preHtml = HtmlProcessor.runHtmlOperations(html, operations);
            Severity: Major
            Found in lib/content-extractor.js and 1 other location - About 1 hr to fix
            lib/content-extractor.js on lines 46..53

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 60.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                static postprocess(html) {
                    return new Promise((resolve) => {
                        const operations = ContentExtractor.postprocess.OPERATIONS;
            
                        const postHtml = HtmlProcessor.runHtmlOperations(html, operations);
            Severity: Major
            Found in lib/content-extractor.js and 1 other location - About 1 hr to fix
            lib/content-extractor.js on lines 26..33

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 60.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

                writeEpub() {
                    this._ebook = Book.getEpubWriter(this.getMetadata());
            
                    this.getSections().forEach((section) => {
                        if (section.title && section.xhtml) {
            Severity: Minor
            Found in lib/book.js - About 1 hr to fix

              Function bookFromBody has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function bookFromBody(body) {
                  return new Promise((resolve) => {
                      const sections = [];
                      if (body.urls) {
                          log.verbose('Urls request');
              Severity: Minor
              Found in routes/api/books-beta.js - About 1 hr to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                                {
                                    id: 1,
                                    title: 'Seed Book 1',
                                    sections: JSON.stringify([
                                        { title: 'Colombia', url: 'http://wikitravel.org/en/Colombia' },
                Severity: Minor
                Found in seeders/20160414000803-book-seed.js and 1 other location - About 55 mins to fix
                seeders/20160414000803-book-seed.js on lines 17..25

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 54.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                                {
                                    id: 2,
                                    title: 'Seed Book 2',
                                    sections: JSON.stringify([
                                        { title: 'Ecuador', url: 'http://wikitravel.org/en/Ecuador' },
                Severity: Minor
                Found in seeders/20160414000803-book-seed.js and 1 other location - About 55 mins to fix
                seeders/20160414000803-book-seed.js on lines 8..16

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 54.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        if (percent <= ResultsValidator.LENGTH_THRESHOLD) {
                            log.warn(`Remaining content ${percent}%`, { url: this.url });
                            return false;
                        }
                Severity: Minor
                Found in lib/results-validator.js and 1 other location - About 40 mins to fix
                lib/results-validator.js on lines 28..31

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 49.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        if (percent <= ResultsValidator.PARAGRAPH_THRESHOLD) {
                            log.warn(`Remaining paragraphs ${percent}%`, { url: this.url });
                            return false;
                        }
                Severity: Minor
                Found in lib/results-validator.js and 1 other location - About 40 mins to fix
                lib/results-validator.js on lines 16..19

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 49.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                    static replaceWithChildren(selector, html) {
                        return HtmlProcessor._proccessElements(selector, html, ($elem) => {
                            $elem.replaceWith($elem.children());
                        });
                    }
                Severity: Minor
                Found in lib/html-processor.js and 2 other locations - About 35 mins to fix
                lib/html-processor.js on lines 203..207
                lib/html-processor.js on lines 215..219

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 47.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Severity
                Category
                Status
                Source
                Language