Showing 1,672 of 1,672 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
ModuleName.propTypes = {
due_date: PropTypes.string.isRequired,
isExercise: PropTypes.bool.isRequired,
name: PropTypes.string.isRequired
};
- Read upRead up
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 51.
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
Function searchForPages
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
async searchForPages(wiki, search_term, namespace, map=(el)=>el, depth, limit=10){
Function createNewsContent
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
export const createNewsContent = (newsContent, post = false) => async (dispatch, getState) => {
if (post) {
try {
// If `post` is true, create news on the server
const newsDetails = await API.createNews(getState().news.create_news);
- 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 claimAssignment
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
export const claimAssignment = (assignment, successNotification) => (dispatch) => {
return claimAssignmentPromise(assignment)
.then((resp) => {
if (resp.assignment) {
if (successNotification) { dispatch(addNotification(successNotification)); }
- 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 option
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
option: (styles, { isDisabled, isFocused, isSelected }) => {
let backgroundColor;
let color;
if (isDisabled) {
backgroundColor = 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"
Further reading
Function updateCourseDates
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
updateCourseDates(prevCourse, valueKey, value) {
const updatedCourse = Object.assign({}, prevCourse); // clone the course
updatedCourse[valueKey] = value;
// Just return with the new value if it doesn't pass validation
// or if it it lacks timeline dates
- 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 range
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function* range(left, right, inclusive) {
const ascending = left < right;
let endOfRange;
if (!inclusive) {
- 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 getWikiMap
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
export const getWikiMap = (revisions) => {
const wikiMap = new Map();
for (const revision of revisions) {
if (supportsPageAssessments(revision.wiki) || isSupportedORESWiki(revision.wiki)
) {
- 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 option
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
option: (styles, { isDisabled, isFocused, isSelected }) => {
let backgroundColor;
let color;
if (isDisabled) {
backgroundColor = 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"
Further reading
Function fetchCourseScopedRevisions
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
export const fetchCourseScopedRevisions = (course, limit) => async (dispatch, getState) => {
const state = getState();
const users = state.users.users.filter(user => user.role === STUDENT_ROLE);
dispatch({ type: COURSE_SCOPED_REVISIONS_LOADING });
- 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 InstructorStats
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const InstructorStats = ({ username, stats, maxProject, statsGraphsData, graphWidth, graphHeight, isStudent }) => {
const [selectedGraph, setSelectedGraph] = useState('courses_count');
const [coursesGraph, setCoursesGraph] = useState(true);
const setCoursesCountGraph = () => {
- 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
Avoid deeply nested control flow statements. Open
if (moveUp) {
const toWeekBlocks = this.getBlocksInWeek(toWeek.id);
atIndex = toWeekBlocks.length;
}
Function NamespaceSelect
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const NamespaceSelect = (props) => {
const [selectedNamespaces, setSelectedNamespaces] = useState([]);
const [options, setOptions] = useState([]);
useEffect(() => {
- 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 NewAccountModal
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const NewAccountModal = ({ course, passcode, currentUser, closeModal, newAccount, actions }) => {
const checkAvailability = () => (actions.checkAvailability(newAccount));
const createRequestedAccountImmediately = currentUser.isInstructor;
const requestAccount = () => {
actions.requestAccount(passcode, course, newAccount, createRequestedAccountImmediately);
- 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 CourseScoping
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const CourseScoping = ({ show, wizardController, showCourseDates }) => {
const selectedScopingMethods = useSelector(state => state.scopingMethods.selected);
const scopingMethods = [
'index',
...selectedScopingMethods
- 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 CourseForm
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const CourseForm = (props) => {
const handleWikiChange = (wiki) => {
const home_wiki = wiki.value;
const prev_wiki = { ...props.course.home_wiki };
const wikis = CourseUtils.normalizeWikis(
- 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 Revision
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const Revision = ({ revision, index, wikidataLabel, course, setSelectedIndex, lastIndex, selectedIndex }) => {
const ratingClass = `rating ${revision.rating}`;
const ratingMobileClass = `${ratingClass} tablet-only`;
const formattedTitle = CourseUtils.formattedArticleTitle({ title: revision.title, project: revision.wiki.project, language: revision.wiki.language }, course.home_wiki, wikidataLabel);
const subtitle = wikidataLabel ? `(${CourseUtils.removeNamespace(revision.title)})` : '';
- 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 selectDay
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
selectDay(day) {
let exceptions;
if (!this.inrange(day)) { return; }
const { course } = this.props;
if (course.day_exceptions === undefined) {
- 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 Reply
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
export const Reply = ({ message }) => {
const { sender, details } = message;
let delivered_message;
let failed_message;
if (details.delivered) {
- 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 SlideMenu
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
const SlideMenu = (props) => {
useEffect(() => {
window.addEventListener('click', props.closeMenu, false);
return () => {
- 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"