Skip to content

Commit

Permalink
add some tests, add doc comment
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Nov 14, 2023
1 parent 14e3560 commit 6ac3d03
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs/rules/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ import express from 'express/index';
import * as path from 'path';
```

The following patterns are considered problems when the configuration is set to "never" and the option "checkTypeImports" is set to `true`:

```js
import type { Foo } from './foo.ts';

export type { Foo } from './foo.ts';
```

The following patterns are considered problems when configuration set to "always":

```js
Expand Down Expand Up @@ -169,7 +177,7 @@ import express from 'express';
import foo from '@/foo';
```

The following patterns are considered problems when the option "checkTypeImports" is set to `true`:
The following patterns are considered problems when the configuration is set to "always" and the option "checkTypeImports" is set to `true`:

```js
import type { Foo } from './foo';
Expand Down
49 changes: 49 additions & 0 deletions tests/src/rules/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import rule from 'rules/extensions';
import { getTSParsers, test, testFilePath, parsers } from '../utils';

const ruleTester = new RuleTester();
const ruleTesterWithTypeScriptImports = new RuleTester({
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
},
});

ruleTester.run('extensions', rule, {
valid: [
Expand Down Expand Up @@ -660,5 +669,45 @@ describe('TypeScript', () => {
}),
],
});
ruleTesterWithTypeScriptImports.run(`${parser}: (with TS resolver) extensions are enforced for type imports/export when checkTypeImports is set`, rule, {
valid: [
test({
code: 'import type { MyType } from "./typescript-declare.ts";',
options: [
'always',
{ checkTypeImports: true },
],
parser,
}),
test({
code: 'export type { MyType } from "./typescript-declare.ts";',
options: [
'always',
{ checkTypeImports: true },
],
parser,
}),
],
invalid: [
test({
code: 'import type { MyType } from "./typescript-declare";',
errors: ['Missing file extension "ts" for "./typescript-declare"'],
options: [
'always',
{ checkTypeImports: true },
],
parser,
}),
test({
code: 'export type { MyType } from "./typescript-declare";',
errors: ['Missing file extension "ts" for "./typescript-declare"'],
options: [
'always',
{ checkTypeImports: true },
],
parser,
}),
],
});
});
});

0 comments on commit 6ac3d03

Please sign in to comment.