WikiEducationFoundation/WikiEduDashboard

View on GitHub

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
};
app/assets/javascripts/components/settings/views/featured_campaign.jsx on lines 30..34

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

Further Reading

Function searchForPages has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

  async searchForPages(wiki, search_term, namespace, map=(el)=>el, depth, limit=10){
Severity: Minor
Found in app/assets/javascripts/utils/api.js - About 45 mins to fix

    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);
    Severity: Minor
    Found in app/assets/javascripts/actions/news_action.js - About 45 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

    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)); }
    Severity: Minor
    Found in app/assets/javascripts/actions/assignment_actions.js - About 45 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

    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;
    Severity: Minor
    Found in app/assets/javascripts/styles/sort_select.js - About 45 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

    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
    Severity: Minor
    Found in app/assets/javascripts/utils/course_date_utils.js - About 45 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

    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) {
    Severity: Minor
    Found in app/assets/javascripts/utils/course_date_utils.js - About 45 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

    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)
        ) {
    Severity: Minor
    Found in app/assets/javascripts/utils/revision_utils.js - About 45 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

    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;
    Severity: Minor
    Found in app/assets/javascripts/styles/single_select.js - About 45 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

    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 });
    Severity: Minor
    Found in app/assets/javascripts/actions/revisions_actions.js - About 45 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

    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 = () => {
    Severity: Minor
    Found in app/assets/javascripts/components/user_profiles/instructor_stats.jsx - About 45 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

    Avoid deeply nested control flow statements.
    Open

                if (moveUp) {
                  const toWeekBlocks = this.getBlocksInWeek(toWeek.id);
                  atIndex = toWeekBlocks.length;
                }
    Severity: Major
    Found in app/assets/javascripts/components/timeline/timeline.jsx - About 45 mins to fix

      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(() => {
      Severity: Minor
      Found in app/assets/javascripts/components/common/namespace_select.jsx - About 45 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

      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);
      Severity: Minor
      Found in app/assets/javascripts/components/enroll/new_account_modal.jsx - About 45 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

      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

      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(
      Severity: Minor
      Found in app/assets/javascripts/components/course_creator/course_form.jsx - About 45 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

      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)})` : '';
      Severity: Minor
      Found in app/assets/javascripts/components/revisions/revision.jsx - About 45 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

      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) {
      Severity: Minor
      Found in app/assets/javascripts/components/common/calendar.jsx - About 45 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

      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) {
      Severity: Minor
      Found in app/assets/javascripts/components/tickets/reply.jsx - About 45 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

      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 () => {
      Severity: Minor
      Found in app/assets/javascripts/training/components/slide_menu.jsx - About 45 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

      Severity
      Category
      Status
      Source
      Language