[DevOps] Create ESLint rule to prevent usage of "magic number" status codes
Description
We need to implement an ESLint rule that prevents direct usage of numeric HTTP status codes in our codebase. Instead, developers should use the StatusCodes enum from the http-status-codes library.
Current Problem
In our codebase, there are instances where HTTP status codes are used directly as numbers (e.g., this.setStatus(200) or response.status(404)). These "magic numbers" reduce code readability and maintainability.
Expected Solution
- Create a custom ESLint rule that detects and flags direct usage of numeric HTTP status codes
- The rule should warn or error when numbers like 200, 201, 400, 404, etc. are used with
setStatus(), response.status(), or similar methods
- The rule should suggest using the appropriate constant from
StatusCodes enum (e.g., StatusCodes.OK instead of 200)
Examples
❌ Disallowed:
this.setStatus(200);
response.status(404).send('Not found');
✅ Allowed:
this.setStatus(StatusCodes.OK);
response.status(StatusCodes.NOT_FOUND).send('Not found');
Implementation Notes
- Focus on common HTTP methods that set status codes
- Consider using an ESLint no-restricted-syntax or no-magic-numbers rule with appropriate configuration
- The rule should also work with Express-style response handling
Acceptance Criteria
- ESLint rule correctly identifies magic number HTTP status codes
- Rule provides helpful error messages with suggestions for the correct StatusCodes constant
- Documentation for the rule is added to our development guidelines
- Existing codebase passes with the new rule (after necessary refactoring)
BEFORE MERGING
[DevOps] Create ESLint rule to prevent usage of "magic number" status codes
Description
We need to implement an ESLint rule that prevents direct usage of numeric HTTP status codes in our codebase. Instead, developers should use the
StatusCodesenum from thehttp-status-codeslibrary.Current Problem
In our codebase, there are instances where HTTP status codes are used directly as numbers (e.g.,
this.setStatus(200)orresponse.status(404)). These "magic numbers" reduce code readability and maintainability.Expected Solution
setStatus(),response.status(), or similar methodsStatusCodesenum (e.g.,StatusCodes.OKinstead of200)Examples
❌ Disallowed:
✅ Allowed:
Implementation Notes
Acceptance Criteria
BEFORE MERGING
git fetch origin master:master, thengit rebase masterorgit merge master)