import js from '@eslint/js';
import globals from 'globals';
import stylistic from '@stylistic/eslint-plugin';

export default [
    js.configs.recommended,
    {
        languageOptions: {sourceType: 'script', globals: {...globals.browser}},
        linterOptions: {reportUnusedDisableDirectives: true},
        plugins: {'@stylistic': stylistic},

        rules: {
            // Possible problems
            'no-await-in-loop': 'error',
            'no-constant-binary-expression': 'error',
            'no-duplicate-imports': ['error', {includeExports: true}],
            'no-self-compare': 'error',
            'no-template-curly-in-string': 'error',
            'no-unreachable-loop': 'error',
            'no-unused-private-class-members': 'error',
            'no-use-before-define': 'error',

            // Suggestions
            'accessor-pairs': 'error',
            'array-callback-return': ['error', {allowImplicit: true}],
            'arrow-body-style': ['error', 'as-needed'],
            'camelcase': 'error',
            'capitalized-comments': [
                'error', 'always',
                {'ignoreInlineComments': true, 'ignoreConsecutiveComments': true},
            ],
            'consistent-this': ['error', 'self'],
            'curly': ['error', 'multi-line', 'consistent'],
            'default-case-last': 'error',
            'default-param-last': 'error',
            'dot-notation': 'error',
            'eqeqeq': 'error',
            'func-names': ['error', 'as-needed'],
            'func-style': ['error', 'declaration'],
            'grouped-accessor-pairs': ['error', 'getBeforeSet'],
            'guard-for-in': 'error',
            'id-length': 'error',
            'multiline-comment-style': ['error', 'separate-lines', {checkJSDoc: true}],
            'new-cap': 'error',
            'no-alert': 'error',
            'no-array-constructor': 'error',
            'no-caller': 'error',
            'no-confusing-arrow': 'error',
            'no-console': 'error',
            'no-constructor-return': 'error',
            'no-else-return': ['error', {allowElseIf: false}],
            'no-empty-static-block': 'error',
            'no-eq-null': 'error',
            'no-eval': 'error',
            'no-extend-native': 'error',
            'no-extra-bind': 'error',
            'no-extra-label': 'error',
            'no-floating-decimal': 'error',
            'no-implicit-coercion': ['error', {disallowTemplateShorthand: true}],
            'no-implied-eval': 'error',
            'no-invalid-this': 'error',
            'no-iterator': 'error',
            'no-label-var': 'error',
            'no-lone-blocks': 'error',
            'no-lonely-if': 'error',
            'no-loop-func': 'error',
            'no-mixed-operators': 'error',
            'no-multi-assign': 'error',
            'no-new': 'error',
            'no-new-func': 'error',
            'no-new-native-nonconstructor': 'error',
            'no-new-object': 'error',
            'no-new-wrappers': 'error',
            'no-octal-escape': 'error',
            'no-param-reassign': ['error', {props: false}],
            'no-plusplus': 'error',
            'no-promise-executor-return': 'error',
            'no-proto': 'error',
            'no-restricted-globals': ['error', 'event'],
            'no-return-assign': 'error',
            'no-return-await': 'error',
            'no-script-url': 'error',
            'no-sequences': 'error',
            'no-shadow': ['error', {builtinGlobals: false}],
            'no-throw-literal': 'error',
            'no-undef-init': 'error',
            'no-undefined': 'error',
            'no-underscore-dangle': 'error',
            'no-unneeded-ternary': ['error', {defaultAssignment: false}],
            'no-unused-expressions': [
                'error',
                {
                    allowShortCircuit: false,
                    allowTernary: false,
                    allowTaggedTemplates: false,
                },
            ],
            'no-unused-vars': ['error', {vars: 'all', args: 'all'}],
            'no-useless-call': 'error',
            'no-useless-computed-key': 'error',
            'no-useless-concat': 'error',
            'no-useless-constructor': 'error',
            'no-useless-rename': 'error',
            'no-useless-return': 'error',
            'no-var': 'error',
            'no-void': 'error',
            'no-warning-comments': 'error',
            'object-shorthand': [
                'error', 'always',
                {avoidQuotes: true, ignoreConstructors: false},
            ],
            'one-var': ['error', 'never'],
            'operator-assignment': 'error',
            'prefer-arrow-callback': 'error',
            'prefer-const': ['error', {destructuring: 'any', ignoreReadBeforeAssign: true}],
            'prefer-exponentiation-operator': 'error',
            'prefer-named-capture-group': 'error',
            'prefer-numeric-literals': 'error',
            'prefer-object-has-own': 'error',
            'prefer-object-spread': 'error',
            'prefer-promise-reject-errors': ['error', {allowEmptyReject: true}],
            'prefer-regex-literals': ['error', {disallowRedundantWrapping: true}],
            'prefer-rest-params': 'error',
            'prefer-spread': 'error',
            'prefer-template': 'error',
            'quote-props': ['error', 'as-needed', {keywords: true, numbers: true}],
            'require-await': 'error',
            'require-yield': 'error',
            'sort-imports': 'error',
            'spaced-comment': 'error',
            'strict': ['error', 'global'],
            'symbol-description': 'error',
            'unicode-bom': 'error',
            'vars-on-top': 'error',
            'yoda': 'error',

            // Layout & formatting
            '@stylistic/array-bracket-newline': ['error', 'consistent'],
            '@stylistic/array-bracket-spacing': 'error',
            '@stylistic/array-element-newline': ['error', 'consistent'],
            '@stylistic/arrow-parens': ['error', 'always'],
            '@stylistic/arrow-spacing': 'error',
            '@stylistic/block-spacing': 'error',
            '@stylistic/brace-style': ['error', '1tbs', {allowSingleLine: true}],
            '@stylistic/comma-dangle': ['error', 'always-multiline'],
            '@stylistic/comma-spacing': 'error',
            '@stylistic/comma-style': 'error',
            '@stylistic/computed-property-spacing': 'error',
            '@stylistic/dot-location': ['error', 'property'],
            '@stylistic/eol-last': ['error', 'always'],
            '@stylistic/function-call-spacing': 'error',
            '@stylistic/function-call-argument-newline': ['error', 'consistent'],
            '@stylistic/function-paren-newline': ['error', 'consistent'],
            '@stylistic/generator-star-spacing': 'error',
            '@stylistic/implicit-arrow-linebreak': 'error',
            '@stylistic/indent': ['error', 4],
            '@stylistic/key-spacing': 'error',
            '@stylistic/keyword-spacing': 'error',
            '@stylistic/linebreak-style': ['error', 'unix'],
            '@stylistic/new-parens': 'error',
            '@stylistic/no-extra-parens': [
                'error', 'all',
                {
                    nestedBinaryExpressions: false,
                    returnAssign: false,
                    enforceForArrowConditionals: false,
                },
            ],
            '@stylistic/no-multi-spaces': 'error',
            '@stylistic/no-multiple-empty-lines': ['error', {max: 1, maxEOF: 0, maxBOF: 0}],
            '@stylistic/no-tabs': 'error',
            '@stylistic/no-trailing-spaces': 'error',
            '@stylistic/no-whitespace-before-property': 'error',
            '@stylistic/nonblock-statement-body-position': 'error',
            '@stylistic/object-curly-newline': 'error',
            '@stylistic/object-curly-spacing': 'error',
            '@stylistic/operator-linebreak': ['error', 'before'],
            '@stylistic/padded-blocks': ['error', 'never'],
            '@stylistic/quotes': ['error', 'single', {avoidEscape: true}],
            '@stylistic/rest-spread-spacing': 'error',
            '@stylistic/semi': ['error', 'always'],
            '@stylistic/semi-spacing': 'error',
            '@stylistic/semi-style': 'error',
            '@stylistic/space-before-blocks': 'error',
            '@stylistic/space-before-function-paren': [
                'error', {anonymous: 'always', named: 'never', asyncArrow: 'always'},
            ],
            '@stylistic/space-in-parens': 'error',
            '@stylistic/space-infix-ops': 'error',
            '@stylistic/space-unary-ops': 'error',
            '@stylistic/switch-colon-spacing': 'error',
            '@stylistic/template-curly-spacing': 'error',
            '@stylistic/template-tag-spacing': 'error',
            '@stylistic/wrap-iife': 'error',
            '@stylistic/wrap-regex': 'error',
            '@stylistic/yield-star-spacing': 'error',
        },
    },
]
