File size: 1,298 Bytes
49e53ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict";
var _definerule = require("../utils/define-rule");
var url = "https://nextjs.org/docs/messages/no-sync-scripts";
module.exports = (0, _definerule.defineRule)({
    meta: {
        docs: {
            description: "Prevent synchronous scripts.",
            recommended: true,
            url: url
        },
        type: "problem",
        schema: []
    },
    create: function create(context) {
        return {
            JSXOpeningElement: function JSXOpeningElement(node) {
                if (node.name.name !== "script") {
                    return;
                }
                if (node.attributes.length === 0) {
                    return;
                }
                var attributeNames = node.attributes.filter(function(attr) {
                    return attr.type === "JSXAttribute";
                }).map(function(attr) {
                    return attr.name.name;
                });
                if (attributeNames.includes("src") && !attributeNames.includes("async") && !attributeNames.includes("defer")) {
                    context.report({
                        node: node,
                        message: "Synchronous scripts should not be used. See: ".concat(url)
                    });
                }
            }
        };
    }
});