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');
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({
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');
}
- Read upRead up
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) {
- Read upRead up
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) {
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();
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) {
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, '/');
}
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];
- Read upRead up
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)
- Read upRead up
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, '/');
}
- Read upRead up
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');
}
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) {
- Read upRead up
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"