Skip to content

Commit

Permalink
[fix] no-unused-modules: prevent memory overflow
Browse files Browse the repository at this point in the history
Fixes #1364.
  • Loading branch information
rfermann authored and ljharb committed Aug 8, 2019
1 parent f235aab commit 7ffbf03
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let preparationDone = false
const importList = new Map()
const exportList = new Map()
const ignoredFiles = new Set()
const filesOutsideSrc = new Set()

const isNodeModule = path => {
return /\/(node_modules)\//.test(path)
Expand Down Expand Up @@ -192,8 +193,9 @@ const getSrc = src => {
* prepare the lists of existing imports and exports - should only be executed once at
* the start of a new eslint run
*/
let srcFiles
const doPreparation = (src, ignoreExports, context) => {
const srcFiles = resolveFiles(getSrc(src), ignoreExports)
srcFiles = resolveFiles(getSrc(src), ignoreExports)
prepareImportsAndExports(srcFiles, context)
determineUsage()
preparationDone = true
Expand Down Expand Up @@ -375,12 +377,17 @@ module.exports = {
return
}

// refresh list of source files
const srcFiles = resolveFiles(getSrc(src), ignoreExports)
if (filesOutsideSrc.has(file)) {
return
}

// make sure file to be linted is included in source files
if (!srcFiles.has(file)) {
return
srcFiles = resolveFiles(getSrc(src), ignoreExports)
if (!srcFiles.has(file)) {
filesOutsideSrc.add(file)
return
}
}

exports = exportList.get(file)
Expand Down

0 comments on commit 7ffbf03

Please sign in to comment.