Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for compatibility with @typescript-eslint/no-unsafe-call rule #120

Merged
merged 2 commits into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"root": true,
"extends": ["xo", "xo-typescript"],
"parserOptions": {
"project": "tsconfig.tsd.json"
Expand Down
2 changes: 1 addition & 1 deletion source/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import * as meow from 'meow';
import meow from 'meow';
import formatter from './lib/formatter';
import tsd from './lib';

Expand Down
2 changes: 1 addition & 1 deletion source/lib/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as formatter from 'eslint-formatter-pretty';
import formatter from 'eslint-formatter-pretty';
import {Diagnostic} from './interfaces';

interface FileWithDiagnostics {
Expand Down
8 changes: 4 additions & 4 deletions source/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import * as readPkgUp from 'read-pkg-up';
import * as pathExists from 'path-exists';
import * as globby from 'globby';
import path from 'path';
import readPkgUp from 'read-pkg-up';
import pathExists from 'path-exists';
import globby from 'globby';
import {getDiagnostics as getTSDiagnostics} from './compiler';
import loadConfig from './config';
import getCustomDiagnostics from './rules';
Expand Down
6 changes: 3 additions & 3 deletions source/lib/rules/files-property.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import * as fs from 'fs';
import * as globby from 'globby';
import path from 'path';
import fs from 'fs';
import globby from 'globby';
import {Context, Diagnostic} from '../interfaces';
import {getJSONPropertyPosition} from '../utils';

Expand Down
4 changes: 2 additions & 2 deletions source/lib/rules/types-property.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import * as fs from 'fs';
import path from 'path';
import fs from 'fs';
import {Context, Diagnostic} from '../interfaces';
import {getJSONPropertyPosition} from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion source/test/assignability.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from 'path';
import path from 'path';
import test from 'ava';
import {verify} from './fixtures/utils';
import tsd from '..';
Expand Down
4 changes: 2 additions & 2 deletions source/test/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import path from 'path';
import test from 'ava';
import * as execa from 'execa';
import execa from 'execa';

interface ExecaError extends Error {
readonly exitCode: number;
Expand Down
2 changes: 1 addition & 1 deletion source/test/deprecated.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from 'path';
import path from 'path';
import test from 'ava';
import {verify} from './fixtures/utils';
import tsd from '..';
Expand Down
29 changes: 29 additions & 0 deletions source/test/eslint-compatibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import path from 'path';
import test from 'ava';
import execa from 'execa';

test('`expectType` is compatible with eslint @typescript-eslint/no-unsafe-call rule', t => {
try {
execa.sync(
'node_modules/.bin/eslint',
['source/test/fixtures/eslint-compatibility', '--no-ignore'],
{
cwd: path.join(__dirname, '../../')
}
);

t.fail('eslint should have found an error!');
} catch (error: unknown) {
if (!error) {
t.fail('Thrown error is falsy!');
}

const execaError = error as execa.ExecaError;

const outLines = execaError.stdout.trim().split('\n');

t.regex(outLines[0], /fixtures[/\\]eslint-compatibility[/\\]index.test-d.ts$/, 'Lint error found in unexpected file');
t.is(outLines[1], ' 9:1 error Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call');
t.is(outLines[3], '✖ 1 problem (1 error, 0 warnings)');
}
});
9 changes: 9 additions & 0 deletions source/test/fixtures/eslint-compatibility/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"root": false,
"parserOptions": {
"project": "source/test/fixtures/eslint-compatibility/tsconfig.json"
},
"rules": {
"@typescript-eslint/no-unsafe-call": "error"
}
}
6 changes: 6 additions & 0 deletions source/test/fixtures/eslint-compatibility/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare const one: {
(foo: string, bar: string): string;
(foo: number, bar: number): number;
};

export default one;
4 changes: 4 additions & 0 deletions source/test/fixtures/eslint-compatibility/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports.default = (foo, bar) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/restrict-plus-operands
return foo + bar;
};
9 changes: 9 additions & 0 deletions source/test/fixtures/eslint-compatibility/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {expectType} from '../../..';
import one from '.';

expectType<string>(one('foo', 'bar'));
expectType<number>(one(1, 2));

declare const anyVar: any;

anyVar();
3 changes: 3 additions & 0 deletions source/test/fixtures/eslint-compatibility/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "foo"
}
1 change: 1 addition & 0 deletions source/test/fixtures/eslint-compatibility/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion source/test/fixtures/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from 'path';
import path from 'path';
import {ExecutionContext} from 'ava';
import {Diagnostic} from '../../lib/interfaces';

Expand Down
2 changes: 1 addition & 1 deletion source/test/identicality.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from 'path';
import path from 'path';
import test from 'ava';
import {verify} from './fixtures/utils';
import tsd from '..';
Expand Down
2 changes: 1 addition & 1 deletion source/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from 'path';
import path from 'path';
import test from 'ava';
import {verify, verifyWithFileName} from './fixtures/utils';
import tsd from '..';
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.tsd.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noEmitOnError": true,
"forceConsistentCasingInFileNames": true
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
},
"exclude": [
"node_modules",
Expand Down