chore: prevent importing theme components with relative paths (#7674)

This commit is contained in:
Sébastien Lorber 2022-06-24 17:22:44 +02:00 committed by GitHub
parent 2c7012f706
commit 90a8ca387e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 31 deletions

49
.eslintrc.js vendored
View file

@ -9,6 +9,18 @@ const OFF = 0;
const WARNING = 1;
const ERROR = 2;
const ClientRestrictedImportPatterns = [
// Prevent importing lodash in client bundle for bundle size
'lodash',
'lodash.**',
'lodash/**',
// Prevent importing server code in client bundle
'**/../babel/**',
'**/../server/**',
'**/../commands/**',
'**/../webpack/**',
];
module.exports = {
root: true,
env: {
@ -371,25 +383,32 @@ module.exports = {
},
overrides: [
{
files: [
'packages/docusaurus-*/src/theme/**/*.{js,ts,tsx}',
'packages/docusaurus/src/client/**/*.{js,ts,tsx}',
],
files: ['packages/docusaurus/src/client/**/*.{js,ts,tsx}'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
// Prevent importing lodash in client bundle for bundle size
'lodash',
'lodash.**',
'lodash/**',
// Prevent importing server code in client bundle
'**/../babel/**',
'**/../server/**',
'**/../commands/**',
'**/../webpack/**',
],
patterns: ClientRestrictedImportPatterns,
},
],
},
},
{
files: ['packages/docusaurus-*/src/theme/**/*.{js,ts,tsx}'],
excludedFiles: '*.test.{js,ts,tsx}',
rules: {
'no-restricted-imports': [
'error',
{
patterns: ClientRestrictedImportPatterns.concat(
// Prevents relative imports between React theme components
[
'../**',
'./**',
// Allows relative styles module import with consistent filename
'!./styles.module.css',
],
),
},
],
},