Skip to content

Commit 4202097

Browse files
eslint: ban direct imports of platform-aliased files
The webpack/tsconfig aliases for backend, contentSources, and useGetEnvironment resolve to different index files per build target. Importing the platform-specific files directly bypasses this switching and can silently break the cockpit build. The rule is disabled for the alias test directories that legitimately test both variants. Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
1 parent b880b4e commit 4202097

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

eslint.config.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ module.exports = defineConfig([
9696
ignoreMemberSort: false,
9797
}],
9898
'no-duplicate-imports': 'error',
99+
'prefer-const': ['error', {
100+
destructuring: 'any',
101+
}],
99102
// NOTE: we can enable this after the revamp and after summit. We can live with
100103
// the mixture of alias imports and relative imports. We can then enable the warning
101104
// or maybe errors (after summit). We can slowly migrate during the revamp, but adding
@@ -106,8 +109,18 @@ module.exports = defineConfig([
106109
// message: 'Avoid deep relative imports (../../ or deeper). Use @/ alias instead.',
107110
// }],
108111
// }],
109-
'prefer-const': ['error', {
110-
destructuring: 'any',
112+
'no-restricted-imports': ['error', {
113+
patterns: [{
114+
group: [
115+
'**/store/api/backend/index.hosted*',
116+
'**/store/api/backend/index.onprem*',
117+
'**/store/api/contentSources/index.hosted*',
118+
'**/store/api/contentSources/index.onprem*',
119+
'**/Utilities/useGetEnvironment/index.hosted*',
120+
'**/Utilities/useGetEnvironment/index.onprem*',
121+
],
122+
message: 'Import from the alias (e.g. @/store/api/backend) instead of the platform-specific file directly. Webpack/tsconfig aliases handle platform switching.',
123+
}],
111124
}],
112125
'no-console': 'error',
113126
'eqeqeq': 'error',
@@ -186,5 +199,16 @@ module.exports = defineConfig([
186199
},
187200
},
188201

202+
{ // Allow direct imports of platform-specific files in their own tests
203+
files: [
204+
'src/store/api/backend/tests/**',
205+
'src/store/api/contentSources/tests/**',
206+
'src/Utilities/useGetEnvironment/tests/**',
207+
],
208+
rules: {
209+
'no-restricted-imports': 'off',
210+
},
211+
},
212+
189213
prettierConfig,
190214
]);

0 commit comments

Comments
 (0)