Showing 686 of 688 total issues
Class WikiController
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class WikiController < ApplicationController
before_action :require_user, only: %i(new create edit update delete replace)
def subdomain
url = "//#{request.host}/wiki/"
- Create a ticketCreate a ticket
Class AdminController
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class AdminController < ApplicationController
before_action :require_user, only: %i(spam spam_revisions mark_comment_spam publish_comment spam_comments)
# intended to provide integration tests for assets
def assets; end
- Create a ticketCreate a ticket
Class TagController
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class TagController < ApplicationController
respond_to :html, :xml, :json, :ics
before_action :require_user, only: %i(create delete)
include Pagy::Backend
- Create a ticketCreate a ticket
Method new_note
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def self.new_note(params)
saved = false
author = User.find(params[:uid])
node = Node.new(uid: author.uid,
title: params[:title],
- Read upRead up
- Create a ticketCreate a ticket
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 CommentsList
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
const CommentsList = ({
commentFormsVisibility,
comments,
currentUser,
dispatch,
- Read upRead up
- Create a ticketCreate a ticket
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 generateCommentComponents
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
const generateCommentComponents = (commentsArray) => {
return commentsArray.map((comment) => {
// these props are common to all forms
const commentFormProps = {
commentId: comment.commentId,
- Create a ticketCreate a ticket
Function reducer
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
const reducer = (state, action) => {
switch(action.type) {
// COMMENT actions
case "CREATE COMMENT":
return {
- Create a ticketCreate a ticket
Method delete
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def delete
@comment = Comment.find params[:id]
comments_node_and_path
- Read upRead up
- Create a ticketCreate a ticket
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
Method create
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def create
if current_user.status == 1
# we no longer allow custom urls, just titles which are parameterized automatically into urls
# slug = params[:title].parameterize
# slug = params[:id].parameterize if params[:id] != "" && !params[:id].nil?
- Read upRead up
- Create a ticketCreate a ticket
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
Method add_tag
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
def add_tag(tagname, user)
if user.status == 1
tagname = tagname.downcase
unless has_tag_without_aliasing(tagname)
saved = false
- Create a ticketCreate a ticket
Method index
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
def index
@toggle = params[:sort] || "uses"
@title = I18n.t('tag_controller.tags')
@paginated = true
- Create a ticketCreate a ticket
File validation.js
has 272 lines of code (exceeds 250 allowed). Consider refactoring. Open
$(document).ready(function() {
$("#edit-form").validate({
rules: {
'user[email]': {
required: true,
- Create a ticketCreate a ticket
Function 'promptTag' has a complexity of 13. Open
function promptTag(val) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Limit Cyclomatic Complexity (complexity)
Cyclomatic complexity measures the number of linearly independent paths through a program's source code. This rule allows setting a cyclomatic complexity threshold.
function a(x) {
if (true) {
return x; // 1st path
} else if (false) {
return x+1; // 2nd path
} else {
return 4; // 3rd path
}
}
Rule Details
This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is 20
).
Examples of incorrect code for a maximum of 2:
/*eslint complexity: ["error", 2]*/
function a(x) {
if (true) {
return x;
} else if (false) {
return x+1;
} else {
return 4; // 3rd path
}
}
Examples of correct code for a maximum of 2:
/*eslint complexity: ["error", 2]*/
function a(x) {
if (true) {
return x;
} else {
return 4;
}
}
Options
Optionally, you may specify a max
object property:
"complexity": ["error", 2]
is equivalent to
"complexity": ["error", { "max": 2 }]
Deprecated: the object property maximum
is deprecated. Please use the property max
instead.
When Not To Use It
If you can't determine an appropriate complexity limit for your code, then it's best to disable this rule.
Further Reading
Related Rules
- [max-depth](max-depth.md)
- [max-len](max-len.md)
- [max-nested-callbacks](max-nested-callbacks.md)
- [max-params](max-params.md)
- [max-statements](max-statements.md) Source: http://eslint.org/docs/rules/
Method check_and_add_tweets
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def self.check_and_add_tweets(tweets)
tweets.each do |tweet|
next unless tweet.reply?
in_reply_to_tweet_id = tweet.in_reply_to_tweet_id
- Read upRead up
- Create a ticketCreate a ticket
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 'diffString' has a complexity of 12. Open
function diffString( o, n ) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Limit Cyclomatic Complexity (complexity)
Cyclomatic complexity measures the number of linearly independent paths through a program's source code. This rule allows setting a cyclomatic complexity threshold.
function a(x) {
if (true) {
return x; // 1st path
} else if (false) {
return x+1; // 2nd path
} else {
return 4; // 3rd path
}
}
Rule Details
This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is 20
).
Examples of incorrect code for a maximum of 2:
/*eslint complexity: ["error", 2]*/
function a(x) {
if (true) {
return x;
} else if (false) {
return x+1;
} else {
return 4; // 3rd path
}
}
Examples of correct code for a maximum of 2:
/*eslint complexity: ["error", 2]*/
function a(x) {
if (true) {
return x;
} else {
return 4;
}
}
Options
Optionally, you may specify a max
object property:
"complexity": ["error", 2]
is equivalent to
"complexity": ["error", { "max": 2 }]
Deprecated: the object property maximum
is deprecated. Please use the property max
instead.
When Not To Use It
If you can't determine an appropriate complexity limit for your code, then it's best to disable this rule.
Further Reading
Related Rules
- [max-depth](max-depth.md)
- [max-len](max-len.md)
- [max-nested-callbacks](max-nested-callbacks.md)
- [max-params](max-params.md)
- [max-statements](max-statements.md) Source: http://eslint.org/docs/rules/
Method show
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
def show
@node = if params[:lang]
Node.find_wiki(params[:lang] + '/' + params[:id])
else
Node.find_wiki(params[:id])
- Create a ticketCreate a ticket
Identical blocks of code found in 2 locations. Consider refactoring. Open
respond_with(nodes) do |format|
format.html { render 'tag/show' }
format.xml { render xml: nodes }
format.json do
json = []
- 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 86.
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
respond_with(nodes) do |format|
format.html { render 'tag/show' }
format.xml { render xml: nodes }
format.json do
json = []
- 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 86.
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
Method parse_comment_from_email
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def self.parse_comment_from_email(mail, node_id, user, reply_to = [false, nil])
node = Node.where(nid: node_id).first
if node && mail&.html_part
mail_doc = Nokogiri::HTML(mail&.html_part&.body&.decoded) # To parse the mail to extract comment content and reply content
domain = get_domain mail.from.first
- Read upRead up
- Create a ticketCreate a ticket
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
Method publish
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def publish
if logged_in_as(['admin', 'moderator'])
@node = Node.find params[:id]
if @node.status == 1
flash[:notice] = 'Item already published.'
- Read upRead up
- Create a ticketCreate a ticket
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"