emmercm/metalsmith-htaccess

View on GitHub

Showing 14 of 14 total issues

Function generate has a Cognitive Complexity of 79 (exceeds 5 allowed). Consider refactoring.
Open

const generate = (options) => {
  let htaccess = '';

  /* ***** Core ***** */

Severity: Minor
Found in lib/index.js - About 1 day 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 generate has 176 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const generate = (options) => {
  let htaccess = '';

  /* ***** Core ***** */

Severity: Major
Found in lib/index.js - About 7 hrs to fix

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

        if (options.core.errorDocuments && Object.keys(options.core.errorDocuments).length) {
          Object.keys(options.core.errorDocuments)
            .forEach((code) => {
              htaccess += `ErrorDocument ${code} ${options.core.errorDocuments[code]}\n`;
            });
    Severity: Major
    Found in lib/index.js and 3 other locations - About 3 hrs to fix
    lib/index.js on lines 183..188
    lib/index.js on lines 190..195
    lib/index.js on lines 197..202

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

    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 4 locations. Consider refactoring.
    Open

        if (options.mime.types && Object.keys(options.mime.types).length) {
          Object.keys(options.mime.types)
            .forEach((type) => {
              htaccess += `\tAddType ${type} ${options.mime.types[type]}\n`;
            });
    Severity: Major
    Found in lib/index.js and 3 other locations - About 3 hrs to fix
    lib/index.js on lines 46..51
    lib/index.js on lines 183..188
    lib/index.js on lines 190..195

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

    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 4 locations. Consider refactoring.
    Open

        if (options.mime.charsets && Object.keys(options.mime.charsets).length) {
          Object.keys(options.mime.charsets)
            .forEach((charset) => {
              htaccess += `\tAddCharset ${charset} ${options.mime.charsets[charset]}\n`;
            });
    Severity: Major
    Found in lib/index.js and 3 other locations - About 3 hrs to fix
    lib/index.js on lines 46..51
    lib/index.js on lines 183..188
    lib/index.js on lines 197..202

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

    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 4 locations. Consider refactoring.
    Open

        if (options.mime.languages && Object.keys(options.mime.languages).length) {
          Object.keys(options.mime.languages)
            .forEach((language) => {
              htaccess += `\tAddLanguage ${language} ${options.mime.languages[language]}\n`;
            });
    Severity: Major
    Found in lib/index.js and 3 other locations - About 3 hrs to fix
    lib/index.js on lines 46..51
    lib/index.js on lines 190..195
    lib/index.js on lines 197..202

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

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

    module.exports = (options) => {
      /**
       * Defaults are set with recommendations from the following websites:
       *  - https://htaccessbook.com/useful-htaccess-rules
       *  - https://perishablepress.com/stupid-htaccess-tricks
    Severity: Major
    Found in lib/index.js - About 2 hrs to fix

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

                  Object.keys(files)
                    .forEach((filename) => {
                      const newFilename = filename.replace(/[/\\]/g, pathSeparator);
                      if (newFilename !== filename) {
                        files[newFilename] = files[filename];
      Severity: Major
      Found in lib/index.test.js and 1 other location - About 2 hrs to fix
      lib/index.test.js on lines 40..47

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

      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

                  Object.keys(files)
                    .forEach((filename) => {
                      const newFilename = filename.replace(/[/\\]/g, properPathSeparator);
                      if (newFilename !== filename) {
                        files[newFilename] = files[filename];
      Severity: Major
      Found in lib/index.test.js and 1 other location - About 2 hrs to fix
      lib/index.test.js on lines 25..32

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

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

      'use strict';
      
      const deepmerge = require('deepmerge');
      
      const generate = (options) => {
      Severity: Minor
      Found in lib/index.js - About 2 hrs to fix

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

        const test = (dir, config) => {
          describe(dir, () => {
            // Allow src directory to not exist / be empty and not committed
            if (!existsSync(`${dir}/src`)) {
              mkdirSync(`${dir}/src`);
        Severity: Minor
        Found in lib/index.test.js - About 1 hr to fix

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

              if (options.gzip.exclude && options.gzip.exclude.length) {
                options.gzip.exclude
                  .forEach((exclude) => {
                    htaccess += `\tmod_gzip_item_exclude ${exclude}\n`;
                  });
          Severity: Major
          Found in lib/index.js and 1 other location - About 1 hr to fix
          lib/index.js on lines 142..147

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

          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 (options.gzip.include && options.gzip.include.length) {
                options.gzip.include
                  .forEach((include) => {
                    htaccess += `\tmod_gzip_item_include ${include}\n`;
                  });
          Severity: Major
          Found in lib/index.js and 1 other location - About 1 hr to fix
          lib/index.js on lines 149..154

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

          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 test has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          const test = (dir, config) => {
            describe(dir, () => {
              // Allow src directory to not exist / be empty and not committed
              if (!existsSync(`${dir}/src`)) {
                mkdirSync(`${dir}/src`);
          Severity: Minor
          Found in lib/index.test.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

          Severity
          Category
          Status
          Source
          Language