source: imaps-frontend/node_modules/eslint/lib/rules/no-script-url.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[d565449]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
9const astUtils = require("./utils/ast-utils");
10
11//------------------------------------------------------------------------------
12// Rule Definition
13//------------------------------------------------------------------------------
14
15/** @type {import('../shared/types').Rule} */
16module.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.