ahbeng/NUSMods

View on GitHub

Showing 212 of 556 total issues

Function handler has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  return async function handler(request, response) {
    try {
      throwIfAcademicYearNotSet();
      setUpSentry();

Severity: Minor
Found in export/src/handler.ts - About 1 hr to fix

    Function fetchModule has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function fetchModule(moduleCode: ModuleCode) {
      return (dispatch: Dispatch, getState: GetState) => {
        const onFinally = () => {
          // Update the timestamp of the accessed module if it is in the store.
          if (getState().moduleBank.modules[moduleCode]) {
    Severity: Minor
    Found in website/src/actions/moduleBank.ts - About 1 hr to fix

      Function run has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async run(): Promise<Output> {
          this.logger.info(
            `Getting exams for all modules in ${this.academicYear} semester ${this.semester}`,
          );
          const term = getTermCode(this.semester, this.academicYear);
      Severity: Minor
      Found in scrapers/nus-v2/src/tasks/GetSemesterExams.ts - About 1 hr to fix

        Function Announcements has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const Announcements = memo(() => {
          const [isOpen, setIsOpen] = useState(() => {
            if (!enableAnnouncements) return false;
            if (key) return !storage.getItem(key);
            return true;
        Severity: Minor
        Found in website/src/views/components/notfications/Announcements.tsx - About 1 hr to fix

          Function courses has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public courses(): CoursesContext {
                  let _localctx: CoursesContext = new CoursesContext(this._ctx, this.state);
                  this.enterRule(_localctx, 36, NusModsParser.RULE_courses);
                  let _la: number;
                  try {
          Severity: Minor
          Found in scrapers/nus-v2/src/services/requisite-tree/antlr4/NusModsParser.ts - About 1 hr to fix

            Function checkPrerequisite has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function checkPrerequisite(moduleSet: Set<ModuleCode>, tree: PrereqTree): PrereqTree[] {
              const moduleArray = Array.from(moduleSet);
            
              function walkTree(fragment: PrereqTree): PrereqTree[] {
                if (typeof fragment === 'string') {
            Severity: Minor
            Found in website/src/utils/planner.ts - About 1 hr to fix

              Function Tree has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const Tree: React.FC<TreeDisplay> = (props) => {
                const { layer, node, isPrereq } = props;
              
                const isConditional = typeof node !== 'string';
                const { prefix, name } = nodeName(node);
              Severity: Minor
              Found in website/src/views/modules/ModuleTree.tsx - About 1 hr to fix

                Function renderModule has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  const renderModule = (module: ModuleWithColor) => {
                    const { semester, readOnly, tombstone, resetTombstone } = props;
                
                    if (tombstone && tombstone.moduleCode === module.moduleCode) {
                      return <ModuleTombstone module={module} resetTombstone={resetTombstone} />;
                Severity: Minor
                Found in website/src/views/timetable/TimetableModulesTable.tsx - About 1 hr to fix

                  Function ButtonGroupSelector has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  const ButtonGroupSelector: React.FC<Props> = (props) => {
                    const {
                      size,
                      choices,
                      selectedChoice,
                  Severity: Minor
                  Found in website/src/views/components/ButtonGroupSelector.tsx - About 1 hr to fix

                    Function renderLesson has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      const renderLesson = (lesson: ColoredLesson, i: number) => {
                        const { openLesson, onOpenLesson, marker, date } = props;
                    
                        const isOpen =
                          !!openLesson && isSameDay(openLesson.date, date) && isSameLesson(openLesson.lesson, lesson);
                    Severity: Minor
                    Found in website/src/views/today/DayEvents.tsx - About 1 hr to fix

                      Function getAcadWeekName has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      export function getAcadWeekName(acadWeekNumber: number): AcadWeek | null {
                        switch (acadWeekNumber) {
                          case 7:
                            return {
                              weekType: 'Recess',
                      Severity: Minor
                      Found in packages/nusmoderator/src/academicCalendar.ts - About 1 hr to fix

                        Function formatWeekRange has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        function formatWeekRange(weekRange: WeekRange) {
                          const start = parseISO(weekRange.start);
                        
                          // Start = end means there's just one lesson
                          if (weekRange.start === weekRange.end) return format(start, lessonDateFormat);
                        Severity: Minor
                        Found in website/src/views/timetable/TimetableCell.tsx - About 1 hr to fix

                          Function must_be_in has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public must_be_in(): Must_be_inContext {
                                  let _localctx: Must_be_inContext = new Must_be_inContext(this._ctx, this.state);
                                  this.enterRule(_localctx, 40, NusModsParser.RULE_must_be_in);
                                  let _la: number;
                                  try {
                          Severity: Minor
                          Found in scrapers/nus-v2/src/services/requisite-tree/antlr4/NusModsParser.ts - About 1 hr to fix

                            Function must_not_be_in has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public must_not_be_in(): Must_not_be_inContext {
                                    let _localctx: Must_not_be_inContext = new Must_not_be_inContext(this._ctx, this.state);
                                    this.enterRule(_localctx, 42, NusModsParser.RULE_must_not_be_in);
                                    let _la: number;
                                    try {
                            Severity: Minor
                            Found in scrapers/nus-v2/src/services/requisite-tree/antlr4/NusModsParser.ts - About 1 hr to fix

                              Function boolean_expr has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  public boolean_expr(): Boolean_exprContext {
                                      let _localctx: Boolean_exprContext = new Boolean_exprContext(this._ctx, this.state);
                                      this.enterRule(_localctx, 8, NusModsParser.RULE_boolean_expr);
                                      let _la: number;
                                      try {
                              Severity: Minor
                              Found in scrapers/nus-v2/src/services/requisite-tree/antlr4/NusModsParser.ts - About 1 hr to fix

                                Function iterateBoard has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                Open

                                function iterateBoard(
                                  board: Board,
                                  iterator: (tile: Square, col: number, row: number) => boolean | void,
                                ) {
                                  let continueIterating = true;
                                Severity: Minor
                                Found in website/src/views/tetris/board.ts - About 1 hr 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 requests has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                export default function requests(state: Requests = {}, action: FSA): Requests {
                                  const { meta } = action;
                                
                                  // requestStatus is a field specially designed and owned by api request actions
                                  if (!meta || !meta.requestStatus || !meta[API_REQUEST]) {
                                Severity: Minor
                                Found in website/src/reducers/requests.ts - About 1 hr to fix

                                  Function downloadBusStops has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  async function downloadBusStops() {
                                    const busStopResponse = await axios.get(getBusStop);
                                    const data = busStopResponse.data.BusStopsResult.busstops;
                                  
                                    // Map bus stops to the correct shape
                                  Severity: Minor
                                  Found in website/scripts/download-bus-stops.js - About 1 hr to fix

                                    Function special has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        public special(): SpecialContext {
                                            let _localctx: SpecialContext = new SpecialContext(this._ctx, this.state);
                                            this.enterRule(_localctx, 28, NusModsParser.RULE_special);
                                            try {
                                                this.enterOuterAlt(_localctx, 1);
                                    Severity: Minor
                                    Found in scrapers/nus-v2/src/services/requisite-tree/antlr4/NusModsParser.ts - About 1 hr to fix

                                      Function run has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                        async run() {
                                          try {
                                            const [departments, faculties] = await Promise.all([
                                              this.api.getDepartment(),
                                              this.api.getFaculty(),
                                      Severity: Minor
                                      Found in scrapers/nus-v2/src/tasks/TestApi.ts - About 1 hr to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language