File size: 2,975 Bytes
bc20498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import * as eslint from 'eslint';
import * as semver from 'semver';
import { c as convertConfigToRc } from './shared/eslint-compat-utils.1a5060cf.mjs';
import { g as getUnsupported } from './shared/eslint-compat-utils.3ecba7ac.mjs';
import { c as convertOptionToLegacy } from './shared/eslint-compat-utils.cb6790c2.mjs';
import 'module';

var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
let cacheRuleTester;
let cachePrefix = "";
function getRuleTester() {
  return cacheRuleTester != null ? cacheRuleTester : cacheRuleTester = getRuleTesterInternal();
  function getRuleTesterInternal() {
    if (semver.gte(eslint.Linter.version, "9.0.0-0")) {
      cachePrefix = "rule-to-test/";
      return eslint.RuleTester;
    }
    const flatRuleTester = getUnsupported().FlatRuleTester;
    if (flatRuleTester) {
      cachePrefix = "rule-to-test/";
      return patchForV8FlatRuleTester(flatRuleTester);
    }
    return getRuleTesterClassFromLegacyRuleTester();
  }
}
function getRuleIdPrefix() {
  getRuleTester();
  return cachePrefix;
}
function patchForV8FlatRuleTester(flatRuleTester) {
  return class RuleTesterWithPatch extends flatRuleTester {
    constructor(options) {
      super(patchConfig(options));
    }
  };
  function patchConfig(config) {
    return {
      files: ["**/*.*"],
      ...config
    };
  }
}
function getRuleTesterClassFromLegacyRuleTester() {
  return class RuleTesterForV8 extends eslint.RuleTester {
    constructor(options) {
      var _a;
      const defineRules = [];
      const { processor, ...others } = options;
      super(
        convertConfigToRc(others, {
          defineRule(...args) {
            defineRules.push(args);
          }
        })
      );
      __publicField(this, "defaultProcessor");
      for (const args of defineRules) {
        (_a = this.linter) == null ? void 0 : _a.defineRule(...args);
      }
      this.defaultProcessor = processor;
    }
    run(name, rule, tests) {
      super.run(name, rule, {
        valid: (tests.valid || []).map(
          (test) => typeof test === "string" ? test : convert(test, this.defaultProcessor)
        ),
        invalid: (tests.invalid || []).map(
          (test) => convert(test, this.defaultProcessor)
        )
      });
    }
  };
  function convert(config, defaultProcessor) {
    const { processor: configProcessor, ...otherConfig } = config;
    const processor = configProcessor || defaultProcessor;
    const converted = convertConfigToRc(otherConfig);
    if (!processor) {
      return converted;
    }
    return {
      ...converted,
      filename: convertOptionToLegacy(processor, config.filename, config)
    };
  }
}

export { getRuleIdPrefix, getRuleTester };