File javascript.js
has 861 lines of code (exceeds 250 allowed). Consider refactoring. Open
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
- Create a ticketCreate a ticket
Function tokenBase
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
function tokenBase(stream, state) {
var ch = stream.next();
if (ch == '"' || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
- Create a ticketCreate a ticket
Function statement
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
function statement(type, value) {
if (type == "var") return cont(pushlex("vardef", value), vardef, expect(";"), poplex);
if (type == "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex);
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
if (type == "keyword d") return cx.stream.match(/^\s*$/, false) ? cont() : cont(pushlex("stat"), maybeexpression, expect(";"), poplex);
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (type == "async" ||
(type == "variable" &&
(value == "static" || value == "get" || value == "set" || (isTS && isModifier(value))) &&
cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false))) {
cx.marked = "keyword";
- Create a ticketCreate a ticket
Function findFatArrow
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function findFatArrow(stream, state) {
if (state.fatArrowAt) state.fatArrowAt = null;
var arrow = stream.string.indexOf("=>", stream.start);
if (arrow < 0) return;
- Create a ticketCreate a ticket
Function objprop
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function objprop(type, value) {
if (type == "async") {
cx.marked = "property";
return cont(objprop);
} else if (type == "variable" || cx.style == "keyword") {
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (next == ch && stream.string.charAt(pos - 2) != "\\") { pos--; break }
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (ch == "!" || ch == "=") stream.eat("=")
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (keywords.propertyIsEnumerable(word)) {
var kw = keywords[word]
return ret(kw.type, kw.style, word)
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (pos == 0) return
- Create a ticketCreate a ticket
Function JSLexical
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function JSLexical(indented, column, type, align, prev, info) {
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (word == "async" && stream.match(/^(\s|\/\*.*?\*\/)*[\[\(\w]/, false))
return ret("async", "keyword", word)
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
} else if (/[<>*+\-]/.test(ch)) {
stream.eat(ch)
if (ch == ">") stream.eat(ch)
}
- Create a ticketCreate a ticket
Function parseJS
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function parseJS(state, style, type, content, stream) {
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "quasi") return pass(quasi, maybeop);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(expression, maybetype, expect("]"), afterprop);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "}") return cont();
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("operator", "operator", stream.current());
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(pushlex("stat"), maybelabel);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "case") return cont(expression, expect(":"));
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return pass(pushlex("stat"), expression, expect(";"), poplex);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "new") return cont(maybeTarget(noComma));
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(objprop);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
else return lexical.indented + (closing ? 0 : indentUnit);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("number", "number");
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return tokenQuasi(stream, state);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("error", "error");
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "function") return cont(functiondef);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("=>", "operator");
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(pushlex("form"), parenExpr, statement, poplex, maybeelse);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "{") return contCommasep(proppattern, "}");
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(expect(":"), pattern, maybeAssign);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("number", "number");
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "keyword c" || type == "async") return cont(noComma ? expressionNoComma : expression);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("async", "keyword", word)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return context
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "class" || (isTS && value == "interface")) { cx.marked = "keyword"; return cont(pushlex("form"), classExpression, poplex); }
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == ".") return cont(property, me);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (isTS && value == "as") { cx.marked = "keyword"; return cont(typeexpr, me) }
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (value == "?") return cont(typeexpr, expect(":"), typeexpr)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("operator", "operator", stream.current());
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType, afterType)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("comment", "comment");
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("variable", "variable", word)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(pushlex("form"), expression, statement, poplex)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(expr)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
else if (type == "form") return lexical.indented + indentUnit;
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return tokenComment(stream, state);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(statement)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(expressionNoComma, afterprop);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (isTS && type == "(") return pass(functiondecl, classBody)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("comment", "comment")
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return new Context(context.prev, new Var(varname, context.vars), false)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == ";") return cont();
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont();
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "quasi") { return pass(quasi, me); }
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return pass(afterprop)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return pass(functiondecl, typeprop)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(classBody);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret(kw.type, kw.style, word)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (value == "enum") return cont(enumdef);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == ";" || type == ",") return cont(classBody);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (value == "@") return cont(expression, classBody)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return ret("regexp", "string-2");
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (value == "@") return cont(expression, statement)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "import") return cont(expression);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(afterprop);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(objprop)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "debugger") return cont(expect(";"));
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
else return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(statement)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "catch") return cont(pushlex("form"), pushcontext, maybeCatchBinding, statement, poplex, popcontext);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "async") return cont(statement)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == ";") return;
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "<") return cont(commasep(typeexpr, ">"), typeexpr)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(pushlex("form", type == "class" ? type : value), className, poplex)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"), pushblockcontext,
block, poplex, poplex, popcontext);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "default") return cont(expect(":"));
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return cont(expr);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType)
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "{") return cont(pushlex("}"), pushblockcontext, block, poplex, popcontext);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
else if (value == "type") return cont(typename, expect("operator"), typeexpr, expect(";"));
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
- Create a ticketCreate a ticket
Identical blocks of code found in 2 locations. Consider refactoring. Open
function poplex() {
var state = cx.state;
if (state.lexical.prev) {
if (state.lexical.type == ")")
state.indented = state.lexical.indented;
- Read upRead up
- Create a ticketCreate a ticket
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 88.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
function JSLexical(indented, column, type, align, prev, info) {
this.indented = indented;
this.column = column;
this.type = type;
this.prev = prev;
- Read upRead up
- Create a ticketCreate a ticket
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 88.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
function tokenComment(stream, state) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
- Read upRead up
- Create a ticketCreate a ticket
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 78.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
function popcontext() {
cx.state.localVars = cx.state.context.vars
cx.state.context = cx.state.context.prev
}
- Read upRead up
- Create a ticketCreate a ticket
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 62.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
function pass() {
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
}
- Read upRead up
- Create a ticketCreate a ticket
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 55.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
function inList(name, list) {
for (var v = list; v; v = v.next) if (v.name == name) return true
return false;
}
- Read upRead up
- Create a ticketCreate a ticket
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 50.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
function Context(prev, vars, block) { this.prev = prev; this.vars = vars; this.block = block }
- Read upRead up
- Create a ticketCreate a ticket
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
for (var cx = state.context; cx; cx = cx.prev) {
for (var v = cx.vars; v; v = v.next)
if (v.name == varname) return true;
}
- Read upRead up
- Create a ticketCreate a ticket
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 45.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76