summaryrefslogtreecommitdiff
path: root/rushs/eplace/eslint.config.mjs
blob: a315e710da209b716131f752079a6856fcf76ddc (plain)
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
import jestPlugin from "eslint-plugin-jest";
import globals from "globals";
import prettierPlugin from "eslint-plugin-prettier"; // Import the Prettier plugin
import eslintComments from "eslint-plugin-eslint-comments";
import js from "@eslint/js";

const cleanGlobals = (obj) =>
    Object.fromEntries(
        Object.entries(obj).map(([key, val]) => [key.trim(), val]),
    );

export default [
    js.configs.recommended, // Nice defaults rules
    {
        files: ["**/*.js", "**/*.mjs"], // Apply to .js and .mjs files
        languageOptions: {
            sourceType: "module",
            globals: {
                AudioWorkletGlobalScope: "readonly",
                ...cleanGlobals(globals.node),
                ...cleanGlobals(jestPlugin.environments.globals.globals),
                ...cleanGlobals(globals.browser),
            },
        },
        plugins: {
            prettier: prettierPlugin, // Add Prettier plugin correctly
            jest: jestPlugin, // Jest plugin
            "eslint-comments": eslintComments, // Add plugin to detect cheats
        },
        rules: {
            "eslint-comments/no-use": ["error", { allow: [] }], // Disallow disable rules
            curly: ["error", "all"], // Enforce curlies in conditionnal blocks
            "brace-style": ["error", "1tbs"],
            "max-statements-per-line": ["error", { max: 1 }],
            semi: ["error", "always"], // Enforce semicolons
            "prefer-const": "error", // Prefer const over let
            "no-undef": "error", // Detect definition
            "no-unused-vars": [
                "error",
                { argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
            ],
            // Detect error of line width (but can't fix them without the prettier)
            "max-len": [
                "error",
                {
                    code: 80,
                    tabWidth: 4,
                    ignoreComments: true,
                    ignoreStrings: true,
                    ignoreTemplateLiterals: true,
                    ignoreRegExpLiterals: true,
                },
            ], // More rules to complete with the existants in .prettierrc.js file
            "prettier/prettier": ["error"], // Enforce Prettier formatting
            "padding-line-between-statements": [
                // Create nice looking paddings between statements
                "error",
                {
                    blankLine: "always",
                    prev: ["const", "let", "var", "if", "for", "while", "do"],
                    next: "*",
                },
                {
                    blankLine: "any",
                    prev: ["const", "let", "var"],
                    next: ["const", "let", "var"],
                },
            ], // Requires blank lines between the given 2 kinds of statements
        },
    },
];