Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @fileoverview Rule to flag when using javascript: urls |
| 3 | * @author Ilya Volodin |
| 4 | */ |
| 5 | /* jshint scripturl: true */ |
| 6 | /* eslint no-script-url: 0 */ |
| 7 | |
| 8 | "use strict"; |
| 9 | |
| 10 | //------------------------------------------------------------------------------ |
| 11 | // Rule Definition |
| 12 | //------------------------------------------------------------------------------ |
| 13 | |
| 14 | module.exports = { |
| 15 | meta: { |
| 16 | type: "suggestion", |
| 17 | |
| 18 | docs: { |
| 19 | description: "disallow `javascript:` urls", |
| 20 | category: "Best Practices", |
| 21 | recommended: false, |
| 22 | url: "https://eslint.org/docs/rules/no-script-url" |
| 23 | }, |
| 24 | |
| 25 | schema: [] |
| 26 | }, |
| 27 | |
| 28 | create(context) { |
| 29 | |
| 30 | return { |
| 31 | |
| 32 | Literal(node) { |
| 33 | if (node.value && typeof node.value === "string") { |
| 34 | const value = node.value.toLowerCase(); |
| 35 | |
| 36 | if (value.indexOf("javascript:") === 0) { |
| 37 | context.report({ node, message: "Script URL is a form of eval." }); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | } |
| 44 | }; |