|
| 1 | +module.exports = { |
| 2 | + // Don't merge into parent configs. |
| 3 | + root: true, |
| 4 | + |
| 5 | + // Enable modern browser globals. |
| 6 | + env: { |
| 7 | + es2020: true, |
| 8 | + browser: true, |
| 9 | + }, |
| 10 | + |
| 11 | + // Enable ES Module mode. |
| 12 | + parserOptions: { |
| 13 | + sourceType: "module", |
| 14 | + }, |
| 15 | + |
| 16 | + extends: [ |
| 17 | + // Core |
| 18 | + "eslint:recommended", |
| 19 | + |
| 20 | + // Import Plugin |
| 21 | + "plugin:import/errors", |
| 22 | + |
| 23 | + // Unicorn Plugin |
| 24 | + "plugin:unicorn/recommended", |
| 25 | + |
| 26 | + // React Plugin |
| 27 | + "plugin:react/recommended", |
| 28 | + |
| 29 | + // React Hooks Plugin |
| 30 | + "plugin:react-hooks/recommended", |
| 31 | + |
| 32 | + // React A11Y Plugin |
| 33 | + "plugin:jsx-a11y/strict", |
| 34 | + |
| 35 | + // Prettier Plugin |
| 36 | + "plugin:prettier/recommended", |
| 37 | + "prettier/react", |
| 38 | + ], |
| 39 | + plugins: ["regex", "graphql"], |
| 40 | + |
| 41 | + rules: { |
| 42 | + // Core |
| 43 | + "arrow-body-style": "error", // Don't use unnecessary curly braces for arrow functions. |
| 44 | + "capitalized-comments": "error", |
| 45 | + "new-cap": "error", // Require constructor names to begin with a capital letter. |
| 46 | + "new-parens": "error", |
| 47 | + "no-array-constructor": "error", |
| 48 | + "no-console": "error", |
| 49 | + "no-duplicate-imports": ["error", { includeExports: true }], |
| 50 | + "no-else-return": ["error", { allowElseIf: false }], |
| 51 | + "no-extra-bind": "error", |
| 52 | + "no-iterator": "error", |
| 53 | + "no-lonely-if": "error", // In else blocks. |
| 54 | + "no-new-wrappers": "error", |
| 55 | + "no-proto": "error", |
| 56 | + "no-return-await": "error", |
| 57 | + "no-shadow": "error", |
| 58 | + "no-unneeded-ternary": ["error", { defaultAssignment: false }], |
| 59 | + "no-unused-expressions": "error", |
| 60 | + "no-use-before-define": "error", |
| 61 | + "no-useless-computed-key": "error", |
| 62 | + "no-useless-concat": "error", |
| 63 | + "no-useless-constructor": "error", |
| 64 | + "no-useless-return": "error", |
| 65 | + "no-var": "error", |
| 66 | + "object-shorthand": "error", |
| 67 | + "one-var": ["error", "never"], |
| 68 | + "operator-assignment": "error", |
| 69 | + "prefer-arrow-callback": "error", |
| 70 | + "prefer-const": "error", |
| 71 | + "prefer-exponentiation-operator": "error", |
| 72 | + "prefer-numeric-literals": "error", |
| 73 | + "prefer-object-spread": "error", |
| 74 | + "prefer-rest-params": "error", |
| 75 | + "prefer-spread": "error", |
| 76 | + "prefer-template": "error", |
| 77 | + "require-await": "error", |
| 78 | + "spaced-comment": "error", |
| 79 | + curly: ["error", "multi"], // Don't use unnecessary curly braces. |
| 80 | + eqeqeq: "error", |
| 81 | + "no-restricted-imports": [ |
| 82 | + "error", |
| 83 | + { |
| 84 | + patterns: [ |
| 85 | + "..", // No relative parent imports. |
| 86 | + "theme-ui", // This should be internal to the design system. |
| 87 | + "next/link", // Use the custom version that maintains query parameters instead. |
| 88 | + ], |
| 89 | + }, |
| 90 | + ], |
| 91 | + // Sort named import members alphabetically. |
| 92 | + "sort-imports": [ |
| 93 | + "error", |
| 94 | + { |
| 95 | + ignoreDeclarationSort: true, |
| 96 | + }, |
| 97 | + ], |
| 98 | + |
| 99 | + // Import Plugin |
| 100 | + "import/no-unused-modules": [ |
| 101 | + "error", |
| 102 | + { |
| 103 | + missingExports: true, |
| 104 | + unusedExports: true, |
| 105 | + ignoreExports: ["pages", "./*.js", "subgraph"], |
| 106 | + }, |
| 107 | + ], |
| 108 | + // Don't allow reaching into modules, except for Next.js imports, and assets. |
| 109 | + "import/no-internal-modules": [ |
| 110 | + "error", |
| 111 | + { |
| 112 | + allow: ["next/*", "_pages/**", "subgraph/**"], |
| 113 | + }, |
| 114 | + ], |
| 115 | + "import/no-useless-path-segments": [ |
| 116 | + "error", |
| 117 | + { |
| 118 | + noUselessIndex: true, |
| 119 | + }, |
| 120 | + ], |
| 121 | + "import/extensions": "error", // Don't use unnecessary file extensions. |
| 122 | + "import/order": [ |
| 123 | + "error", |
| 124 | + { |
| 125 | + "newlines-between": "always", |
| 126 | + alphabetize: { |
| 127 | + order: "asc", |
| 128 | + }, |
| 129 | + }, |
| 130 | + ], |
| 131 | + "import/newline-after-import": "error", |
| 132 | + "import/no-anonymous-default-export": [ |
| 133 | + "error", |
| 134 | + { allowCallExpression: false }, |
| 135 | + ], |
| 136 | + |
| 137 | + // Unicorn Plugin |
| 138 | + "unicorn/prevent-abbreviations": [ |
| 139 | + "error", |
| 140 | + { |
| 141 | + replacements: { |
| 142 | + acc: false, |
| 143 | + args: false, |
| 144 | + arr: false, |
| 145 | + err: false, |
| 146 | + prop: false, |
| 147 | + props: false, |
| 148 | + ref: false, |
| 149 | + res: false, |
| 150 | + }, |
| 151 | + }, |
| 152 | + ], |
| 153 | + "unicorn/no-nested-ternary": "off", |
| 154 | + "unicorn/no-null": "off", |
| 155 | + "unicorn/no-reduce": "off", |
| 156 | + "unicorn/catch-error-name": [ |
| 157 | + "error", |
| 158 | + { |
| 159 | + name: "err", |
| 160 | + }, |
| 161 | + ], |
| 162 | + "unicorn/custom-error-definition": "error", |
| 163 | + "unicorn/no-keyword-prefix": "error", |
| 164 | + "unicorn/no-unsafe-regex": "error", |
| 165 | + "unicorn/no-unused-properties": "error", |
| 166 | + "unicorn/prefer-flat-map": "error", |
| 167 | + "unicorn/prefer-replace-all": "error", |
| 168 | + "unicorn/string-content": "error", |
| 169 | + |
| 170 | + // React Plugin |
| 171 | + "react/react-in-jsx-scope": "off", |
| 172 | + "react/prop-types": "off", |
| 173 | + "react/prefer-stateless-function": "error", |
| 174 | + "react/function-component-definition": "error", |
| 175 | + "react/self-closing-comp": "error", |
| 176 | + "react/jsx-no-useless-fragment": "error", |
| 177 | + "react/jsx-fragments": "error", |
| 178 | + "react/jsx-boolean-value": "error", |
| 179 | + "react/jsx-curly-brace-presence": "error", |
| 180 | + // Force platform agnostic use of the design system. |
| 181 | + "react/forbid-elements": [ |
| 182 | + "error", |
| 183 | + { |
| 184 | + forbid: [ |
| 185 | + "!--...--", |
| 186 | + "!DOCTYPE", |
| 187 | + "a", |
| 188 | + "abbr", |
| 189 | + "acronym", |
| 190 | + "address", |
| 191 | + "applet", |
| 192 | + "area", |
| 193 | + "article", |
| 194 | + "aside", |
| 195 | + "audio", |
| 196 | + "b", |
| 197 | + "base", |
| 198 | + "basefont", |
| 199 | + "bdi", |
| 200 | + "bdo", |
| 201 | + "big", |
| 202 | + "blockquote", |
| 203 | + "body", |
| 204 | + "br", |
| 205 | + "button", |
| 206 | + "canvas", |
| 207 | + "caption", |
| 208 | + "center", |
| 209 | + "cite", |
| 210 | + "code", |
| 211 | + "col", |
| 212 | + "colgroup", |
| 213 | + "data", |
| 214 | + "datalist", |
| 215 | + "dd", |
| 216 | + "del", |
| 217 | + "details", |
| 218 | + "dfn", |
| 219 | + "dialog", |
| 220 | + "dir", |
| 221 | + "div", |
| 222 | + "dl", |
| 223 | + "dt", |
| 224 | + "em", |
| 225 | + "embed", |
| 226 | + "fieldset", |
| 227 | + "figcaption", |
| 228 | + "figure", |
| 229 | + "font", |
| 230 | + "footer", |
| 231 | + "form", |
| 232 | + "frame", |
| 233 | + "frameset", |
| 234 | + "h1", |
| 235 | + "h2", |
| 236 | + "h3", |
| 237 | + "h4", |
| 238 | + "h5", |
| 239 | + "h6", |
| 240 | + "head", |
| 241 | + "header", |
| 242 | + "hr", |
| 243 | + "html", |
| 244 | + "i", |
| 245 | + "iframe", |
| 246 | + "img", |
| 247 | + "input", |
| 248 | + "ins", |
| 249 | + "kbd", |
| 250 | + "label", |
| 251 | + "legend", |
| 252 | + "li", |
| 253 | + "link", |
| 254 | + "main", |
| 255 | + "map", |
| 256 | + "mark", |
| 257 | + "meta", |
| 258 | + "meter", |
| 259 | + "nav", |
| 260 | + "noframes", |
| 261 | + "noscript", |
| 262 | + "object", |
| 263 | + "ol", |
| 264 | + "optgroup", |
| 265 | + "option", |
| 266 | + "output", |
| 267 | + "p", |
| 268 | + "param", |
| 269 | + "picture", |
| 270 | + "pre", |
| 271 | + "progress", |
| 272 | + "q", |
| 273 | + "rp", |
| 274 | + "rt", |
| 275 | + "ruby", |
| 276 | + "s", |
| 277 | + "samp", |
| 278 | + "script", |
| 279 | + "section", |
| 280 | + "select", |
| 281 | + "small", |
| 282 | + "source", |
| 283 | + "span", |
| 284 | + "strike", |
| 285 | + "strong", |
| 286 | + "style", |
| 287 | + "sub", |
| 288 | + "summary", |
| 289 | + "sup", |
| 290 | + "svg", |
| 291 | + "table", |
| 292 | + "tbody", |
| 293 | + "td", |
| 294 | + "template", |
| 295 | + "textarea", |
| 296 | + "tfoot", |
| 297 | + "th", |
| 298 | + "thead", |
| 299 | + "time", |
| 300 | + "title", |
| 301 | + "tr", |
| 302 | + "track", |
| 303 | + "tt", |
| 304 | + "u", |
| 305 | + "ul", |
| 306 | + "var", |
| 307 | + "video", |
| 308 | + "wbr", |
| 309 | + ], |
| 310 | + }, |
| 311 | + ], |
| 312 | + |
| 313 | + // React Hooks Plugin |
| 314 | + "react-hooks/exhaustive-deps": ["error"], |
| 315 | + |
| 316 | + // Regex Plugin |
| 317 | + "regex/invalid": [ |
| 318 | + "error", |
| 319 | + [ |
| 320 | + 'import.*(/|\\.)";', // Don't use trailing slashes or cyclic index imports. |
| 321 | + '"\\d+"', // Don't use numerical strings. |
| 322 | + "[^\\d]0p[x]", // Don't use pixels unit for zero values. |
| 323 | + "(?=.*[A-F])#[0-9a-fA-F]{1,6}", // Don't use upper case letters in hex colors. |
| 324 | + "@js[x]", // Don't use a custom JSX pragma. |
| 325 | + "Style[d]", // Don't use "styled" components. |
| 326 | + ",\\s+&", // Don't use spaces between comma separated selectors. |
| 327 | + "eslint-disabl[e]", // Don't disable rules. |
| 328 | + ], |
| 329 | + ], |
| 330 | + |
| 331 | + // GraphQL Plugin |
| 332 | + "graphql/template-strings": [ |
| 333 | + "error", |
| 334 | + { |
| 335 | + env: "relay", |
| 336 | + schemaJsonFilepath: "subgraph/build/full-schema.json", |
| 337 | + tagName: "graphql", |
| 338 | + }, |
| 339 | + ], |
| 340 | + }, |
| 341 | + |
| 342 | + settings: { |
| 343 | + "import/resolver": { |
| 344 | + alias: [ |
| 345 | + ["_pages", "./_pages"], |
| 346 | + ["subgraph", "./subgraph"], |
| 347 | + ], |
| 348 | + }, |
| 349 | + react: { version: "detect" }, |
| 350 | + }, |
| 351 | + |
| 352 | + // Node config files and scripts. |
| 353 | + overrides: [ |
| 354 | + { |
| 355 | + files: ["./*.js", "subgraph/**.js"], |
| 356 | + env: { node: true }, |
| 357 | + }, |
| 358 | + ], |
| 359 | +}; |
0 commit comments