es-builtins.js 5.46 KB
Newer Older
liang ce committed
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
/**
 * @author Toru Nagashima
 * See LICENSE file in root directory for full license.
 */
"use strict"

const { READ } = require("eslint-utils")
const checkUnsupportedBuiltins = require("../../util/check-unsupported-builtins")
const enumeratePropertyNames = require("../../util/enumerate-property-names")

const trackMap = {
    globals: {
        Array: {
            from: { [READ]: { supported: "4.0.0" } },
            of: { [READ]: { supported: "4.0.0" } },
        },
        Map: {
            [READ]: { supported: "0.12.0" },
        },
        Math: {
            acosh: { [READ]: { supported: "0.12.0" } },
            asinh: { [READ]: { supported: "0.12.0" } },
            atanh: { [READ]: { supported: "0.12.0" } },
            cbrt: { [READ]: { supported: "0.12.0" } },
            clz32: { [READ]: { supported: "0.12.0" } },
            cosh: { [READ]: { supported: "0.12.0" } },
            expm1: { [READ]: { supported: "0.12.0" } },
            fround: { [READ]: { supported: "0.12.0" } },
            hypot: { [READ]: { supported: "0.12.0" } },
            imul: { [READ]: { supported: "0.12.0" } },
            log10: { [READ]: { supported: "0.12.0" } },
            log1p: { [READ]: { supported: "0.12.0" } },
            log2: { [READ]: { supported: "0.12.0" } },
            sign: { [READ]: { supported: "0.12.0" } },
            sinh: { [READ]: { supported: "0.12.0" } },
            tanh: { [READ]: { supported: "0.12.0" } },
            trunc: { [READ]: { supported: "0.12.0" } },
        },
        Number: {
            EPSILON: { [READ]: { supported: "0.12.0" } },
            isFinite: { [READ]: { supported: "0.10.0" } },
            isInteger: { [READ]: { supported: "0.12.0" } },
            isNaN: { [READ]: { supported: "0.10.0" } },
            isSafeInteger: { [READ]: { supported: "0.12.0" } },
            MAX_SAFE_INTEGER: { [READ]: { supported: "0.12.0" } },
            MIN_SAFE_INTEGER: { [READ]: { supported: "0.12.0" } },
            parseFloat: { [READ]: { supported: "0.12.0" } },
            parseInt: { [READ]: { supported: "0.12.0" } },
        },
        Object: {
            assign: { [READ]: { supported: "4.0.0" } },
            getOwnPropertySymbols: { [READ]: { supported: "0.12.0" } },
            is: { [READ]: { supported: "0.10.0" } },
            setPrototypeOf: { [READ]: { supported: "0.12.0" } },
            values: { [READ]: { supported: "7.0.0" } },
            entries: { [READ]: { supported: "7.0.0" } },
            getOwnPropertyDescriptors: { [READ]: { supported: "7.0.0" } },
        },
        Promise: {
            [READ]: { supported: "0.12.0" },
        },
        Proxy: {
            [READ]: { supported: "6.0.0" },
        },
        Reflect: {
            [READ]: { supported: "6.0.0" },
        },
        Set: {
            [READ]: { supported: "0.12.0" },
        },
        String: {
            fromCodePoint: { [READ]: { supported: "4.0.0" } },
            raw: { [READ]: { supported: "4.0.0" } },
        },
        Symbol: {
            [READ]: { supported: "0.12.0" },
        },
        Int8Array: {
            [READ]: { supported: "0.10.0" },
        },
        Uint8Array: {
            [READ]: { supported: "0.10.0" },
        },
        Uint8ClampedArray: {
            [READ]: { supported: "0.10.0" },
        },
        Int16Array: {
            [READ]: { supported: "0.10.0" },
        },
        Uint16Array: {
            [READ]: { supported: "0.10.0" },
        },
        Int32Array: {
            [READ]: { supported: "0.10.0" },
        },
        Uint32Array: {
            [READ]: { supported: "0.10.0" },
        },
        Float32Array: {
            [READ]: { supported: "0.10.0" },
        },
        Float64Array: {
            [READ]: { supported: "0.10.0" },
        },
        DataView: {
            [READ]: { supported: "0.10.0" },
        },
        WeakMap: {
            [READ]: { supported: "0.12.0" },
        },
        WeakSet: {
            [READ]: { supported: "0.12.0" },
        },
        Atomics: {
            [READ]: { supported: "8.10.0" },
        },
        SharedArrayBuffer: {
            [READ]: { supported: "8.10.0" },
        },
    },
}

module.exports = {
    meta: {
        docs: {
            description:
                "disallow unsupported ECMAScript built-ins on the specified version",
            category: "Possible Errors",
            recommended: true,
            url:
                "https://github.com/mysticatea/eslint-plugin-node/blob/v8.0.1/docs/rules/no-unsupported-features/es-builtins.md",
        },
        type: "problem",
        fixable: null,
        schema: [
            {
                type: "object",
                properties: {
                    version: {
                        type: "string",
                    },
                    ignores: {
                        type: "array",
                        items: {
                            enum: Array.from(
                                enumeratePropertyNames(trackMap.globals)
                            ),
                        },
                        uniqueItems: true,
                    },
                },
                additionalProperties: false,
            },
        ],
        messages: {
            unsupported:
                "The '{{name}}' is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
        },
    },
    create(context) {
        return {
            "Program:exit"() {
                checkUnsupportedBuiltins(context, trackMap)
            },
        }
    },
}