.eslintrc.mjs (5839B)
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 importPlugin from "eslint-plugin-import"; 6 import jsxA11y from "eslint-plugin-jsx-a11y"; 7 import react from "eslint-plugin-react"; 8 import globals from "globals"; 9 10 export default [ 11 { 12 ...jsxA11y.flatConfigs.recommended, 13 // When adding items to this file please check for effects on sub-directories. 14 plugins: { import: importPlugin, react, "jsx-a11y": jsxA11y }, 15 settings: { 16 react: { 17 version: "16.2.0", 18 }, 19 }, 20 rules: { 21 "react/jsx-boolean-value": ["error", "always"], 22 "react/jsx-key": "error", 23 "react/jsx-no-bind": [ 24 "error", 25 { allowArrowFunctions: true, allowFunctions: true }, 26 ], 27 "react/jsx-no-comment-textnodes": "error", 28 "react/jsx-no-duplicate-props": "error", 29 "react/jsx-no-target-blank": "error", 30 "react/jsx-no-undef": "error", 31 "react/jsx-pascal-case": "error", 32 "react/jsx-uses-react": "error", 33 "react/jsx-uses-vars": "error", 34 "react/no-access-state-in-setstate": "error", 35 "react/no-danger": "error", 36 "react/no-deprecated": "error", 37 "react/no-did-mount-set-state": "error", 38 "react/no-did-update-set-state": "error", 39 "react/no-direct-mutation-state": "error", 40 "react/no-is-mounted": "error", 41 "react/no-unknown-property": [ 42 "error", 43 { 44 // Custom HTML attributes used in aboutwelcome React components. 45 ignore: [ 46 "flow", 47 "alignment", 48 "button-size", 49 "layout", 50 "pos", 51 "hide-secondary-section", 52 "reverse-split", 53 "no-rdm", 54 "above-button", 55 "fullscreen", 56 "narrow", 57 "srcset", 58 ], 59 }, 60 ], 61 "react/require-render-return": "error", 62 63 "accessor-pairs": [ 64 "error", 65 { setWithoutGet: true, getWithoutSet: false }, 66 ], 67 "array-callback-return": "error", 68 "block-scoped-var": "error", 69 "consistent-this": ["error", "use-bind"], 70 eqeqeq: "error", 71 "func-name-matching": "error", 72 "guard-for-in": "error", 73 "max-nested-callbacks": ["error", 4], 74 "max-params": ["error", 6], 75 "max-statements": ["error", 50], 76 "new-cap": ["error", { newIsCap: true, capIsNew: false }], 77 "no-alert": "error", 78 "no-div-regex": "error", 79 "no-duplicate-imports": "error", 80 "no-eq-null": "error", 81 "no-extend-native": "error", 82 "no-extra-label": "error", 83 "no-implicit-coercion": ["error", { allow: ["!!"] }], 84 "no-implicit-globals": "error", 85 "no-loop-func": "error", 86 "no-multi-assign": "error", 87 "no-multi-str": "error", 88 "no-new": "error", 89 "no-new-func": "error", 90 "no-octal-escape": "error", 91 "no-param-reassign": "error", 92 "no-proto": "error", 93 "no-prototype-builtins": "error", 94 "no-return-assign": ["error", "except-parens"], 95 "no-script-url": "error", 96 "no-template-curly-in-string": "error", 97 "no-undef-init": "error", 98 "no-unmodified-loop-condition": "error", 99 "no-unused-expressions": "error", 100 "no-use-before-define": "error", 101 "no-useless-computed-key": "error", 102 "no-useless-constructor": "error", 103 "no-useless-rename": "error", 104 "no-var": "error", 105 "no-void": ["error", { allowAsStatement: true }], 106 "one-var": ["error", "never"], 107 "operator-assignment": ["error", "always"], 108 "prefer-destructuring": [ 109 "error", 110 { 111 AssignmentExpression: { array: true }, 112 VariableDeclarator: { array: true, object: true }, 113 }, 114 ], 115 "prefer-numeric-literals": "error", 116 "prefer-promise-reject-errors": "error", 117 "prefer-rest-params": "error", 118 "prefer-spread": "error", 119 "prefer-template": "error", 120 radix: ["error", "always"], 121 "sort-vars": "error", 122 "symbol-description": "error", 123 "vars-on-top": "error", 124 yoda: ["error", "never"], 125 }, 126 }, 127 { 128 // TODO: Bug 1773467 - Move these to .mjs or figure out a generic way 129 // to identify these as modules. 130 files: ["tests/unit/**/*.js"], 131 languageOptions: { 132 sourceType: "module", 133 }, 134 }, 135 { 136 // These files use fluent-dom to insert content 137 files: [ 138 "content-src/components/Zap.jsx", 139 "content-src/components/MultiStageAboutWelcome.jsx", 140 "content-src/components/MultiStageScreen.jsx", 141 "content-src/components/MultiStageProtonScreen.jsx", 142 "content-src/components/MultiSelect.jsx", 143 ], 144 rules: { 145 "jsx-a11y/anchor-has-content": "off", 146 "jsx-a11y/heading-has-content": "off", 147 "jsx-a11y/label-has-associated-control": "off", 148 "jsx-a11y/no-onchange": "off", 149 }, 150 }, 151 { 152 files: ["content-src/**", "tests/unit/**"], 153 languageOptions: { globals: globals.node }, 154 }, 155 { 156 // Use a configuration that's appropriate for modules, workers and 157 // non-production files. 158 files: ["tests/**"], 159 rules: { 160 "no-implicit-globals": "off", 161 }, 162 }, 163 { 164 files: ["content-src/**", "tests/unit/**"], 165 rules: { 166 // Disallow commonjs in these directories. 167 "import/no-commonjs": 2, 168 }, 169 }, 170 { 171 // These tests simulate the browser environment. 172 files: "tests/unit/**", 173 languageOptions: { 174 globals: { 175 ...globals.browser, 176 ...globals.mocha, 177 assert: "readonly", 178 chai: "readonly", 179 sinon: "readonly", 180 }, 181 }, 182 }, 183 { 184 files: "tests/**", 185 rules: { 186 "func-name-matching": 0, 187 "lines-between-class-members": 0, 188 }, 189 }, 190 ];