Skip to content

Commit

Permalink
Merge pull request #1347 from rfermann/1338
Browse files Browse the repository at this point in the history
[fix] `no-unused-modules`: don't crash when lint file outside src-folder
  • Loading branch information
ljharb authored Apr 27, 2019
2 parents 4620185 + bb686de commit f63dd26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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: [],
})

0 comments on commit f63dd26

Please sign in to comment.