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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
@@ -1,4 +1,5 @@
{
"root": true,
"extends": ["xo", "xo-typescript"],
"parserOptions": {
"project": "tsconfig.tsd.json"
Expand Down
29 changes: 29 additions & 0 deletions source/test/eslint-compatibility.ts
@@ -0,0 +1,29 @@
import * as path from 'path';
BendingBender marked this conversation as resolved.
Show resolved Hide resolved
import test from 'ava';
import * as 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 (e: unknown) {
BendingBender marked this conversation as resolved.
Show resolved Hide resolved
if (!e) {
t.fail('Thrown error is falsy!');
}

const error = e as execa.ExecaError;

const outLines = error.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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,3 @@
{
"name": "foo"
}
1 change: 1 addition & 0 deletions source/test/fixtures/eslint-compatibility/tsconfig.json
@@ -0,0 +1 @@
{}