Skip to content

Commit

Permalink
Merge f9d7e2b into 112a0bf
Browse files Browse the repository at this point in the history
  • Loading branch information
rfermann committed Nov 17, 2019
2 parents 112a0bf + f9d7e2b commit a7c34de
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/rules/no-unused-modules.js
Expand Up @@ -42,6 +42,7 @@ const VARIABLE_DECLARATION = 'VariableDeclaration'
const FUNCTION_DECLARATION = 'FunctionDeclaration'
const CLASS_DECLARATION = 'ClassDeclaration'
const DEFAULT = 'default'
const TYPE_ALIAS = 'TypeAlias'

let preparationDone = false
const importList = new Map()
Expand Down Expand Up @@ -391,6 +392,7 @@ module.exports = {
}

exports = exportList.get(file)
console.log('file: ', file)

// special case: export * from
const exportAll = exports.get(EXPORT_ALL_DECLARATION)
Expand All @@ -409,8 +411,10 @@ module.exports = {
}

const exportStatement = exports.get(exportedValue)
console.log('exportStatement: ', exportStatement)

const value = exportedValue === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportedValue
console.log('value: ', value)

if (typeof exportStatement !== 'undefined'){
if (exportStatement.whereUsed.size < 1) {
Expand Down Expand Up @@ -463,7 +467,8 @@ module.exports = {
if (declaration) {
if (
declaration.type === FUNCTION_DECLARATION ||
declaration.type === CLASS_DECLARATION
declaration.type === CLASS_DECLARATION ||
declaration.type === TYPE_ALIAS
) {
newExportIdentifiers.add(declaration.id.name)
}
Expand Down Expand Up @@ -788,7 +793,8 @@ module.exports = {
if (node.declaration) {
if (
node.declaration.type === FUNCTION_DECLARATION ||
node.declaration.type === CLASS_DECLARATION
node.declaration.type === CLASS_DECLARATION ||
node.declaration.type === TYPE_ALIAS
) {
checkUsage(node, node.declaration.id.name)
}
Expand Down
1 change: 1 addition & 0 deletions tests/files/no-unused-modules/flow-0.js
@@ -0,0 +1 @@
import { type FooType } from './flow-2';
2 changes: 2 additions & 0 deletions tests/files/no-unused-modules/flow-1.js
@@ -0,0 +1,2 @@
// @flow strict
export type Bar = number;
2 changes: 2 additions & 0 deletions tests/files/no-unused-modules/flow-2.js
@@ -0,0 +1,2 @@
// @flow strict
export type FooType = string;
32 changes: 32 additions & 0 deletions tests/src/rules/no-unused-modules.js
Expand Up @@ -638,3 +638,35 @@ describe('do not report unused export for files mentioned in package.json', () =
],
})
})

describe('correctly report flow types', () => {
ruleTester.run('no-unused-modules', rule, {
valid: [
test({
options: unusedExportsOptions,
code: 'import { type FooType } from "./flow-2";',
parser: require.resolve('babel-eslint'),
filename: testFilePath('./no-unused-modules/flow-0.js'),
}),
test({
options: unusedExportsOptions,
code: `// @flow strict
export type FooType = string;`,
parser: require.resolve('babel-eslint'),
filename: testFilePath('./no-unused-modules/flow-2.js'),
}),
],
invalid: [
test({
options: unusedExportsOptions,
code: `// @flow strict
export type Bar = string;`,
parser: require.resolve('babel-eslint'),
filename: testFilePath('./no-unused-modules/flow-1.js'),
errors: [
error(`exported declaration 'Bar' not used within other modules`),
],
}),
],
})
})

0 comments on commit a7c34de

Please sign in to comment.