-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix]
no-unused-modules
: fix usage of import/extensions
settings
- Loading branch information
Showing
5 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {b} from './file-ts-b'; | ||
|
||
export const a = b + 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const b = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { test, testFilePath } from '../utils' | ||
import typescriptConfig from '../../../config/typescript' | ||
|
||
import { RuleTester } from 'eslint' | ||
|
||
// We need to clear the cache to reinitialize the rule for Typescript only | ||
delete require.cache[require.resolve('rules/no-unused-modules')] | ||
|
||
const ruleTester = new RuleTester(typescriptConfig) | ||
, rule = require('rules/no-unused-modules') | ||
|
||
const error = message => ({ ruleId: 'no-unused-modules', message }) | ||
|
||
const unusedExportsTypescriptOptions = [{ | ||
unusedExports: true, | ||
src: [testFilePath('./no-unused-modules/typescript')], | ||
ignoreExports: undefined, | ||
}] | ||
|
||
describe('correctly work with Typescript only files', () => { | ||
ruleTester.run('no-unused-modules', rule, { | ||
valid: [ | ||
test({ | ||
options: unusedExportsTypescriptOptions, | ||
code: 'import a from "file-a";', | ||
parser: require.resolve('@typescript-eslint/parser'), | ||
filename: testFilePath('./no-unused-modules/typescript/file-ts-a.ts'), | ||
}), | ||
], | ||
invalid: [ | ||
test({ | ||
options: unusedExportsTypescriptOptions, | ||
code: `export const b = 2;`, | ||
parser: require.resolve('@typescript-eslint/parser'), | ||
filename: testFilePath('./no-unused-modules/typescript/file-ts-b.ts'), | ||
errors: [ | ||
error(`exported declaration 'b' not used within other modules`), | ||
], | ||
}), | ||
], | ||
}) | ||
}) |