feat(eslint-plugin): add no-hardcoded-src rule #11489
Open
+102
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pre-flight checklist
Motivation
This pull request adds the new
no-hardcoded-srcESLint 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
RuleTestersetup, 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 runningyarn test, and the project builds successfully withyarn build.