-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow url constructor patched value
- Loading branch information
1 parent
a55cad3
commit 7f85aa9
Showing
3 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} | ||
}) | ||
} | ||
}, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters