qiu8310/coding

View on GitHub

Showing 15 of 15 total issues

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

function renameRequire(ast, filePath, opts) {
  var aliasMap = {},
    addAlias = function(alias) { if (alias) { _.assign(aliasMap, alias); } },
    delAlias = function(alias) { if (alias) { aliasMap = _.omit(aliasMap, _.keys(alias)); } };

Severity: Minor
Found in src/lib/refactor.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

Function removeExport has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

function removeExport(ast, filePath, opts) {
  var bodyNodes = ast.body, node, obj, prop, i, statCount = 0, exportCount = 0, exportMember, exportGlobal = false;

  var exp = rename(filePath, opts);

Severity: Minor
Found in src/lib/refactor.js - About 3 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 findAllRequiredFile has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

function findAllRequiredFile(filePath) {
  var ast = helper.getFileAST(filePath),
    result = [];

  //require('fs').writeFile(filePath.replace(/\.js$/, '.json'), JSON.stringify(ast, null, 2));
Severity: Minor
Found in src/lib/traverse.js - About 3 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 removeExport has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function removeExport(ast, filePath, opts) {
  var bodyNodes = ast.body, node, obj, prop, i, statCount = 0, exportCount = 0, exportMember, exportGlobal = false;

  var exp = rename(filePath, opts);

Severity: Major
Found in src/lib/refactor.js - About 2 hrs to fix

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

    function removeRequire(ast, filePath, opts) {
      var removePaths = [];
      estraverse.traverse(ast, {
        enter: function(node, parent) {
          if (node.type === 'VariableDeclaration') {
    Severity: Minor
    Found in src/lib/refactor.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 renameRequire has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function renameRequire(ast, filePath, opts) {
      var aliasMap = {},
        addAlias = function(alias) { if (alias) { _.assign(aliasMap, alias); } },
        delAlias = function(alias) { if (alias) { aliasMap = _.omit(aliasMap, _.keys(alias)); } };
    
    
    Severity: Minor
    Found in src/lib/refactor.js - About 1 hr to fix

      Function removeRequire has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function removeRequire(ast, filePath, opts) {
        var removePaths = [];
        estraverse.traverse(ast, {
          enter: function(node, parent) {
            if (node.type === 'VariableDeclaration') {
      Severity: Minor
      Found in src/lib/refactor.js - About 1 hr to fix

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

        function findAllRequiredFile(filePath) {
          var ast = helper.getFileAST(filePath),
            result = [];
        
          //require('fs').writeFile(filePath.replace(/\.js$/, '.json'), JSON.stringify(ast, null, 2));
        Severity: Minor
        Found in src/lib/traverse.js - About 1 hr to fix

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

          module.exports = function(filePath, opts) {
            opts = _.assign({
              global: 'G',
              rename: null,
              transform: null,  // should be function
          Severity: Minor
          Found in src/coding.js - About 1 hr to fix

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

                enter: function(node, parent) {
                  addAlias(node._alias);
            
                  var i, id, param, t;
                  // 函数中的参数如果包含有 alias 的话,则之后出现的 alias 全部忽略
            Severity: Minor
            Found in src/lib/refactor.js - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                        if (!exportMember) {
                          exportGlobal = true;
                        }
              Severity: Major
              Found in src/lib/refactor.js - About 45 mins to fix

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

                module.exports = function(filePath, opts) {
                  opts = _.assign({
                    global: 'G',
                    rename: null,
                    transform: null,  // should be function
                Severity: Minor
                Found in src/coding.js - About 35 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

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

                          if (param.type === 'Identifier' && ((id = param.name) in aliasMap)) {
                            t = node._unalias || {};
                            t[id] = aliasMap[id];
                            node._unalias = t;
                          }
                Severity: Minor
                Found in src/lib/refactor.js and 1 other location - About 35 mins to fix
                src/lib/refactor.js on lines 97..101

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

                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 (param.id && param.id.type === 'Identifier' && ((id = param.id.name) in aliasMap)) {
                            t = parent._unalias || {};
                            t[id] = aliasMap[id];
                            parent._unalias = t;
                          }
                Severity: Minor
                Found in src/lib/refactor.js and 1 other location - About 35 mins to fix
                src/lib/refactor.js on lines 85..89

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

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

                function rename(filePath, opts) {
                  var res;
                  if (opts.rename && typeof opts.rename === 'function') {
                    res = opts.rename(filePath);
                    if (typeof res === 'string') {
                Severity: Minor
                Found in src/lib/refactor.js - About 25 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