patrickarlt/acetate

View on GitHub

Showing 21 of 27 total issues

File Acetate.js has 636 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const EventEmitter = require("events").EventEmitter;
const chokidar = require("chokidar");
const path = require("path");
const fs = require("fs");
const _ = require("lodash");
Severity: Major
Found in lib/Acetate.js - About 1 day to fix

    Function createServer has 158 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function createServer(acetate, options = {}) {
      function notFoundMiddleware(request, response) {
        acetate.log.warn(`404 not found ${url.parse(request.url).pathname}`);
        response.writeHead(404, { "Content-Type": "text/html" });
        response.end(notFoundPageTemplate);
    Severity: Major
    Found in lib/modes/server.js - About 6 hrs to fix

      Acetate has 41 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Acetate extends EventEmitter {
        constructor({
          config = "acetate.config.js",
          sourceDir = "src",
          outDir = "build",
      Severity: Minor
      Found in lib/Acetate.js - About 5 hrs to fix

        Function reloadConfig has 80 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          reloadConfig() {
            this.emit("config:reloading");
            this.reset();
        
            this.require("./helpers/highlight-block.js");
        Severity: Major
        Found in lib/Acetate.js - About 3 hrs to fix

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

          module.exports = function(acetate) {
            acetate.helper(
              "link",
              function(context, destinationUrl, text) {
                const currentUrl = context.options.currentUrl || context.page.url;
          Severity: Minor
          Found in lib/helpers/link-helper.js - About 2 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 exports has 68 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          module.exports = function(acetate) {
            acetate.helper(
              "link",
              function(context, destinationUrl, text) {
                const currentUrl = context.options.currentUrl || context.page.url;
          Severity: Major
          Found in lib/helpers/link-helper.js - About 2 hrs to fix

            Function exports has 59 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            module.exports = function(acetate) {
              const pagesCache = {};
            
              const acetateMiddleware = function acetateMiddleware(
                request,
            Severity: Major
            Found in lib/modes/middleware.js - About 2 hrs to fix

              Function acetateMiddleware has 48 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                const acetateMiddleware = function acetateMiddleware(
                  request,
                  response,
                  next
                ) {
              Severity: Minor
              Found in lib/modes/middleware.js - About 1 hr to fix

                Function createServer has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                function createServer(acetate, options = {}) {
                  function notFoundMiddleware(request, response) {
                    acetate.log.warn(`404 not found ${url.parse(request.url).pathname}`);
                    response.writeHead(404, { "Content-Type": "text/html" });
                    response.end(notFoundPageTemplate);
                Severity: Minor
                Found in lib/modes/server.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 createWatcher has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                module.exports = function createWatcher(acetate) {
                  function removePage(page) {
                    const outputPath = path.join(acetate.outDir, page.dest);
                    deleteFile(outputPath)
                      .then(function() {
                Severity: Minor
                Found in lib/modes/watcher.js - About 1 hr to fix

                  Function _createLoaderTask has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    _createLoaderTask(
                      pattern,
                      { ignore = [], metadata = {}, basePath = "" } = {}
                    ) {
                      return (createPage, callback) => {
                  Severity: Minor
                  Found in lib/Acetate.js - About 1 hr to fix

                    Function reset has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      reset() {
                        this._paths = [];
                        this._pages = [];
                        this._pagesLoaded = false;
                        this._loaders = [];
                    Severity: Minor
                    Found in lib/Acetate.js - About 1 hr to fix

                      Function _handlePageWatcherEvent has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        _handlePageWatcherEvent(src, eventName, verb) {
                          this.log.info(`${src} ${verb}`);
                          if (path.basename(src)[0] === "_") {
                            this.emit(`watcher:template:${eventName}`, src);
                          } else {
                      Severity: Minor
                      Found in lib/Acetate.js - About 1 hr to fix

                        Function run has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        function run() {
                          if (argv.require && argv.require.length) {
                            argv.require.forEach(dep => {
                              require(dep);
                            });
                        Severity: Minor
                        Found in lib/cli.js - About 1 hr to fix

                          Function transform has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                          Open

                            transform(pattern, transformer, label) {
                              const matcher = new minimatch.Minimatch(pattern);
                              const transformRunner = function(page, done) {
                                if (!matcher.match(page.src)) {
                                  process.nextTick(() => {
                          Severity: Minor
                          Found in lib/Acetate.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 startPageWatcher has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            startPageWatcher() {
                              if (this._pageWatcher) {
                                this.stopWatcher();
                              }
                          
                          
                          Severity: Minor
                          Found in lib/Acetate.js - About 1 hr to fix

                            Function constructor has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              constructor(error, page) {
                                error = typeof error === "string" ? new Error(error) : error;
                                let originalMessage = _.trim(_.last(error.message.split("\n")));
                                if (/ \[(Line) \d+, Column \d+\]/.test(error.message)) {
                                  let originalErrorLocation = error.message.match(/.*: \((.*)\)/);
                            Severity: Minor
                            Found in lib/error-types/PageRenderError.js - About 1 hr to fix

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

                                transform(pattern, transformer, label) {
                                  const matcher = new minimatch.Minimatch(pattern);
                                  const transformRunner = function(page, done) {
                                    if (!matcher.match(page.src)) {
                                      process.nextTick(() => {
                              Severity: Minor
                              Found in lib/Acetate.js - About 1 hr to fix

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

                                      const done = (error, filepaths) => {
                                        if (error) {
                                          callback(error);
                                        }
                                
                                
                                Severity: Minor
                                Found in lib/Acetate.js - About 1 hr to fix

                                  Function fromTemplate has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  function fromTemplate(src, templatePath, defaultMetadata = {}, options) {
                                    const filename = path.basename(templatePath, path.extname(templatePath));
                                    const dirname = path.dirname(templatePath);
                                    const yamlMetadataPath = path.join(dirname, `${filename}.metadata.yaml`);
                                    const jsonMetadataPath = path.join(dirname, `${filename}.metadata.json`);
                                  Severity: Minor
                                  Found in lib/createPage.js - About 1 hr to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language