feat(eslint-plugin): add no-hardcoded-src rule
Pre-flight checklist
- [x] I have read the Contributing Guidelines on pull requests.
- [x] I have written unit tests to fully verify the new behavior.
- [x] This PR has an accompanying issue (#6472) and I'm tackling one of the unchecked items.
Motivation
This pull request adds the new no-hardcoded-src ESLint rule, as proposed in issue #6472. The goal is to prevent hardcoded image paths to ensure assets work correctly across different site configurations.
Difference from Previous PR
This is a new, clean pull request to replace my previous attempt in #11486.
My apologies for the messy state of the first PR. I wrote the initial implementation and tests myself, but I ran into some complex TypeScript errors with the RuleTester setup, specifically around the parser configuration.
To debug those errors, I used an AI assistant for help. While it fixed the type issue, it also incorrectly introduced many unrelated changes to configuration files (package.json, jest.config.js), which I failed to catch before submitting.
After reviewing your feedback, I researched the project's testing setup more carefully and found the correct pattern used by other ESLint rules in the repository. This new pull request contains only the two necessary files (the rule and its test) and is free of any unrelated configuration changes.
Test Plan
I've added a new test suite for the rule at packages/eslint-plugin/src/rules/__tests__/no-hardcoded-src.test.ts. All tests are passing locally after running yarn test, and the project builds successfully with yarn build.
[V2]
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | f7826961f107b1f020f2ad942fbd355c16d61870 |
| Latest deploy log | https://app.netlify.com/projects/docusaurus-2/deploys/68f135cb35451800081ed385 |
| Deploy Preview | https://deploy-preview-11489--docusaurus-2.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.
@slorber Just a friendly reminder about this PR. I would appreciate it if you could take a look when you have a moment. Thanks!