tor-browser

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

.eslintrc.mjs (9747B)


      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 
      9 export default [
     10  {
     11    plugins: { react },
     12    languageOptions: {
     13      globals: {
     14        exports: true,
     15        isWorker: true,
     16        DebuggerNotificationObserver: true,
     17      },
     18    },
     19    rules: {
     20      // These are the rules that have been configured so far to match the
     21      // devtools coding style.
     22 
     23      // Rules from the mozilla plugin
     24      "mozilla/balanced-observers": "error",
     25      "mozilla/no-aArgs": "error",
     26      // See bug 1224289.
     27      "mozilla/reject-importGlobalProperties": ["error", "everything"],
     28      "mozilla/var-only-at-top-level": "error",
     29 
     30      // Rules from the React plugin
     31      "react/display-name": "error",
     32      "react/no-danger": "error",
     33      "react/no-deprecated": "error",
     34      "react/no-did-mount-set-state": "error",
     35      "react/no-did-update-set-state": "error",
     36      "react/no-direct-mutation-state": "error",
     37      "react/no-unknown-property": "error",
     38      "react/prefer-es6-class": ["off", "always"],
     39      "react/prop-types": "error",
     40      "react/sort-comp": [
     41        "error",
     42        {
     43          order: ["static-methods", "lifecycle", "everything-else", "render"],
     44          groups: {
     45            lifecycle: [
     46              "displayName",
     47              "propTypes",
     48              "contextTypes",
     49              "childContextTypes",
     50              "mixins",
     51              "statics",
     52              "defaultProps",
     53              "constructor",
     54              "getDefaultProps",
     55              "getInitialState",
     56              "state",
     57              "getChildContext",
     58              "UNSAFE_componentWillMount",
     59              "componentDidMount",
     60              "UNSAFE_componentWillReceiveProps",
     61              "shouldComponentUpdate",
     62              "UNSAFE_componentWillUpdate",
     63              "componentDidUpdate",
     64              "componentWillUnmount",
     65            ],
     66          },
     67        },
     68      ],
     69 
     70      // Disallow using variables outside the blocks they are defined (especially
     71      // since only let and const are used, see "no-var").
     72      "block-scoped-var": "error",
     73      // Require camel case names
     74      camelcase: ["error", { properties: "never" }],
     75      // Warn about cyclomatic complexity in functions.
     76      // 20 is ESLint's default, and we want to keep it this way to prevent new highly
     77      // complex functions from being introduced. However, because Mozilla's eslintrc has
     78      // some other value defined, we need to override it here. See bug 1553449 for more
     79      // information on complex DevTools functions that are currently excluded.
     80      // Note: this was increased to 25 in May 2025, to account for the ESLint v9 upgrade
     81      // which changed the rule to take into account optional chaining and default values
     82      // in destructuring patterns and parameters
     83      complexity: ["error", 24],
     84      // componentDidUnmount is not a real lifecycle method, use componentWillUnmount.
     85      "id-denylist": ["error", "componentDidUnmount"],
     86      // Maximum depth callbacks can be nested.
     87      "max-nested-callbacks": ["error", 3],
     88      // Require a capital letter for constructors, only check if all new
     89      // operators are followed by a capital letter. Don't warn when capitalized
     90      // functions are used without the new operator.
     91      "new-cap": ["error", { capIsNew: false }],
     92      // Disallow empty statements. This will report an error for:
     93      // try { something(); } catch (e) {}
     94      // but will not report it for:
     95      // try { something(); } catch (e) { /* Silencing the error because ...*/ }
     96      // which is a valid use case.
     97      "no-empty": "error",
     98      // Disallow adding to native types
     99      "no-extend-native": "error",
    100      // Disallow use of multiline strings (use template strings instead).
    101      "no-multi-str": "error",
    102      // Disallow usage of __proto__ property.
    103      "no-proto": "error",
    104      // Disallow use of assignment in return statement. It is preferable for a
    105      // single line of code to have only one easily predictable effect.
    106      "no-return-assign": "error",
    107      // Disallow global and local variables that aren't used. Allow unused
    108      // function arguments prefixed with `_`.
    109      "no-unused-vars": [
    110        "error",
    111        { argsIgnorePattern: "^_", caughtErrors: "none", vars: "all" },
    112      ],
    113      // Enforce using `let` only when variables are reassigned.
    114      "prefer-const": ["error", { destructuring: "all" }],
    115      // Require use of the second argument for parseInt().
    116      radix: "error",
    117      // Require "use strict" to be defined globally in the script.
    118      strict: ["error", "global"],
    119      // Disallow Yoda conditions (where literal value comes first).
    120      yoda: "error",
    121 
    122      // And these are the rules that haven't been discussed so far, and that are
    123      // disabled for now until we introduce them, one at a time.
    124 
    125      // disallow overwriting functions written as function declarations
    126      "no-func-assign": "off",
    127      // disallow unnecessary nested blocks
    128      "no-lone-blocks": "off",
    129      // disallow unnecessary concatenation of literals or template literals
    130      "no-useless-concat": "off",
    131      // This rule will match any function starting with `use` which aren't
    132      // necessarily in a React component. Also DevTools aren't using React hooks
    133      // so this sounds unecessary.
    134      "react-hooks/rules-of-hooks": "off",
    135    },
    136    settings: {
    137      react: {
    138        version: "16.8",
    139      },
    140    },
    141  },
    142  {
    143    files: ["**"],
    144    ignores: ["**/*.sys.mjs", "**/*.worker.js"],
    145    languageOptions: {
    146      globals: {
    147        loader: true,
    148        module: true,
    149        require: true,
    150      },
    151    },
    152  },
    153  {
    154    files: ["client/framework/**"],
    155    rules: {
    156      "no-return-assign": "off",
    157    },
    158  },
    159  {
    160    files: [
    161      // Allow non-camelcase so that run_test doesn't produce a warning.
    162      "**/test*/**/*",
    163    ],
    164    rules: {
    165      camelcase: "off",
    166    },
    167  },
    168  {
    169    files: ["client/framework/**"],
    170    rules: {
    171      "max-nested-callbacks": "off",
    172    },
    173  },
    174  {
    175    files: ["client/framework/test/**"],
    176    rules: {
    177      "mozilla/var-only-at-top-level": "off",
    178    },
    179  },
    180  {
    181    files: [
    182      // Bug 1467784 - Fix these instances to have strict enabled.
    183      "client/framework/**",
    184      "client/shared/components/object-inspector/**",
    185      "client/shared/components/test/node/stubs/object-inspector/",
    186    ],
    187    rules: {
    188      strict: "off",
    189    },
    190  },
    191  {
    192    // For all head*.js files, turn off no-unused-vars at a global level
    193    files: ["**/head*.js"],
    194    rules: {
    195      "no-unused-vars": [
    196        "error",
    197        { argsIgnorePattern: "^_", caughtErrors: "none", vars: "local" },
    198      ],
    199    },
    200  },
    201  {
    202    // For all server and shared files, prevent requiring devtools/client
    203    // modules.
    204    files: ["server/**", "shared/**"],
    205    rules: {
    206      "mozilla/reject-some-requires": [
    207        "error",
    208        "^(resource://)?devtools/client",
    209      ],
    210    },
    211    ignores: [
    212      // Tests can always import anything.
    213      "**/test*/**/*",
    214    ],
    215  },
    216  {
    217    // All DevTools files should avoid relative paths.
    218    files: ["**"],
    219    ignores: [
    220      // Debugger modules have a custom bundling logic which relies on relative
    221      // paths.
    222      "client/debugger/src/**",
    223      // `client/shared/build` contains node helpers to build the debugger and
    224      // not devtools modules.
    225      "client/shared/build/**",
    226    ],
    227    rules: {
    228      "mozilla/reject-relative-requires": "error",
    229    },
    230  },
    231  {
    232    // These tests use old React. We should accept deprecated API usages
    233    files: [
    234      "client/inspector/markup/test/events/doc_markup_events_react_development_15.4.1.html",
    235      "client/inspector/markup/test/events/doc_markup_events_react_development_15.4.1_jsx.html",
    236      "client/inspector/markup/test/events/doc_markup_events_react_production_15.3.1.html",
    237      "client/inspector/markup/test/events/doc_markup_events_react_production_15.3.1_jsx.html",
    238    ],
    239    rules: {
    240      "react/no-deprecated": "off",
    241    },
    242  },
    243  {
    244    // These files are used in both browser and node environments,
    245    files: [
    246      "shared/compatibility/constants.js",
    247      "shared/compatibility/helpers.js",
    248    ],
    249    languageOptions: {
    250      globals: {
    251        ...mozilla.turnOff(globals.browser),
    252        ...mozilla.turnOff(mozilla.environments.privileged.globals),
    253        ...mozilla.turnOff(mozilla.environments.specific.globals),
    254      },
    255    },
    256  },
    257  {
    258    // This file is only used in node environment.
    259    files: ["shared/compatibility/bin/update.js"],
    260    languageOptions: {
    261      globals: {
    262        ...mozilla.turnOff(globals.browser),
    263        ...globals.node,
    264        ...mozilla.environments.privileged.globals,
    265        ...mozilla.environments.specific.globals,
    266      },
    267    },
    268  },
    269  {
    270    files: [
    271      "client/inspector/markup/test/events/doc_markup_events_react_*_jsx.html",
    272    ],
    273    languageOptions: {
    274      parserOptions: {
    275        ecmaFeatures: {
    276          jsx: true,
    277        },
    278      },
    279    },
    280  },
    281  {
    282    files: ["**/xpcshell/**"],
    283    rules: {
    284      // Allow non-camelcase so that run_test doesn't produce a warning.
    285      camelcase: "off",
    286      "block-scoped-var": "off",
    287      // Tests don't have to cleanup observers
    288      "mozilla/balanced-observers": 0,
    289      // Tests can always import anything.
    290      "mozilla/reject-some-requires": "off",
    291    },
    292  },
    293  {
    294    files: ["**/node/**"],
    295    languageOptions: { globals: globals.jest },
    296  },
    297 ];