tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

.eslintrc.mjs (14020B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 import globals from "globals";
      6 import react from "eslint-plugin-react";
      7 import mozilla from "eslint-plugin-mozilla";
      8 import importPlugin from "eslint-plugin-import";
      9 import jestPlugin from "eslint-plugin-jest";
     10 
     11 export default [
     12  {
     13    files: ["**/tests/**"],
     14    ...jestPlugin.configs["flat/recommended"],
     15  },
     16  {
     17    plugins: { jest: jestPlugin, react, mozilla, import: importPlugin },
     18    languageOptions: {
     19      parserOptions: {
     20        ecmaVersion: "latest",
     21        ecmaFeatures: { jsx: true },
     22      },
     23      sourceType: "module",
     24      globals: {
     25        ...globals.es6,
     26        ...globals.browser,
     27        ...globals.commonjs,
     28        ...globals.jest,
     29        atob: true,
     30        btoa: true,
     31        Cc: true,
     32        Ci: true,
     33        Components: true,
     34        console: true,
     35        Cr: true,
     36        Cu: true,
     37        devtools: true,
     38        dump: true,
     39        EventEmitter: true,
     40        isWorker: true,
     41        loader: true,
     42        Services: true,
     43        Task: true,
     44        XPCOMUtils: true,
     45        _Iterator: true,
     46        __dirname: true,
     47        process: true,
     48        global: true,
     49        L10N: true,
     50      },
     51    },
     52    rules: {
     53      // These are the rules that have been configured so far to match the
     54      // devtools coding style.
     55 
     56      // Rules from the mozilla plugin
     57      "mozilla/mark-test-function-used": "error",
     58      "mozilla/no-aArgs": "error",
     59      // See bug 1224289.
     60      "mozilla/reject-importGlobalProperties": "error",
     61      "mozilla/var-only-at-top-level": "error",
     62 
     63      // Rules from the React plugin
     64      "react/jsx-uses-react": "error",
     65      "react/jsx-uses-vars": "error",
     66      "react/no-danger": "error",
     67      "react/no-did-mount-set-state": "error",
     68      "react/no-did-update-set-state": "error",
     69      "react/no-direct-mutation-state": "error",
     70      "react/no-unknown-property": "error",
     71      "react/prop-types": "off",
     72      "react/sort-comp": [
     73        "error",
     74        {
     75          order: ["propTypes", "everything-else", "render"],
     76        },
     77      ],
     78 
     79      // Check for import errors.
     80      "import/no-duplicates": "error",
     81      "import/named": "error",
     82      "import/export": "error",
     83 
     84      // Adds compatibility with jest-in-case cases. See related GitHub issue
     85      // https://github.com/jest-community/eslint-plugin-jest/issues/534
     86      "jest/no-standalone-expect": [
     87        "error",
     88        { additionalTestBlockFunctions: ["cases"] },
     89      ],
     90 
     91      // Disallow flow control that escapes from "finally".
     92      "no-unsafe-finally": "error",
     93 
     94      // Disallow using variables outside the blocks they are defined (especially
     95      // since only let and const are used, see "no-var").
     96      "block-scoped-var": 2,
     97      // Require camel case names
     98      camelcase: ["error", { properties: "never" }],
     99      // Warn about cyclomatic complexity in functions.
    100      complexity: ["error", { max: 23 }],
    101      // Don't warn for inconsistent naming when capturing this (not so important
    102      // with auto-binding fat arrow functions).
    103      "consistent-this": 0,
    104      // Don't require a default case in switch statements. Avoid being forced to
    105      // add a bogus default when you know all possible cases are handled.
    106      "default-case": 0,
    107      // Encourage the use of dot notation whenever possible.
    108      "dot-notation": 2,
    109      // Allow using == instead of ===, in the interest of landing something since
    110      // the devtools codebase is split on convention here.
    111      eqeqeq: 0,
    112      // Don't require function expressions to have a name.
    113      // This makes the code more verbose and hard to read. Our engine already
    114      // does a fantastic job assigning a name to the function, which includes
    115      // the enclosing function name, and worst case you have a line number that
    116      // you can just look up.
    117      "func-names": 0,
    118      // Allow use of function declarations and expressions.
    119      "func-style": 0,
    120      // Deprecated, will be removed in 1.0.
    121      "global-strict": 0,
    122      // Only useful in a node environment.
    123      "handle-callback-err": 0,
    124      // Maximum depth callbacks can be nested.
    125      "max-nested-callbacks": [2, 4],
    126      // Don't limit the number of parameters that can be used in a function.
    127      "max-params": 0,
    128      // Don't limit the maximum number of statement allowed in a function. We
    129      // already have the complexity rule that's a better measurement.
    130      "max-statements": 0,
    131      // Require a capital letter for constructors, only check if all new
    132      // operators are followed by a capital letter. Don't warn when capitalized
    133      // functions are used without the new operator.
    134      "new-cap": [2, { capIsNew: false }],
    135      // Disallow use of the Array constructor.
    136      "no-array-constructor": 2,
    137      // Allow use of bitwise operators.
    138      "no-bitwise": 0,
    139      // Disallow use of arguments.caller or arguments.callee.
    140      "no-caller": 2,
    141      // Disallow the catch clause parameter name being the same as a variable in
    142      // the outer scope, to avoid confusion.
    143      "no-catch-shadow": 2,
    144      // Disallow assignment in conditional expressions.
    145      "no-cond-assign": 2,
    146      // Allow use of the continue statement.
    147      "no-continue": 0,
    148      // Disallow control characters in regular expressions.
    149      "no-control-regex": 2,
    150      // Disallow use of debugger.
    151      "no-debugger": 2,
    152      // Disallow deletion of variables (deleting properties is fine).
    153      "no-delete-var": 2,
    154      // Allow division operators explicitly at beginning of regular expression.
    155      "no-div-regex": 0,
    156      // Disallow duplicate arguments in functions.
    157      "no-dupe-args": 2,
    158      // Disallow a duplicate case label.
    159      "no-duplicate-case": 2,
    160      // Disallow else after a return in an if. The else around the second return
    161      // here is useless:
    162      // if (something) { return false; } else { return true; }
    163      "no-else-return": 2,
    164      // Disallow empty statements. This will report an error for:
    165      // try { something(); } catch (e) {}
    166      // but will not report it for:
    167      // try { something(); } catch (e) { /* Silencing the error because ...*/ }
    168      // which is a valid use case.
    169      "no-empty": 2,
    170      // Disallow the use of empty character classes in regular expressions.
    171      "no-empty-character-class": 2,
    172      // Disallow use of labels for anything other then loops and switches.
    173      "no-labels": 2,
    174      // Disallow use of eval(). We have other APIs to evaluate code in content.
    175      "no-eval": 2,
    176      // Disallow assigning to the exception in a catch block.
    177      "no-ex-assign": 2,
    178      // Disallow adding to native types
    179      "no-extend-native": 2,
    180      // Disallow unnecessary function binding.
    181      "no-extra-bind": 2,
    182      // Disallow double-negation boolean casts in a boolean context.
    183      "no-extra-boolean-cast": 2,
    184      // Deprecated, will be removed in 1.0.
    185      "no-extra-strict": 0,
    186      // Disallow comments inline after code.
    187      "no-inline-comments": 2,
    188      // Disallow if as the only statement in an else block.
    189      "no-lonely-if": 2,
    190      // Allow mixing regular variable and require declarations (not a node env).
    191      "no-mixed-requires": 0,
    192      // Disallow use of multiline strings (use template strings instead).
    193      "no-multi-str": 2,
    194      "prefer-template": "error",
    195      "prefer-const": [
    196        "error",
    197        {
    198          destructuring: "all",
    199          ignoreReadBeforeAssign: false,
    200        },
    201      ],
    202      // Disallow reassignments of native objects.
    203      "no-native-reassign": 2,
    204      // Disallow nested ternary expressions, they make the code hard to read.
    205      "no-nested-ternary": 2,
    206      // Allow use of new operator with the require function.
    207      "no-new-require": 0,
    208      // Disallow use of octal literals.
    209      "no-octal": 2,
    210      // Allow reassignment of function parameters.
    211      "no-param-reassign": 0,
    212      // Allow string concatenation with __dirname and __filename (not a node env).
    213      "no-path-concat": 0,
    214      // Allow use of unary operators, ++ and --.
    215      "no-plusplus": 0,
    216      // Allow using process.env (not a node environment).
    217      "no-process-env": 0,
    218      // Allow using process.exit (not a node environment).
    219      "no-process-exit": 0,
    220      // Disallow usage of __proto__ property.
    221      "no-proto": 2,
    222      // Disallow multiple spaces in a regular expression literal.
    223      "no-regex-spaces": 2,
    224      // Don't restrict usage of specified node modules (not a node environment).
    225      "no-restricted-modules": 0,
    226      // Disallow use of assignment in return statement. It is preferable for a
    227      // single line of code to have only one easily predictable effect.
    228      "no-return-assign": 2,
    229      // Allow use of javascript: urls.
    230      "no-script-url": 0,
    231      // Disallow comparisons where both sides are exactly the same.
    232      "no-self-compare": 2,
    233      // Disallow use of comma operator.
    234      "no-sequences": 2,
    235      // Disallow sparse arrays, eg. let arr = [,,2].
    236      // Array destructuring is fine though:
    237      // for (let [, breakpointPromise] of aPromises)
    238      "no-sparse-arrays": 2,
    239      // Allow use of synchronous methods (not a node environment).
    240      "no-sync": 0,
    241      // Allow the use of ternary operators.
    242      "no-ternary": 0,
    243      // Disallow throwing literals (eg. throw "error" instead of
    244      // throw new Error("error")).
    245      "no-throw-literal": 2,
    246      // Disallow use of undeclared variables unless mentioned in a /*global */
    247      // block. Note that globals from head.js are automatically imported in tests
    248      // by the import-headjs-globals rule form the mozilla eslint plugin.
    249      "no-undef": 2,
    250      // Allow dangling underscores in identifiers (for privates).
    251      "no-underscore-dangle": 0,
    252      // Allow use of undefined variable.
    253      "no-undefined": 0,
    254      // Disallow the use of Boolean literals in conditional expressions.
    255      "no-unneeded-ternary": 2,
    256      // Disallow unreachable statements after a return, throw, continue, or break
    257      // statement.
    258      "no-unreachable": 2,
    259      // Disallow global and local variables that arent used. Allow unused function arguments
    260      // that are prefixed with `_`.
    261      "no-unused-vars": [
    262        2,
    263        { vars: "all", caughtErrors: "none", argsIgnorePattern: "^_" },
    264      ],
    265      // Allow using variables before they are defined.
    266      "no-use-before-define": 0,
    267      // We use var-only-at-top-level instead of no-var as we allow top level
    268      // vars.
    269      "no-var": 0,
    270      // Allow using TODO/FIXME comments.
    271      "no-warning-comments": 0,
    272      // Allow more than one variable declaration per function.
    273      "one-var": 0,
    274      // Require use of the second argument for parseInt().
    275      radix: 2,
    276      // Dont require to sort variables within the same declaration block.
    277      // Anyway, one-var is disabled.
    278      "sort-vars": 0,
    279      // Require "use strict" to be defined globally in the script.
    280      strict: [2, "global"],
    281      // Disallow comparisons with the value NaN.
    282      "use-isnan": 2,
    283      // Ensure that the results of typeof are compared against a valid string.
    284      "valid-typeof": 2,
    285      // Allow vars to be declared anywhere in the scope.
    286      "vars-on-top": 0,
    287      // Disallow Yoda conditions (where literal value comes first).
    288      yoda: 2,
    289 
    290      // And these are the rules that haven't been discussed so far, and that are
    291      // disabled for now until we introduce them, one at a time.
    292 
    293      // Require for-in loops to have an if statement.
    294      "guard-for-in": 0,
    295      // allow/disallow an empty newline after var statement
    296      "newline-after-var": 0,
    297      // disallow the use of alert, confirm, and prompt
    298      "no-alert": 0,
    299      // disallow comparisons to null without a type-checking operator
    300      "no-eq-null": 0,
    301      // disallow overwriting functions written as function declarations
    302      "no-func-assign": 0,
    303      // disallow use of eval()-like methods
    304      "no-implied-eval": 0,
    305      // disallow function or variable declarations in nested blocks
    306      "no-inner-declarations": 0,
    307      // disallow invalid regular expression strings in the RegExp constructor
    308      "no-invalid-regexp": 0,
    309      // disallow irregular whitespace outside of strings and comments
    310      "no-irregular-whitespace": 0,
    311      // disallow labels that share a name with a variable
    312      "no-label-var": 0,
    313      // disallow unnecessary nested blocks
    314      "no-lone-blocks": 0,
    315      // disallow creation of functions within loops
    316      "no-loop-func": 0,
    317      // disallow negation of the left operand of an in expression
    318      "no-negated-in-lhs": 0,
    319      // disallow use of new operator when not part of the assignment or
    320      // comparison
    321      "no-new": 0,
    322      // disallow use of new operator for Function object
    323      "no-new-func": 0,
    324      // disallow use of the Object constructor
    325      "no-new-object": 0,
    326      // disallows creating new instances of String,Number, and Boolean
    327      "no-new-wrappers": 0,
    328      // disallow the use of object properties of the global object (Math and
    329      // JSON) as functions
    330      "no-obj-calls": 0,
    331      // disallow use of octal escape sequences in string literals, such as
    332      // var foo = "Copyright \251";
    333      "no-octal-escape": 0,
    334      // disallow use of undefined when initializing variables
    335      "no-undef-init": 0,
    336      // disallow usage of expressions in statement position
    337      "no-unused-expressions": 0,
    338      // disallow use of void operator
    339      "no-void": 0,
    340      // require assignment operator shorthand where possible or prohibit it
    341      // entirely
    342      "operator-assignment": 0,
    343    },
    344    settings: {
    345      jest: {
    346        // Keep in sync with "jest" version from debugger's package.json
    347        version: 29,
    348      },
    349    },
    350  },
    351 ];