/* global process */
import path from "node:path";

const buildLintCommand = (filenames) => {
  const isNext =
    process.env.npm_package_devDependencies_next ||
    process.env.npm_package_dependencies_next;

  if (isNext) {
    return `next lint --fix --file ${filenames
      .map((f) => path.relative(process.cwd(), f))
      .join(" --file ")}`;
  }

  return "eslint --fix --no-warn-ignored";
};

const config = {
  "*.{js,jsx,ts,tsx}": [buildLintCommand, "prettier --write"],
  "*.{json,md,css,scss}": ["prettier --write"],
};

export default config;
