-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
devopsAnything to do with development operationsAnything to do with development operations
Description
[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
StatusCodesenum (e.g.,StatusCodes.OKinstead of200)
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
- Acceptance criteria met
- PR Reviewed (For non-trivial changes)
- Changes tested after rebasing on master or merging in master (hint:
git fetch origin master:master, thengit rebase masterorgit merge master) - All required PR checks passing
Metadata
Metadata
Assignees
Labels
devopsAnything to do with development operationsAnything to do with development operations