Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

7.2 KB
Raw Blame
import js from "@eslint/js";
import tsParser from "@typescript-eslint/parser";
import tsPlugin from "@typescript-eslint/eslint-plugin";
import reactPlugin from "eslint-plugin-react";
import reactHooksPlugin from "eslint-plugin-react-hooks";
import importPlugin from "eslint-plugin-import";
import { defaultConditionNames } from "eslint-import-resolver-typescript";
import jsdocPlugin from "eslint-plugin-jsdoc";
import globals from 'globals';

export default [
    {
        ignores: [
            "dist/**",
            "node_modules/**",
            "playwright-report/**",
            "tests/test-results/**",
        ]
    },
    js.configs.recommended,
    {
        files: ["src/**/*.{ts,tsx}", "tests/**/*.ts", "playwright.config.ts"],
        languageOptions: {
            parser: tsParser,
            parserOptions: {
                ecmaFeatures: { jsx: true },
                ecmaVersion: "latest",
                sourceType: "module",
                project: ["./tsconfig.json", "./tests/tsconfig.json"],
                tsconfigRootDir: import.meta.dirname,
            },
        },
        plugins: {
            "@typescript-eslint": tsPlugin,
            "react": reactPlugin,
            "react-hooks": reactHooksPlugin,
            "import": importPlugin,
            "jsdoc": jsdocPlugin,
        },
        rules: {
            ...tsPlugin.configs.recommended.rules,
            ...reactPlugin.configs.recommended.rules,
            ...reactHooksPlugin.configs.recommended.rules,
            "curly": ["error", "all"],
            "brace-style": ["error", "1tbs", { "allowSingleLine": false }],
            "@typescript-eslint/await-thenable": "error",
            "react/react-in-jsx-scope": "off",
            "react/no-unused-prop-types": "error",
            "@typescript-eslint/explicit-module-boundary-types": "off",
            "@typescript-eslint/no-unused-vars": ["error", {
                "vars": "all",
                "args": "after-used",
                "ignoreRestSiblings": true,
                "varsIgnorePattern": "^_",
                "argsIgnorePattern": "^_"
            }],
            "indent": ["error", 2, {
                "SwitchCase": 1,
                "VariableDeclarator": 1,
                "outerIIFEBody": 1,
                "MemberExpression": 1,
                "FunctionDeclaration": { "parameters": 1, "body": 1 },
                "FunctionExpression": { "parameters": 1, "body": 1 },
                "CallExpression": { "arguments": 1 },
                "ArrayExpression": 1,
                "ObjectExpression": 1,
                "ImportDeclaration": 1,
                "flatTernaryExpressions": false,
                "ignoreComments": false
            }],
            "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1, "maxBOF": 0 }],
            "no-console": ["error", { allow: ["warn", "error", "info", "debug"] }],
            "jsdoc/require-jsdoc": ["error", {
                "require": {
                    "FunctionDeclaration": true,
                    "MethodDefinition": true,
                    "ClassDeclaration": true,
                    "ArrowFunctionExpression": true,
                    "FunctionExpression": true
                }
            }],
            "jsdoc/require-description": ["error", {
                "contexts": [
                    "FunctionDeclaration",
                    "MethodDefinition",
                    "ClassDeclaration",
                    "ArrowFunctionExpression",
                    "FunctionExpression"
                ]
            }],
            "spaced-comment": ["error", "always", { "markers": ["/"] }],
            "react/no-unknown-property": ["error", { "ignore": ["av-enable", "av-suppress-save", "av-disable"] }],
            "multiline-comment-style": ["error", "starred-block"],
            "@typescript-eslint/explicit-member-accessibility": ["error"],
            "@typescript-eslint/explicit-function-return-type": ["error"],
            "@typescript-eslint/typedef": ["error"],
            "@typescript-eslint/naming-convention": [
                "error",
                {
                    "selector": "interface",
                    "format": ["PascalCase"],
                    "prefix": ["I"]
                },
                {
                    "selector": "class",
                    "format": ["PascalCase"]
                }
            ],
            "react-hooks/exhaustive-deps": "warn",
            "react/jsx-no-constructed-context-values": "error",
            "import/no-unresolved": "error",
            "import/order": [
                "error",
                {
                    "groups": [
                    "builtin",
                    "external",
                    "internal",
                    "parent",
                    "sibling",
                    "index",
                    "object",
                    "type"
                    ],
                    "pathGroups": [
                    {
                        pattern: "@/**",
                        group: "internal",
                        position: "before"
                    }
                    ],
                    "pathGroupsExcludedImportTypes": ["builtin"],
                    "newlines-between": "always",
                    "alphabetize": {
                    order: "asc",
                    caseInsensitive: true
                    }
                }
              ],
            },
        settings: {
            'import/resolver': {
                typescript: {
                project: './tsconfig.json',
                conditionNames: ['aliasvault-web', ...defaultConditionNames],
                },
            },
            react: {
                version: "detect",
            },
        },
    },
    {
        // Brand style enforcement.
        files: ["src/**/*.{ts,tsx}"],
        ignores: ["src/components/shared/Icon.tsx", "src/**/__tests__/**"],
        rules: {
            "no-restricted-syntax": ["error",
                { selector: "JSXOpeningElement[name.name='svg']", message: "Use the Icon component with an icon from core/assets/icons instead of inline SVG." },
                { selector: "TemplateElement[value.raw=/<svg/]", message: "Use uiIconSvg() from @aliasvault/models/icons instead of inline SVG markup." },
                { selector: "Literal[value=/<svg/]", message: "Use uiIconSvg() from @aliasvault/models/icons instead of inline SVG markup." },
                { selector: "Literal[value=/(orange|indigo)-[0-9]/]", message: "Use the primary-* brand colors (core/assets/colors) instead of Tailwind orange or indigo; use amber for warnings." },
                { selector: "TemplateElement[value.raw=/(orange|indigo)-[0-9]/]", message: "Use the primary-* brand colors (core/assets/colors) instead of Tailwind orange or indigo; use amber for warnings." },
            ],
        },
    },
    {
        // Playwright fixtures call their `use` callback, which the React hooks rule mistakes for a hook.
        files: ["tests/**/*.ts"],
        rules: {
            "react-hooks/rules-of-hooks": "off",
        },
    },
    {
        languageOptions: {
            globals: {
                ...globals.browser,
                ...globals.node,
                NodeJS: true,
                __APP_VERSION__: 'readonly',
            }
        }
    }
];