import {
  CSS_EXTENSIONS,
  SOLID_EXTENSIONS,
  buildCSSResult,
  buildSolidSyntaxTree,
  createCSSInput,
  extensionsToGlobs,
  rules,
  rules2
} from "./chunk-D2TKH7AJ.js";

// src/eslint-adapter.ts
import { ESLintUtils } from "@typescript-eslint/utils";
function buildSolidInputFromContext(context) {
  const parserServices = ESLintUtils.getParserServices(context);
  const program = parserServices.program;
  if (!program) {
    throw new Error(
      "ganko requires typed linting. Ensure your ESLint config uses typescript-eslint typed linting with `projectService: true`."
    );
  }
  const sourceFile = program.getSourceFile(context.filename);
  if (!sourceFile) {
    throw new Error(`File not found in TypeScript program: ${context.filename}`);
  }
  return {
    file: context.filename,
    sourceFile,
    checker: program.getTypeChecker()
  };
}
var MSG_ID = "_msg";
var MSG_TEMPLATE = { [MSG_ID]: "{{msg}}" };
function applyFix(fixer, op) {
  return fixer.replaceTextRange([op.range[0], op.range[1]], op.text);
}
function toESLintFix(fix) {
  return (fixer) => {
    const first = fix[0];
    if (fix.length === 1 && first) return applyFix(fixer, first);
    const fixes = [];
    for (let i = 0; i < fix.length; i++) {
      const op = fix[i];
      if (!op) continue;
      fixes.push(applyFix(fixer, op));
    }
    return fixes;
  };
}
function toESLintSuggestions(suggestions) {
  const result = [];
  for (let i = 0; i < suggestions.length; i++) {
    const s = suggestions[i];
    if (!s) continue;
    result.push({
      messageId: MSG_ID,
      data: { msg: s.message },
      fix: toESLintFix(s.fix)
    });
  }
  return result;
}
function createRuleModule(rule, getGraph) {
  const meta = {
    type: "problem",
    docs: {
      description: rule.meta.description
    },
    messages: MSG_TEMPLATE,
    schema: []
  };
  if (rule.meta.fixable) meta.fixable = "code";
  return {
    meta,
    defaultOptions: [],
    create(context) {
      return {
        Program() {
          const graph = getGraph(context);
          const diagnostics = [];
          const emit = (d) => diagnostics.push(d);
          rule.check(graph, emit);
          for (let i = 0; i < diagnostics.length; i++) {
            const diag = diagnostics[i];
            if (!diag) continue;
            reportDiagnostic(context, diag);
          }
        }
      };
    }
  };
}
function createCachedPluginAdapter(rules3, buildGraph) {
  const cache = /* @__PURE__ */ new WeakMap();
  function getGraph(context) {
    const sourceCode = context.sourceCode;
    const cached = cache.get(sourceCode);
    if (cached) return cached;
    const graph = buildGraph(context);
    cache.set(sourceCode, graph);
    return graph;
  }
  const eslintRules3 = {};
  for (let i = 0; i < rules3.length; i++) {
    const r = rules3[i];
    if (!r) continue;
    eslintRules3[r.id] = createRuleModule(r, getGraph);
  }
  return { eslintRules: eslintRules3 };
}
function reportDiagnostic(context, d) {
  const data = { msg: d.message };
  if (d.fix) {
    if (d.suggest && d.suggest.length > 0) {
      context.report({
        messageId: MSG_ID,
        data,
        loc: d.loc,
        fix: toESLintFix(d.fix),
        suggest: toESLintSuggestions(d.suggest)
      });
    } else {
      context.report({
        messageId: MSG_ID,
        data,
        loc: d.loc,
        fix: toESLintFix(d.fix)
      });
    }
  } else if (d.suggest && d.suggest.length > 0) {
    context.report({
      messageId: MSG_ID,
      data,
      loc: d.loc,
      suggest: toESLintSuggestions(d.suggest)
    });
  } else {
    context.report({
      messageId: MSG_ID,
      data,
      loc: d.loc
    });
  }
}

// src/solid/eslint-plugin.ts
var { eslintRules } = createCachedPluginAdapter(rules, (context) => {
  const input = buildSolidInputFromContext(context);
  return buildSolidSyntaxTree(input, "");
});

// src/css/eslint-plugin.ts
var { eslintRules: eslintRules2 } = createCachedPluginAdapter(rules2, (context) => {
  return buildCSSResult(createCSSInput([{ path: context.filename, content: context.sourceCode.getText() }])).workspace;
});

// src/eslint-plugin.ts
var allRules = {
  ...eslintRules,
  ...eslintRules2
};
var configs = {};
var plugin = {
  meta: {
    name: "eslint-plugin-ganko",
    version: "0.1.0"
  },
  rules: allRules,
  configs
};
function buildRuleConfig(ruleList) {
  const out = {};
  for (let i = 0; i < ruleList.length; i++) {
    const r = ruleList[i];
    if (!r) continue;
    out[`solid/${r.id}`] = r.severity === "off" ? "off" : r.severity === "warn" ? "warn" : "error";
  }
  return out;
}
var solidOnlyRules = buildRuleConfig(rules);
var cssOnlyRules = buildRuleConfig(rules2);
var tsFiles = extensionsToGlobs(SOLID_EXTENSIONS);
var cssFiles = extensionsToGlobs(CSS_EXTENSIONS);
plugin.configs["recommended"] = [
  {
    plugins: { solid: plugin },
    files: tsFiles,
    rules: solidOnlyRules
  },
  {
    plugins: { solid: plugin },
    files: cssFiles,
    rules: cssOnlyRules
  }
];
var eslint_plugin_default = plugin;
export {
  eslint_plugin_default as default
};
//# sourceMappingURL=eslint-plugin.js.map