Skip to content

Commit

Permalink
🐛[RUMF-1517] Remove specHelper export in src code (#2126)
Browse files Browse the repository at this point in the history
* add local-rules/disallow-test-import-export-from-src

* remove observers.specHelper exports
  • Loading branch information
bcaudan authored Apr 4, 2023
1 parent 59e334c commit 4e0e5d7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ module.exports = {
'jsdoc/check-alignment': 'error',
'jsdoc/check-indentation': 'error',

'local-rules/disallow-test-import-export-from-src': 'error',
'local-rules/disallow-protected-directory-import': [
'error',
{
Expand Down
36 changes: 36 additions & 0 deletions eslint-local-rules/disallowTestImportExportFromSrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
meta: {
docs: {
description:
'Disallow importing or exporting test code in src code to avoid bloating customer package with test code',
recommended: false,
},
schema: [],
},
create(context) {
return {
ImportDeclaration(node) {
checkTestImportExportFromSrc(context, node)
},
ExportNamedDeclaration(node) {
checkTestImportExportFromSrc(context, node)
},
ExportAllDeclaration(node) {
checkTestImportExportFromSrc(context, node)
},
}
},
}

function checkTestImportExportFromSrc(context, node) {
if (!isTestCode(context.getFilename()) && node.source && isTestCode(node.source.value)) {
context.report({
node: node.source,
message: 'Test code import or export is not allowed in src code',
})
}
}

function isTestCode(filename) {
return /(\/test|\.specHelper|\.spec)/.test(filename)
}
1 change: 1 addition & 0 deletions eslint-local-rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
'disallow-enum-exports': require('./disallowEnumExports'),
'disallow-spec-import': require('./disallowSpecImport'),
'disallow-protected-directory-import': require('./disallowProtectedDirectoryImport'),
'disallow-test-import-export-from-src': require('./disallowTestImportExportFromSrc'),
'disallow-zone-js-patched-values': require('./disallowZoneJsPatchedValues'),
'secure-command-execution': require('./secureCommandExecution'),
}
2 changes: 0 additions & 2 deletions packages/rum/src/domain/record/observers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export { initObservers } from './observers'
export { InputCallback, initInputObserver } from './inputObserver'
export { initMutationObserver, MutationCallBack, RumMutationRecord } from './mutationObserver'
export { DEFAULT_CONFIGURATION } from './observers.specHelper'
export { DEFAULT_SHADOW_ROOT_CONTROLLER } from './observers.specHelper'

0 comments on commit 4e0e5d7

Please sign in to comment.