Skip to content

Conversation

@sairamsharan
Copy link

@sairamsharan sairamsharan commented Oct 16, 2025

Pre-flight checklist

Motivation

This pull request adds a new ESLint rule, no-hardcoded-src, to the @docusaurus/eslint-plugin, as proposed in issue #6472.

The goal of this rule is to prevent developers from using hardcoded URLs in src attributes (like in <img> tags). Instead, it encourages the use of require() or useBaseUrl() so that images and assets work correctly across different base URLs and environments.

Test Plan

I have added a new test suite for this rule at packages/eslint-plugin/src/rules/__tests__/no-hardcoded-src.test.ts.

The tests cover both valid cases (using require(), useBaseUrl(), etc.) and invalid cases (using hardcoded strings), ensuring the rule works as expected.

I have verified the implementation by running all tests for the package, which passed successfully.

@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Oct 16, 2025
@netlify
Copy link

netlify bot commented Oct 16, 2025

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 3bc61d3
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/68f086fae5594d00083eac52
😎 Deploy Preview https://deploy-preview-11486--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

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 slorber changed the title Feat/eslint no hardcoded src feat(eslint): Add new no-hardcoded-src rule Oct 16, 2025
@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Oct 16, 2025
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

I'll review the rule/test later, but there are already things to change in this PR.

Was this PR created with AI? If so, you have to disclose it clearly.

"scripts": {
"build": "tsc"
"build": "tsc",
"test": "jest"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to add that

Comment on lines +29 to +32
"@types/eslint": "^9.6.1",
"@types/jest": "^30.0.0",
"eslint-plugin-eslint-plugin": "^5.1.0",
"ts-jest": "^29.4.5"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to add that

Comment on lines +1 to +8
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
moduleFileExtensions: ['ts', 'js'],
verbose: true,
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to add that

return advancedPreset;
};

// @ts-expect-error: TODO fix later
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to remove that


// To continue supporting `require('npm2yarn')` without the `.default` ㄟ(▔,▔)ㄏ
// TODO change to export default after migrating to ESM
// @ts-expect-error: Docusaurus v4: remove
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to remove that


import rules from './rules';

// @ts-expect-error: TODO try to remove later
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to remove that

"incremental": true,
"tsBuildInfoFile": "${configDir}/lib/.tsbuildinfo",
"erasableSyntaxOnly": true,
//"erasableSyntaxOnly": true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this necessary?

js-tokens "^4.0.0"
picocolors "^1.0.0"

"@babel/code-frame@^7.27.1":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't need to change deps?

@sairamsharan
Copy link
Author

Hi @slorber, thank you for the detailed feedback. You are right, the pull request included many unnecessary changes.

I wrote the initial implementation and tests for the no-hardcoded-src rule myself. When I ran into some build errors during the setup, I used an AI assistant to help me debug. It unfortunately introduced a lot of unrelated configuration changes, and I apologize for the messy pull request. I should have reviewed its changes more carefully.

To fix this, I have closed this PR and started over with a new, clean branch. The new pull request contains only the new rule and its test file, with no other changes.

Thank you again for your guidance and for helping me learn the correct process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants