Showing 141 of 141 total issues

Function initialize has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  * initialize(next) {
    logger("using leafjs socketio middleware");

    let leaf = this;
    let koa = leaf.koa;
Severity: Minor
Found in lib/middleware/socketio.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 initialize has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  * initialize(next) {
    let koa = this.koa;

    logger("using leafjs body middleware");

Severity: Major
Found in lib/middleware/body.js - About 2 hrs to fix

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

      constructor() {
        function serviceUp(service) {
          logger(`serviceup: ${service.type.name}`, service);
          if (service.type.name !== "leaf") {
            logger('ignoring service, service name not leaf');
    Severity: Major
    Found in lib/provider/browser.js - About 2 hrs to fix

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

          koa.use(function* bodyParseMiddleware(next) {
            let body, parts;
            let contentType = this.req.headers['content-type'],
              contentLength = this.req.headers["content-length"],
              transferEncoding = this.req.headers["transfer-encoding"];
      Severity: Major
      Found in lib/middleware/body.js - About 2 hrs to fix

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

            function handler(origHeaders) {
              logger("delete accept-encoding in origHeaders");
              delete origHeaders["accept-encoding"];
              return function _handler(method, route, data, headers, cb) {
                logger(`trigger socket.io s handler, with (${method}, ${route}, ${data}, ${headers})`);
        Severity: Major
        Found in lib/middleware/socketio.js - About 2 hrs to fix

          Function constructor has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

            constructor() {
              function serviceUp(service) {
                logger(`serviceup: ${service.type.name}`, service);
                if (service.type.name !== "leaf") {
                  logger('ignoring service, service name not leaf');
          Severity: Minor
          Found in lib/provider/browser.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 decorate has 56 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          exports = module.exports = function decorate(leaf, options) {
            options = options || {};
          
            let koa = leaf.koa;
            // koa request
          Severity: Major
          Found in lib/decorator/index.js - About 2 hrs to fix

            Function _handler has 55 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  return function _handler(method, route, data, headers, cb) {
                    logger(`trigger socket.io s handler, with (${method}, ${route}, ${data}, ${headers})`);
                    if (undefined === cb) { //arguments is method, route, headers, cb
                      cb = headers;
                      headers = data;
            Severity: Major
            Found in lib/middleware/socketio.js - About 2 hrs to fix

              Function decorate has 54 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              exports = module.exports = function decorate(req) {
              
                /**
                 * Intiate a login session for `user`.
                 *
              Severity: Major
              Found in lib/decorator/passport-req.js - About 2 hrs to fix

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

                  it('websocket: should have a get(/test/:name)', function(done) {
                    sio.emit('s', "get", "/test/chrisye", {}, {}, function(status, headers, body) {
                      expect(status).eql(200);
                      expect(body).eql('getchrisye');
                      done();
                Severity: Major
                Found in examples/test/router.js and 1 other location - About 2 hrs to fix
                examples/test/router.js on lines 72..78

                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

                  it('websocket: should have a get(/test)', function(done) {
                    sio.emit('s', "get", "/test", {}, {}, function(status, headers, body) {
                      expect(status).eql(200);
                      expect(body).eql('get');
                      done();
                Severity: Major
                Found in examples/test/router.js and 1 other location - About 2 hrs to fix
                examples/test/router.js on lines 88..94

                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

                Function initialize has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  * initialize(next) {
                    logger("using leaf static server middleware");
                    let leaf = this;
                    let koa = this.koa;
                
                
                Severity: Minor
                Found in lib/middleware/static-server.js - About 2 hrs to fix

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

                        let serverMw = function* startServer(next) {
                          logger("require pmx and initalizing");
                          require("pmx").init();
                  
                          yield * next;
                  Severity: Minor
                  Found in index.js - About 1 hr to fix

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

                        koa.use(function* staticServer(next) {
                          let path = options.uri;
                          if (this.request.path) {
                            if (leaf.namespace && leaf.namespace !== "/") {
                              path = leaf.namespace + path;
                    Severity: Minor
                    Found in lib/middleware/static-server.js - About 1 hr to fix

                      Function decorate has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                      Open

                      exports = module.exports = function decorate(leaf, options) {
                        options = options || {};
                      
                        let koa = leaf.koa;
                        // koa request
                      Severity: Minor
                      Found in lib/decorator/index.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 constructor has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        constructor(mod, config) {
                          super();
                          if (!(this instanceof Leaf)) return new Leaf(mod, config);
                          logger(`root pwd is ${pathModule.resolve(".")}`);
                      
                      
                      Severity: Minor
                      Found in index.js - About 1 hr to fix

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

                          after(function(done) {
                            this.timeout(5000);
                            app.close().then(function() {
                              done();
                            }, function(err) {
                        Severity: Major
                        Found in examples/test/static.js and 1 other location - About 1 hr to fix
                        examples/test/infra.js on lines 22..29

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

                        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

                          after(function(done) {
                            this.timeout(5000);
                            app.close().then(function() {
                              done();
                            }, function(err) {
                        Severity: Major
                        Found in examples/test/infra.js and 1 other location - About 1 hr to fix
                        examples/test/static.js on lines 22..29

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

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

                          get(name, ver) {
                            let time = new Date();
                            // think of a way to refactor this into a generator, so we can just store that as a cache and yield everytime
                            // hopeful usage would be:
                            // var service = cache[service@version].next();
                        Severity: Minor
                        Found in lib/provider/browser.js - About 1 hr to fix

                          Function initialize has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                          Open

                            * initialize(next) {
                              logger("using leaf static server middleware");
                              let leaf = this;
                              let koa = this.koa;
                          
                          
                          Severity: Minor
                          Found in lib/middleware/static-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

                          Severity
                          Category
                          Status
                          Source
                          Language