|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.7 KB
|
| Rev | Line | |
|---|
| [9af201e] | 1 | /**
|
|---|
| 2 | * @fileoverview Rule to flag when using javascript: urls
|
|---|
| 3 | * @author Ilya Volodin
|
|---|
| 4 | */
|
|---|
| 5 | /* eslint no-script-url: 0 -- Code is checking to report such URLs */
|
|---|
| 6 |
|
|---|
| 7 | "use strict";
|
|---|
| 8 |
|
|---|
| 9 | const astUtils = require("./utils/ast-utils");
|
|---|
| 10 |
|
|---|
| 11 | //------------------------------------------------------------------------------
|
|---|
| 12 | // Rule Definition
|
|---|
| 13 | //------------------------------------------------------------------------------
|
|---|
| 14 |
|
|---|
| 15 | /** @type {import('../shared/types').Rule} */
|
|---|
| 16 | module.exports = {
|
|---|
| 17 | meta: {
|
|---|
| 18 | type: "suggestion",
|
|---|
| 19 |
|
|---|
| 20 | docs: {
|
|---|
| 21 | description: "Disallow `javascript:` urls",
|
|---|
| 22 | recommended: false,
|
|---|
| 23 | url: "https://eslint.org/docs/latest/rules/no-script-url"
|
|---|
| 24 | },
|
|---|
| 25 |
|
|---|
| 26 | schema: [],
|
|---|
| 27 |
|
|---|
| 28 | messages: {
|
|---|
| 29 | unexpectedScriptURL: "Script URL is a form of eval."
|
|---|
| 30 | }
|
|---|
| 31 | },
|
|---|
| 32 |
|
|---|
| 33 | create(context) {
|
|---|
| 34 |
|
|---|
| 35 | /**
|
|---|
| 36 | * Check whether a node's static value starts with "javascript:" or not.
|
|---|
| 37 | * And report an error for unexpected script URL.
|
|---|
| 38 | * @param {ASTNode} node node to check
|
|---|
| 39 | * @returns {void}
|
|---|
| 40 | */
|
|---|
| 41 | function check(node) {
|
|---|
| 42 | const value = astUtils.getStaticStringValue(node);
|
|---|
| 43 |
|
|---|
| 44 | if (typeof value === "string" && value.toLowerCase().indexOf("javascript:") === 0) {
|
|---|
| 45 | context.report({ node, messageId: "unexpectedScriptURL" });
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 | return {
|
|---|
| 49 | Literal(node) {
|
|---|
| 50 | if (node.value && typeof node.value === "string") {
|
|---|
| 51 | check(node);
|
|---|
| 52 | }
|
|---|
| 53 | },
|
|---|
| 54 | TemplateLiteral(node) {
|
|---|
| 55 | if (!(node.parent && node.parent.type === "TaggedTemplateExpression")) {
|
|---|
| 56 | check(node);
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 | };
|
|---|
| 60 | }
|
|---|
| 61 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.