2 var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 if (k2 === undefined) k2 = k;
4 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5 }) : (function(o, m, k, k2) {
6 if (k2 === undefined) k2 = k;
9 var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10 Object.defineProperty(o, "default", { enumerable: true, value: v });
14 var __importStar = (this && this.__importStar) || function (mod) {
15 if (mod && mod.__esModule) return mod;
17 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18 __setModuleDefault(result, mod);
21 var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
22 if (!privateMap.has(receiver)) {
23 throw new TypeError("attempted to set private field on non-instance");
25 privateMap.set(receiver, value);
28 var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
29 if (!privateMap.has(receiver)) {
30 throw new TypeError("attempted to get private field on non-instance");
32 return privateMap.get(receiver);
35 Object.defineProperty(exports, "__esModule", { value: true });
36 exports.RuleTester = exports.noFormat = void 0;
37 const path = __importStar(require("path"));
38 const TSESLint = __importStar(require("../ts-eslint"));
39 const parser = '@typescript-eslint/parser';
40 class RuleTester extends TSESLint.RuleTester {
41 // as of eslint 6 you have to provide an absolute path to the parser
42 // but that's not as clean to type, this saves us trying to manually enforce
43 // that contributors require.resolve everything
44 constructor(options) {
46 super(Object.assign(Object.assign({}, options), { parserOptions: Object.assign(Object.assign({}, options.parserOptions), { warnOnUnsupportedTypeScriptVersion: (_b = (_a = options.parserOptions) === null || _a === void 0 ? void 0 : _a.warnOnUnsupportedTypeScriptVersion) !== null && _b !== void 0 ? _b : false }), parser: require.resolve(options.parser) }));
47 _options.set(this, void 0);
48 __classPrivateFieldSet(this, _options, options);
49 // make sure that the parser doesn't hold onto file handles between tests
50 // on linux (i.e. our CI env), there can be very a limited number of watch handles available
53 // instead of creating a hard dependency, just use a soft require
54 // a bit weird, but if they're using this tooling, it'll be installed
55 require(parser).clearCaches();
62 getFilename(options) {
65 const filename = `file.ts${((_a = options.ecmaFeatures) === null || _a === void 0 ? void 0 : _a.jsx) ? 'x' : ''}`;
66 if (options.project) {
67 return path.join(options.tsconfigRootDir != null
68 ? options.tsconfigRootDir
69 : process.cwd(), filename);
73 else if (__classPrivateFieldGet(this, _options).parserOptions) {
74 return this.getFilename(__classPrivateFieldGet(this, _options).parserOptions);
78 // as of eslint 6 you have to provide an absolute path to the parser
79 // If you don't do that at the test level, the test will fail somewhat cryptically...
80 // This is a lot more explicit
81 run(name, rule, testsReadonly) {
82 const errorMessage = `Do not set the parser at the test level unless you want to use a parser other than ${parser}`;
83 const tests = Object.assign({}, testsReadonly);
84 // standardize the valid tests as objects
85 tests.valid = tests.valid.map(test => {
86 if (typeof test === 'string') {
93 tests.valid = tests.valid.map(test => {
94 if (typeof test !== 'string') {
95 if (test.parser === parser) {
96 throw new Error(errorMessage);
99 return Object.assign(Object.assign({}, test), { filename: this.getFilename(test.parserOptions) });
104 tests.invalid = tests.invalid.map(test => {
105 if (test.parser === parser) {
106 throw new Error(errorMessage);
108 if (!test.filename) {
109 return Object.assign(Object.assign({}, test), { filename: this.getFilename(test.parserOptions) });
113 super.run(name, rule, tests);
116 exports.RuleTester = RuleTester;
117 _options = new WeakMap();
119 * Simple no-op tag to mark code samples as "should not format with prettier"
120 * for the internal/plugin-test-formatting lint rule
122 function noFormat(strings, ...keys) {
123 const lastIndex = strings.length - 1;
124 return (strings.slice(0, lastIndex).reduce((p, s, i) => p + s + keys[i], '') +
127 exports.noFormat = noFormat;
128 //# sourceMappingURL=RuleTester.js.map