jeresig/pharos-images

View on GitHub

Showing 451 of 451 total issues

Function exports has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = (app) => {
    const Upload = models("Upload");
    const UploadImage = models("UploadImage");

    const genTmpFile = () => path.join(os.tmpdir(),
Severity: Minor
Found in logic/uploads.js - About 4 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

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

    image.updateSimilarity((err) => {
        t.error(err, "No error should be thrown.");
        t.notEqual(image.similarImages, oldSimilar,
            "Similarity updated.");
        t.equal(image.similarImages.length, 1,
Severity: Major
Found in tests/schemas/UploadImage.js and 2 other locations - About 4 hrs to fix
tests/schemas/Image.js on lines 45..54
tests/schemas/UploadImage.js on lines 49..59

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 116.

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

    image.updateSimilarity((err) => {
        t.error(err, "No error should be thrown.");
        t.notEqual(image.similarImages, oldSimilar,
            "Similarity updated.");
        t.equal(image.similarImages.length, 1,
Severity: Major
Found in tests/schemas/UploadImage.js and 2 other locations - About 4 hrs to fix
tests/schemas/Image.js on lines 45..54
tests/schemas/UploadImage.js on lines 65..75

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 116.

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

    image.updateSimilarity((err) => {
        t.error(err, "No error should be thrown.");
        t.notEqual(image.similarImages, oldSimilar, "Similarity updated.");
        t.equal(image.similarImages.length, 1,
            "Has the correct number of results.");
Severity: Major
Found in tests/schemas/Image.js and 2 other locations - About 4 hrs to fix
tests/schemas/UploadImage.js on lines 49..59
tests/schemas/UploadImage.js on lines 65..75

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 116.

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 ImageImport.js has 334 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"use strict";

const path = require("path");

const tap = require("tap");
Severity: Minor
Found in tests/schemas/ImageImport.js - About 4 hrs to fix

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

        t.same(Artwork.lintData({
            id: "1234",
            source: "nga",
            lang: "en",
            url: "http://google.com",
    Severity: Major
    Found in tests/schemas/Artwork.js and 1 other location - About 4 hrs to fix
    tests/schemas/Artwork.js on lines 824..836

    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 115.

    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

        t.same(Artwork.lintData({
            id: "1234",
            source: "nga",
            lang: "en",
            url: "http://google.com",
    Severity: Major
    Found in tests/schemas/Artwork.js and 1 other location - About 4 hrs to fix
    tests/schemas/Artwork.js on lines 854..866

    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 115.

    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 admin.js has 333 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    "use strict";
    
    const fs = require("fs");
    const path = require("path");
    
    
    Severity: Minor
    Found in tests/logic/admin.js - About 4 hrs to fix

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

      tap.test("uploadData: Source not found", (t) => {
          adminLogin(() => {
              const url = "http://localhost:3000/source/foo/upload-data";
              const formData = {};
              request.post({url, formData}, (err, res) => {
      Severity: Major
      Found in tests/logic/admin.js and 1 other location - About 3 hrs to fix
      tests/logic/admin.js on lines 266..276

      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 113.

      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

      tap.test("uploadImages: Source not found", (t) => {
          adminLogin(() => {
              const url = "http://localhost:3000/source/foo/upload-images";
              const formData = {};
              request.post({url, formData}, (err, res) => {
      Severity: Major
      Found in tests/logic/admin.js and 1 other location - About 3 hrs to fix
      tests/logic/admin.js on lines 193..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 113.

      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

      tap.test("UploadImage.fromFile: New UploadImage (Small File)", (t) => {
          const testFile = path.resolve(process.cwd(), "testData", "small.jpg");
      
          UploadImage.fromFile(testFile, (err, image) => {
              t.ok(err, "Has error object.");
      Severity: Major
      Found in tests/schemas/UploadImage.js and 2 other locations - About 3 hrs to fix
      tests/schemas/UploadImage.js on lines 90..99
      tests/schemas/UploadImage.js on lines 101..110

      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 112.

      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

      tap.test("UploadImage.fromFile: New UploadImage (Empty File)", (t) => {
          const testFile = path.resolve(process.cwd(), "testData", "empty.jpg");
      
          UploadImage.fromFile(testFile, (err, image) => {
              t.ok(err, "Has error object.");
      Severity: Major
      Found in tests/schemas/UploadImage.js and 2 other locations - About 3 hrs to fix
      tests/schemas/UploadImage.js on lines 101..110
      tests/schemas/UploadImage.js on lines 112..121

      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 112.

      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

      tap.test("UploadImage.fromFile: New UploadImage (Corrupted File)", (t) => {
          const testFile = path.resolve(process.cwd(), "testData", "corrupted.jpg");
      
          UploadImage.fromFile(testFile, (err, image) => {
              t.ok(err, "Has error object.");
      Severity: Major
      Found in tests/schemas/UploadImage.js and 2 other locations - About 3 hrs to fix
      tests/schemas/UploadImage.js on lines 90..99
      tests/schemas/UploadImage.js on lines 112..121

      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 112.

      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

      tap.test("saveState", (t) => {
          const batch = init.getArtworkBatch();
          batch.saveState("process.started", () => {
              const state = batch.getCurState();
              t.equal(state.id, "process.started", "Get State ID");
      Severity: Major
      Found in tests/schemas/ArtworkImport.js and 1 other location - About 3 hrs to fix
      tests/schemas/ImageImport.js on lines 44..52

      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 111.

      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

      tap.test("saveState", (t) => {
          const batch = init.getBatch();
          batch.saveState("process.started", () => {
              const state = batch.getCurState();
              t.equal(state.id, "process.started", "Get State ID");
      Severity: Major
      Found in tests/schemas/ImageImport.js and 1 other location - About 3 hrs to fix
      tests/schemas/ArtworkImport.js on lines 61..69

      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 111.

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

          lintData(data, req, optionalSchema) {
              const schema = optionalSchema || Artwork;
      
              const cleaned = {};
              const warnings = [];
      Severity: Major
      Found in schemas/Artwork.js - About 3 hrs to fix

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

                return <tr key={batch._id}>
                    <td><a href={this.props.URL(batch)}>{batch.fileName}</a></td>
                    <td>{this.props.relativeDate(batch.modified)}</td>
                    {columns}
                </tr>;
        Severity: Major
        Found in views/Admin.jsx and 1 other location - About 3 hrs to fix
        views/Admin.jsx on lines 116..120

        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 109.

        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

                return <tr key={batch._id}>
                    <td><a href={this.props.URL(batch)}>{batch.fileName}</a></td>
                    <td>{this.props.relativeDate(batch.modified)}</td>
                    {columns}
                </tr>;
        Severity: Major
        Found in views/Admin.jsx and 1 other location - About 3 hrs to fix
        views/Admin.jsx on lines 225..229

        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 109.

        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

        tap.test("Upload No Image From URL", (t) => {
            const uploadURL = encodeURIComponent("http://");
            const url = `http://localhost:3000/url-upload?url=${uploadURL}`;
        
            request.get({
        Severity: Major
        Found in tests/logic/uploads.js and 1 other location - About 3 hrs to fix
        tests/logic/uploads.js on lines 119..130

        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 108.

        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

        tap.test("Upload Missing Image From URL", (t) => {
            const uploadURL = encodeURIComponent("http://localhost:3000/foo.jpg");
            const url = `http://localhost:3000/url-upload?url=${uploadURL}`;
        
            request.get({
        Severity: Major
        Found in tests/logic/uploads.js and 1 other location - About 3 hrs to fix
        tests/logic/uploads.js on lines 106..117

        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 108.

        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