local common = require('lsp.common')

local eslint = {
    lintCommand = 'eslint -f visualstudio --stdin --stdin-filename ${INPUT}',
    lintIgnoreExitCode = true,
    lintStdin = true,
    lintFormats = {
        "%f(%l,%c): %tarning %m",
        "%f(%l,%c): %trror %m",
    },
}

local mdlint = {
    lintCommand = 'markdownlint -s ',
    lintStdin = true,
    lintFormats = {
        '%f:%l %m',
        '%f:%l:%c %m',
        '%f: %l: %m',
    }
}

local shellcheck = {
    lintCommand = 'shellcheck -f gcc -x',
    lintSource = 'shellcheck',
    lintFormats = {
        '%f:%l:%c: %trror: %m',
        '%f:%l:%c: %tarning: %m',
        '%f:%l:%c: %tote: %m',
    }
}

local fish = {
    lintCommand = 'fish -n ',
    lintSource = 'fish',
    lintFormats = {
        '%sline %l: %m',
    }
}

local stylelint = {
    lintCommand = "stylelint",
    lintSource = "stylelint",
    lintIgnoreExitCode = true,
    lintFormats = {
        "%-P%f",
        [[%*[\ ]%l:%c%*[\ ]%*[✖⚠]%*[\ ]%m]],
        "%-Q",
    },
}

local hadolint = {
    lintCommand = 'hadolint',
    lintFormats = { '%f:%l %m' },
}


require('lspconfig').efm.setup {
    capabilities = common.cap,
    on_attach = common.attach,
    filetypes = {
        "bash",
        "css",
        "dockerfile",
        "fish",
        "javascript",
        "markdown",
        "scss",
        "sh",
        "vimwiki"
    },
    settings = {
        rootMarkers = {".git/"},
        languages = {
            bash = { shellcheck },
            css = { stylelint },
            dockerfile = { hadolint },
            fish = { fish },
            javascript = { eslint },
            markdown = { mdlint },
            scss = { stylelint },
            sh = { shellcheck },
            vimwiki = { mdlint },
        }
    }
}

