Skip to content

Commit 4c1bcf1

Browse files
committed
feature: @putout/test: add ability to use other linter instead of 🐊Putout
1 parent a5460e1 commit 4c1bcf1

File tree

3 files changed

+65
-50
lines changed

3 files changed

+65
-50
lines changed

packages/test/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ const test = createTest(import.meta.url, {
4848
});
4949
```
5050
51+
Or use another linter with the same signature as 🐊**Putout** using `lint` field:
52+
53+
```js
54+
const test = createTest(import.meta.url, {
55+
lint: putout,
56+
plugins: [
57+
['remove-unused-variables', rmVars],
58+
],
59+
});
60+
```
61+
5162
### `report(filename, message: string | string[])`
5263
5364
Check error message (or messages) of a plugin:

packages/test/lib/test.js

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,31 @@ const parsePlugin = (plugins) => {
101101
function createTest(dir, maybeOptions) {
102102
dir = join(dir, 'fixture');
103103

104-
const options = parseOptions(maybeOptions);
104+
const {lint = putout, ...options} = parseOptions(maybeOptions);
105+
105106
const plugin = parsePlugin(options.plugins);
106107

107108
preTest(test, plugin);
108109

109110
return test.extend({
110-
transform: transform(dir, options),
111-
noTransform: noTransform(dir, options),
112-
transformCode: transformCode(options),
113-
noTransformCode: noTransformCode(options),
111+
transform: transform(dir, lint, options),
112+
noTransform: noTransform(dir, lint, options),
113+
transformCode: transformCode(lint, options),
114+
noTransformCode: noTransformCode(lint, options),
114115

115116
progress: progress(dir, options),
116117
progressWithOptions: progressWithOptions(dir, options),
117118

118-
transformWithOptions: transformWithOptions(dir, options),
119-
noTransformWithOptions: noTransformWithOptions(dir, options),
119+
transformWithOptions: transformWithOptions(dir, lint, options),
120+
noTransformWithOptions: noTransformWithOptions(dir, lint, options),
120121

121-
report: report(dir, options),
122-
noReport: noReport(dir, options),
123-
noReportAfterTransform: noReportAfterTransform(dir, options),
124-
noReportAfterTransformWithOptions: noReportAfterTransformWithOptions(dir, options),
125-
reportWithOptions: reportWithOptions(dir, options),
126-
noReportWithOptions: noReportWithOptions(dir, options),
127-
reportCode: reportCode(options),
122+
report: report(dir, lint, options),
123+
noReport: noReport(dir, lint, options),
124+
noReportAfterTransform: noReportAfterTransform(dir, lint, options),
125+
noReportAfterTransformWithOptions: noReportAfterTransformWithOptions(dir, lint, options),
126+
reportWithOptions: reportWithOptions(dir, lint, options),
127+
noReportWithOptions: noReportWithOptions(dir, lint, options),
128+
reportCode: reportCode(lint, options),
128129
format: formatSave(dir, options),
129130
formatMany: formatManySave(dir, options),
130131
noFormat: noFormat(dir, options),
@@ -324,7 +325,7 @@ const progressWithOptions = (dir, options) => (t) => async (name, pluginOptions,
324325
return t.deepEqual(result, expected);
325326
};
326327

327-
const transform = currify((dir, options, t, name, transformed = null, addons = {}) => {
328+
const transform = currify((dir, lint, options, t, name, transformed = null, addons = {}) => {
328329
const {plugins} = options;
329330
const full = join(dir, name);
330331
const isStr = isString(transformed);
@@ -336,7 +337,7 @@ const transform = currify((dir, options, t, name, transformed = null, addons = {
336337

337338
addons = addons || {};
338339

339-
const {code} = putout(input, {
340+
const {code} = lint(input, {
340341
isTS,
341342
...options,
342343
plugins: [{
@@ -362,7 +363,7 @@ const transform = currify((dir, options, t, name, transformed = null, addons = {
362363
return t.equal(code, output);
363364
});
364365

365-
const transformWithOptions = currify((dir, options, t, name, pluginOptions) => {
366+
const transformWithOptions = currify((dir, lint, options, t, name, pluginOptions) => {
366367
const {writeFileSync} = global.__putout_test_fs;
367368
const full = join(dir, name);
368369
const [input, isTS] = readFixture(full);
@@ -373,7 +374,7 @@ const transformWithOptions = currify((dir, options, t, name, pluginOptions) => {
373374
[rule]: ['on', pluginOptions],
374375
};
375376

376-
const {code} = putout(input, {
377+
const {code} = lint(input, {
377378
isTS,
378379
rules,
379380
...options,
@@ -395,7 +396,7 @@ const parseRule = ({plugins}) => {
395396
return plugin[0] || keys(plugin)[0];
396397
};
397398

398-
const noTransformWithOptions = currify((dir, options, t, name, ruleOptions) => {
399+
const noTransformWithOptions = currify((dir, lint, options, t, name, ruleOptions) => {
399400
const full = join(dir, name);
400401
const [input, isTS] = readFixture(full);
401402

@@ -406,7 +407,7 @@ const noTransformWithOptions = currify((dir, options, t, name, ruleOptions) => {
406407
[rule]: ['on', ruleOptions],
407408
};
408409

409-
const {code} = putout(input, {
410+
const {code} = lint(input, {
410411
isTS,
411412
rules,
412413
...options,
@@ -425,7 +426,7 @@ const noTransformWithOptions = currify((dir, options, t, name, ruleOptions) => {
425426
return t.equal(code, input);
426427
});
427428

428-
const noTransform = currify((dir, options, t, name, addons = {}) => {
429+
const noTransform = currify((dir, lint, options, t, name, addons = {}) => {
429430
const full = join(dir, name);
430431
const [fixture] = readFixture(full);
431432

@@ -434,7 +435,7 @@ const noTransform = currify((dir, options, t, name, addons = {}) => {
434435
const {plugins} = options;
435436
const [input, isTS] = readFixture(full);
436437

437-
const {code} = putout(input, {
438+
const {code} = lint(input, {
438439
isTS,
439440
...options,
440441
plugins: [{
@@ -456,61 +457,61 @@ const noTransform = currify((dir, options, t, name, addons = {}) => {
456457
return t.equal(code, fixture);
457458
});
458459

459-
const transformCode = currify((options, t, input, output, isTS = false) => {
460-
const {code} = putout(input, {
460+
const transformCode = currify((lint, options, t, input, output, isTS = false) => {
461+
const {code} = lint(input, {
461462
isTS,
462463
...options,
463464
});
464465

465466
return t.equal(code, output);
466467
});
467468

468-
const noTransformCode = currify((options, t, input) => {
469-
const {code} = putout(input, options);
469+
const noTransformCode = currify((lint, options, t, input) => {
470+
const {code} = lint(input, options);
470471
return t.equal(code, input);
471472
});
472473

473474
const getMessage = ({message}) => message;
474475

475-
const report = (dir, options) => (t) => (name, message) => {
476+
const report = (dir, lint, options) => (t) => (name, message) => {
476477
checkReport(name, message);
477478

478479
const full = join(dir, name);
479480
const [source, isTS] = readFixture(full);
480481

481-
return reportCode({
482+
return reportCode(lint, {
482483
isTS,
483484
...options,
484485
}, t, source, message);
485486
};
486487

487-
const noReport = currify((dir, options, t, name) => {
488+
const noReport = currify((dir, lint, options, t, name) => {
488489
const full = join(dir, name);
489490
const [source, isTS] = readFixture(full);
490491

491492
rmFixture(`${full}-fix`);
492493

493-
return noReportCode({
494+
return noReportCode(lint, {
494495
isTS,
495496
...options,
496497
}, t, source);
497498
});
498499

499500
module.exports._createNoReport = noReport;
500501

501-
const noReportAfterTransform = currify((dir, options, t, name, addons = {}) => {
502+
const noReportAfterTransform = currify((dir, lint, options, t, name, addons = {}) => {
502503
const full = join(dir, name);
503504
const [source, isTS] = readFixture(full);
504505

505-
return noReportCodeAfterTransform({
506+
return noReportCodeAfterTransform(lint, {
506507
isTS,
507508
...options,
508509
}, t, source, addons);
509510
});
510511

511512
module.exports._createNoReportAfterTransform = noReportAfterTransform;
512513

513-
const noReportAfterTransformWithOptions = currify((dir, options, t, name, ruleOptions) => {
514+
const noReportAfterTransformWithOptions = currify((dir, lint, options, t, name, ruleOptions) => {
514515
const full = join(dir, name);
515516
const [source, isTS] = readFixture(full);
516517
const rule = parseRule(options);
@@ -519,7 +520,7 @@ const noReportAfterTransformWithOptions = currify((dir, options, t, name, ruleOp
519520
[rule]: ['on', ruleOptions],
520521
};
521522

522-
return noReportCodeAfterTransform({
523+
return noReportCodeAfterTransform(lint, {
523524
isTS,
524525
...options,
525526
rules: {
@@ -531,7 +532,7 @@ const noReportAfterTransformWithOptions = currify((dir, options, t, name, ruleOp
531532

532533
module.exports._createNoReportAfterTransformWithOptions = noReportAfterTransformWithOptions;
533534

534-
const reportWithOptions = currify((dir, options, t, name, message, ruleOptions) => {
535+
const reportWithOptions = currify((dir, lint, options, t, name, message, ruleOptions) => {
535536
const full = join(dir, name);
536537
const [source, isTS] = readFixture(full);
537538

@@ -541,14 +542,14 @@ const reportWithOptions = currify((dir, options, t, name, message, ruleOptions)
541542
[rule]: ['on', ruleOptions],
542543
};
543544

544-
return reportCode({
545+
return reportCode(lint, {
545546
...options,
546547
rules,
547548
isTS,
548549
}, t, source, message);
549550
});
550551

551-
const noReportWithOptions = currify((dir, options, t, name, ruleOptions) => {
552+
const noReportWithOptions = currify((dir, lint, options, t, name, ruleOptions) => {
552553
const full = join(dir, name);
553554
const [source, isTS] = readFixture(full);
554555

@@ -559,15 +560,15 @@ const noReportWithOptions = currify((dir, options, t, name, ruleOptions) => {
559560
[rule]: ['on', ruleOptions],
560561
};
561562

562-
return noReportCode({
563+
return noReportCode(lint, {
563564
isTS,
564565
...options,
565566
rules,
566567
}, t, source);
567568
});
568569

569-
const reportCode = currify((options, t, source, message) => {
570-
const {places} = putout(source, {
570+
const reportCode = currify((lint, options, t, source, message) => {
571+
const {places} = lint(source, {
571572
fix: false,
572573
...options,
573574
});
@@ -580,18 +581,18 @@ const reportCode = currify((options, t, source, message) => {
580581
return t.equal(resultMessages[0], message);
581582
});
582583

583-
const noReportCode = currify((options, t, source) => {
584-
const {places} = putout(source, {
584+
const noReportCode = currify((lint, options, t, source) => {
585+
const {places} = lint(source, {
585586
fix: false,
586587
...options,
587588
});
588589

589590
return t.deepEqual(places, [], 'should not report');
590591
});
591592

592-
const noReportCodeAfterTransform = currify((options, t, source, addons = {}) => {
593+
const noReportCodeAfterTransform = currify((lint, options, t, source, addons = {}) => {
593594
const {plugins} = options;
594-
const {places} = putout(source, {
595+
const {places} = lint(source, {
595596
fix: true,
596597
...options,
597598
plugins: [{

packages/test/test/report.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ const {join} = require('node:path');
55
const montag = require('montag');
66
const tryCatch = require('try-catch');
77
const {stub} = require('supertape');
8-
const {template} = require('putout');
8+
const putout = require('putout');
99

1010
const {
11+
createTest,
1112
_createNoReport,
1213
_createNoReportAfterTransform,
1314
_createNoReportAfterTransformWithOptions,
1415
} = require('..');
1516

16-
const test = require('..')(__dirname, {
17+
const {template} = putout;
18+
19+
const test = createTest(__dirname, {
1720
'remove-imports': {
1821
report: () => 'avoid imports',
1922
match: ({options}) => ({
@@ -72,7 +75,7 @@ test('putout: test: noReport', (t) => {
7275
plugins,
7376
};
7477

75-
const noReport = _createNoReport(dir, options);
78+
const noReport = _createNoReport(dir, putout, options);
7679
const deepEqual = stub();
7780

7881
const mockTest = {
@@ -126,7 +129,7 @@ test('putout: test: noReportAfterTransform: internal', (t) => {
126129
plugins,
127130
};
128131

129-
const noReportAfterTransform = _createNoReportAfterTransform(dir, options);
132+
const noReportAfterTransform = _createNoReportAfterTransform(dir, putout, options);
130133
const deepEqual = stub();
131134

132135
const mockTest = {
@@ -182,7 +185,7 @@ test('putout: test: noReportAfterTransformWithOptions: internal', (t) => {
182185
plugins,
183186
};
184187

185-
const noReportAfterTransformWithOptions = _createNoReportAfterTransformWithOptions(dir, options);
188+
const noReportAfterTransformWithOptions = _createNoReportAfterTransformWithOptions(dir, putout, options);
186189
const deepEqual = stub();
187190

188191
const mockTest = {
@@ -237,7 +240,7 @@ test('putout: test: report: with one argument', async (t) => {
237240
checkAssertionsCount: false,
238241
});
239242

240-
const testEmptyReport = require('..')(__dirname, {
243+
const testEmptyReport = createTest(__dirname, {
241244
'remove-imports': {
242245
report: () => '',
243246
match: ({options}) => ({

0 commit comments

Comments
 (0)