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

[fix] no-unused-modules: don't crash when lint file outside src-folder #1347

Merged
merged 1 commit into from
Apr 27, 2019
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
8 changes: 8 additions & 0 deletions src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ module.exports = {
return
}

// refresh list of source files
const srcFiles = resolveFiles(getSrc(src), ignoreExports)

// make sure file to be linted is included in source files
if (!srcFiles.has(file)) {
return
}

exports = exportList.get(file)

// special case: export * from
Expand Down
10 changes: 10 additions & 0 deletions tests/src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,13 @@ describe('do not report missing export for ignored file', () => {
invalid: [],
})
})

// lint file not available in `src`
ruleTester.run('no-unused-modules', rule, {
valid: [
test({ options: unusedExportsOptions,
code: `export const jsxFoo = 'foo'; export const jsxBar = 'bar'`,
filename: testFilePath('../jsx/named.jsx')}),
],
invalid: [],
})