src/style-manager.js

Summary

Maintainability
D
1 day
Test Coverage

Function transformDeprecatedShadowDOMSelectors has 87 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function transformDeprecatedShadowDOMSelectors(css, context) {
  const transformedSelectors = [];
  let transformedSource;
  try {
    transformedSource = postcss.parse(css);
Severity: Major
Found in src/style-manager.js - About 3 hrs to fix

    File style-manager.js has 279 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const { Emitter, Disposable } = require('event-kit');
    const crypto = require('crypto');
    const fs = require('fs-plus');
    const path = require('path');
    const postcss = require('postcss');
    Severity: Minor
    Found in src/style-manager.js - About 2 hrs to fix

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

        addStyleSheet(source, params = {}) {
          let styleElement;
          let updated;
          if (
            params.sourcePath != null &&
      Severity: Minor
      Found in src/style-manager.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 addStyleSheet has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        addStyleSheet(source, params = {}) {
          let styleElement;
          let updated;
          if (
            params.sourcePath != null &&
      Severity: Minor
      Found in src/style-manager.js - About 1 hr to fix

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

              const transformedSelector = selectorParser(selectors => {
                selectors.each(selector => {
                  const firstNode = selector.nodes[0];
                  if (
                    context === 'atom-text-editor' &&
        Severity: Minor
        Found in src/style-manager.js - About 1 hr to fix

          Function addStyleElement has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            addStyleElement(styleElement) {
              let insertIndex = this.styleElements.length;
              if (styleElement.priority != null) {
                for (let i = 0; i < this.styleElements.length; i++) {
                  const existingElement = this.styleElements[i];
          Severity: Minor
          Found in src/style-manager.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

          Function upgradeDeprecatedSelectorsForStyleSheet has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            upgradeDeprecatedSelectorsForStyleSheet(styleSheet, context) {
              if (this.cacheDirPath != null) {
                const hash = crypto.createHash('sha1');
                if (context != null) {
                  hash.update(context);
          Severity: Minor
          Found in src/style-manager.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

          Function restoreSnapshot has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            restoreSnapshot(styleElementsToRestore) {
              for (let styleElement of this.getStyleElements()) {
                if (!styleElementsToRestore.includes(styleElement)) {
                  this.removeStyleElement(styleElement);
                }
          Severity: Minor
          Found in src/style-manager.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

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

                if (params.context != null) {
                  styleElement.context = params.context;
                  styleElement.setAttribute('context', params.context);
                }
          Severity: Minor
          Found in src/style-manager.js and 2 other locations - About 35 mins to fix
          src/style-manager.js on lines 133..136
          src/style-manager.js on lines 141..144

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

                if (params.sourcePath != null) {
                  styleElement.sourcePath = params.sourcePath;
                  styleElement.setAttribute('source-path', params.sourcePath);
                }
          Severity: Minor
          Found in src/style-manager.js and 2 other locations - About 35 mins to fix
          src/style-manager.js on lines 137..140
          src/style-manager.js on lines 141..144

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

                if (params.priority != null) {
                  styleElement.priority = params.priority;
                  styleElement.setAttribute('priority', params.priority);
                }
          Severity: Minor
          Found in src/style-manager.js and 2 other locations - About 35 mins to fix
          src/style-manager.js on lines 133..136
          src/style-manager.js on lines 137..140

          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

          There are no issues that match your filters.

          Category
          Status