Skip to content

Commit

Permalink
Disallow url constructor patched value
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Apr 5, 2023
1 parent a55cad3 commit 7f85aa9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ module.exports = {
rules: {
'local-rules/disallow-side-effects': 'error',
'local-rules/disallow-zone-js-patched-values': 'error',
'local-rules/disallow-url-constructor-patched-values': 'error',
'no-restricted-syntax': [
'error',
{
Expand Down
29 changes: 29 additions & 0 deletions eslint-local-rules/disallowUrlConstructorPatchValues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
meta: {
docs: {
description: 'Disallow problematic URL constructor patched values.',
recommended: false,
},
schema: [],
},

create(context) {
return {
'Program:exit'(node) {
const globalScope = context.getScope(node)
const variable = globalScope.set.get('URL')

if (variable && variable.defs.length === 0) {
variable.references.forEach((ref) => {
const idNode = ref.identifier
const parent = idNode.parent

if (parent && parent.type === 'NewExpression' && parent.callee === idNode) {
context.report(idNode, 'This value might be patched. Use `buildUrl` from @datadog/browser-core instead')
}
})
}
},
}
},
}
1 change: 1 addition & 0 deletions eslint-local-rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'disallow-protected-directory-import': require('./disallowProtectedDirectoryImport'),
'disallow-test-import-export-from-src': require('./disallowTestImportExportFromSrc'),
'disallow-zone-js-patched-values': require('./disallowZoneJsPatchedValues'),
'disallow-url-constructor-patched-values': require('./disallowUrlConstructorPatchValues.js'),
'disallow-generic-utils': require('./disallowGenericUtils'),
'secure-command-execution': require('./secureCommandExecution'),
}

0 comments on commit 7f85aa9

Please sign in to comment.