src/grammar-registry.js

Summary

Maintainability
F
3 days
Test Coverage

File grammar-registry.js has 477 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const _ = require('underscore-plus');
const Grim = require('grim');
const CSON = require('season');
const FirstMate = require('first-mate');
const { Disposable, CompositeDisposable } = require('event-kit');
Severity: Minor
Found in src/grammar-registry.js - About 7 hrs to fix

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

    module.exports = class GrammarRegistry {
      constructor({ config } = {}) {
        this.config = config;
        this.subscriptions = new CompositeDisposable();
        this.textmateRegistry = new FirstMate.GrammarRegistry({
    Severity: Minor
    Found in src/grammar-registry.js - About 5 hrs to fix

      Function getGrammarScore has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

        getGrammarScore(grammar, filePath, contents) {
          if (contents == null && fs.isFileSync(filePath)) {
            contents = fs.readFileSync(filePath, 'utf8');
          }
      
      
      Severity: Minor
      Found in src/grammar-registry.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 grammarMatchesPrefix has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        grammarMatchesPrefix(grammar, contents) {
          if (contents && grammar.firstLineRegex) {
            let escaped = false;
            let numberOfNewlinesInRegex = 0;
            for (let character of grammar.firstLineRegex.source) {
      Severity: Minor
      Found in src/grammar-registry.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 grammarMatchesPrefix has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        grammarMatchesPrefix(grammar, contents) {
          if (contents && grammar.firstLineRegex) {
            let escaped = false;
            let numberOfNewlinesInRegex = 0;
            for (let character of grammar.firstLineRegex.source) {
      Severity: Minor
      Found in src/grammar-registry.js - About 1 hr to fix

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

          grammarAddedOrUpdated(grammar) {
            if (grammar.scopeName && !grammar.id) grammar.id = grammar.scopeName;
        
            this.grammarScoresByBuffer.forEach((score, buffer) => {
              const languageMode = buffer.getLanguageMode();
        Severity: Minor
        Found in src/grammar-registry.js - About 1 hr to fix

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

            maintainLanguageMode(buffer) {
              this.grammarScoresByBuffer.set(buffer, null);
          
              const languageOverride = this.languageOverridesByBufferId.get(buffer.id);
              if (languageOverride) {
          Severity: Minor
          Found in src/grammar-registry.js - About 1 hr to fix

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

              getGrammarPathScore(grammar, filePath) {
                if (!filePath) return -1;
                if (process.platform === 'win32') {
                  filePath = filePath.replace(/\\/g, '/');
                }
            Severity: Minor
            Found in src/grammar-registry.js - About 1 hr to fix

              Function treeSitterGrammarForLanguageString has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                treeSitterGrammarForLanguageString(languageString) {
                  let longestMatchLength = 0;
                  let grammarWithLongestMatch = null;
                  for (const id in this.treeSitterGrammarsById) {
                    const grammar = this.treeSitterGrammarsById[id];
              Severity: Minor
              Found in src/grammar-registry.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 addGrammar has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                addGrammar(grammar) {
                  if (grammar instanceof TreeSitterGrammar) {
                    const existingParams =
                      this.treeSitterGrammarsById[grammar.scopeName] || {};
                    if (grammar.scopeName)
              Severity: Minor
              Found in src/grammar-registry.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 getGrammarPathScore has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                getGrammarPathScore(grammar, filePath) {
                  if (!filePath) return -1;
                  if (process.platform === 'win32') {
                    filePath = filePath.replace(/\\/g, '/');
                  }
              Severity: Minor
              Found in src/grammar-registry.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 getGrammarScore has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                getGrammarScore(grammar, filePath, contents) {
                  if (contents == null && fs.isFileSync(filePath)) {
                    contents = fs.readFileSync(filePath, 'utf8');
                  }
              
              
              Severity: Minor
              Found in src/grammar-registry.js - About 1 hr to fix

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

                  assignLanguageMode(buffer, languageId) {
                    if (buffer.getBuffer) buffer = buffer.getBuffer();
                
                    let grammar = null;
                    if (languageId != null) {
                Severity: Minor
                Found in src/grammar-registry.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

                There are no issues that match your filters.

                Category
                Status