ahbeng/NUSMods

View on GitHub

Showing 212 of 556 total issues

Function setItem has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function setItem(key: string, value: unknown) {
  try {
    getLocalStorage().setItem(key, isString(value) ? value : JSON.stringify(value));
  } catch (e) {
    // Calculate used size and attach it to the error report. This is diagnostics
Severity: Minor
Found in website/src/storage/index.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 getWeatherIcon has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

export default function getWeatherIcon(description: string) {
  const cleanedDesc = description.toLowerCase().replace(/[^a-z ]+/g, '');

  // Fair (Day), Fair (Night), Fair & Warm
  if (cleanedDesc.includes('fair')) {
Severity: Minor
Found in website/src/views/components/icons/weather.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 CustomModuleFormComponent has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

export const CustomModuleFormComponent: React.FC<Props> = (props) => {
  // We use an uncontrolled form here because we don't want to update the
  // module title and MCs live
  const inputModuleCredit = React.createRef<HTMLInputElement>();
  const inputTitle = React.createRef<HTMLInputElement>();
Severity: Minor
Found in website/src/views/planner/CustomModuleForm.tsx - 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 combineModules has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

export function combineModules(
  semesters: SemesterModuleData[][],
  aliases: { [moduleCode: string]: ModuleCode[] },
  logger: Logger,
): ModuleWithoutTree[] {
Severity: Minor
Found in scrapers/nus-v2/src/tasks/CollateModules.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 MpeContainer has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

const MpeContainer: React.FC = () => {
  const [isGettingSSOLink, setIsGettingSSOLink] = useState(false);
  const [isModalOpen, setIsModalOpen] = useState(false);
  const [isLoggedIn, setIsLoggedIn] = useState(getLoginState(useLocation(), useHistory()));

Severity: Minor
Found in website/src/views/mpe/MpeContainer.tsx - 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 app has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function app(state: AppState = defaultAppState(), action: Actions): AppState {
  switch (action.type) {
    case SELECT_SEMESTER:
      return {
        ...state,
Severity: Minor
Found in website/src/reducers/app.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 renderPlaceholderForm has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  const renderPlaceholderForm = () => {
    const { placeholder, moduleCode, moduleTitle, semester } = props;

    if (!placeholder) return null;

Severity: Minor
Found in website/src/views/planner/PlannerModule.tsx - About 1 hr to fix

    Function programs_values has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

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

      Function course_items has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

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

        Function renderModuleActions has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          const renderModuleActions = (module: ModuleWithColor) => {
            const hideBtnLabel = `${module.hiddenInTimetable ? 'Show' : 'Hide'} ${module.moduleCode}`;
            const removeBtnLabel = `Remove ${module.moduleCode} from timetable`;
            const { semester } = props;
        
        
        Severity: Minor
        Found in website/src/views/timetable/TimetableModulesTable.tsx - About 1 hr to fix

          Function requestMiddleware has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            () => (next) => (action) => {
              if (!action.meta || !action.meta[API_REQUEST]) {
                // Non-api request action
                return next(action);
              }
          Severity: Minor
          Found in website/src/middlewares/requests-middleware.ts - About 1 hr to fix

            Function plan_types has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

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

              Function programs has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

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

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

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

                  Function makeExportHandler has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export function makeExportHandler<T>(
                    parseExportData: (request: VercelRequest) => T,
                    performExport: (response: VercelResponse, page: Page, data: T) => void | Promise<void>,
                  ): VercelApiHandler {
                    return async function handler(request, response) {
                  Severity: Minor
                  Found in export/src/handler.ts - About 1 hr to fix

                    Function TimetableRow has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    const TimetableRow: React.FC<Props> = (props) => {
                      const { startingIndex, endingIndex, lessons, onModifyCell, verticalMode } = props;
                      const totalCols = endingIndex - startingIndex;
                    
                      let lastStartIndex = startingIndex;
                    Severity: Minor
                    Found in website/src/views/timetable/TimetableRow.tsx - About 1 hr to fix

                      Function BetaToggle has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      const BetaToggle = memo<Props>((props) => {
                        const { betaTester, toggleStates } = props;
                        const hasTests = currentTests.length > 0;
                      
                        // If the user isn't a beta tester already and there are no tests, then
                      Severity: Minor
                      Found in website/src/views/settings/BetaToggle.tsx - About 1 hr to fix

                        Function binop has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public binop(): BinopContext {
                                let _localctx: BinopContext = new BinopContext(this._ctx, this.state);
                                this.enterRule(_localctx, 6, NusModsParser.RULE_binop);
                                try {
                                    this.state = 84;
                        Severity: Minor
                        Found in scrapers/nus-v2/src/services/requisite-tree/antlr4/NusModsParser.ts - About 1 hr to fix

                          Function GlobalSearchContainer has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          const GlobalSearchContainer: FC = () => {
                            const dispatch = useDispatch();
                            useEffect(() => {
                              dispatch(fetchVenueList());
                            }, [dispatch]);
                          Severity: Minor
                          Found in website/src/views/layout/GlobalSearchContainer.tsx - About 1 hr to fix

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

                                public subject_years(): Subject_yearsContext {
                                    let _localctx: Subject_yearsContext = new Subject_yearsContext(this._ctx, this.state);
                                    this.enterRule(_localctx, 26, NusModsParser.RULE_subject_years);
                                    let _la: number;
                                    try {
                            Severity: Minor
                            Found in scrapers/nus-v2/src/services/requisite-tree/antlr4/NusModsParser.ts - About 1 hr to fix
                              Severity
                              Category
                              Status
                              Source
                              Language