Skip to content
Permalink
Browse files

[refactor] fix eslint 6 compat by fixing imports

  • Loading branch information...
ljharb committed May 15, 2019
1 parent 2f85fbe commit 753c9dbf04cca2729bf693d99106b68c81119d41
Showing with 33 additions and 18 deletions.
  1. +7 −1 .travis.yml
  2. +1 −1 src/ExportMap.js
  3. +25 −16 src/rules/no-unused-modules.js
@@ -8,6 +8,7 @@ node_js:
os: linux

env:
- ESLINT_VERSION=^6.0.0-alpha
- ESLINT_VERSION=5
- ESLINT_VERSION=4
- ESLINT_VERSION=3
@@ -49,12 +50,17 @@ matrix:
exclude:
- node_js: '4'
env: ESLINT_VERSION=5

- node_js: '4'
env: ESLINT_VERSION=^6.0.0-alpha
- node_js: '6'
env: ESLINT_VERSION=^6.0.0-alpha

fast_finish: true
allow_failures:
# issues with typescript deps in this version intersection
- node_js: '4'
env: ESLINT_VERSION=4
- env: ESLINT_VERSION=^6.0.0-alpha

before_install:
- 'nvm install-latest-npm'
@@ -4,7 +4,7 @@ import doctrine from 'doctrine'

import debug from 'debug'

import SourceCode from 'eslint/lib/util/source-code'
import { SourceCode } from 'eslint'

import parse from 'eslint-module-utils/parse'
import resolve from 'eslint-module-utils/resolve'
@@ -1,5 +1,5 @@
/**
* @fileOverview Ensures that modules contain exports and/or all
* @fileOverview Ensures that modules contain exports and/or all
* modules are consumed within other modules.
* @author René Fermann
*/
@@ -9,19 +9,28 @@ import resolve from 'eslint-module-utils/resolve'
import docsUrl from '../docsUrl'

// eslint/lib/util/glob-util has been moved to eslint/lib/util/glob-utils with version 5.3
// and has been moved to eslint/lib/cli-engine/file-enumerator in version 6
let listFilesToProcess
try {
listFilesToProcess = require('eslint/lib/util/glob-utils').listFilesToProcess
} catch (err) {
listFilesToProcess = require('eslint/lib/util/glob-util').listFilesToProcess
var FileEnumerator = require('eslint/lib/cli-engine/file-enumerator').FileEnumerator
listFilesToProcess = function (src) {
var e = new FileEnumerator()
return Array.from(e.iterateFiles(src))
}
} catch (e1) {
try {
listFilesToProcess = require('eslint/lib/util/glob-utils').listFilesToProcess
} catch (e2) {
listFilesToProcess = require('eslint/lib/util/glob-util').listFilesToProcess
}
}

const EXPORT_DEFAULT_DECLARATION = 'ExportDefaultDeclaration'
const EXPORT_NAMED_DECLARATION = 'ExportNamedDeclaration'
const EXPORT_ALL_DECLARATION = 'ExportAllDeclaration'
const IMPORT_DECLARATION = 'ImportDeclaration'
const IMPORT_DECLARATION = 'ImportDeclaration'
const IMPORT_NAMESPACE_SPECIFIER = 'ImportNamespaceSpecifier'
const IMPORT_DEFAULT_SPECIFIER = 'ImportDefaultSpecifier'
const IMPORT_DEFAULT_SPECIFIER = 'ImportDefaultSpecifier'
const VARIABLE_DECLARATION = 'VariableDeclaration'
const FUNCTION_DECLARATION = 'FunctionDeclaration'
const DEFAULT = 'default'
@@ -37,7 +46,7 @@ const isNodeModule = path => {

/**
* read all files matching the patterns in src and ignoreExports
*
*
* return all files matching src pattern, which are not matching the ignoreExports pattern
*/
const resolveFiles = (src, ignoreExports) => {
@@ -73,7 +82,7 @@ const prepareImportsAndExports = (srcFiles, context) => {
currentExportAll.add(value().path)
})
exportAll.set(file, currentExportAll)

reexports.forEach((value, key) => {
if (key === DEFAULT) {
exports.set(IMPORT_DEFAULT_SPECIFIER, { whereUsed: new Set() })
@@ -106,7 +115,7 @@ const prepareImportsAndExports = (srcFiles, context) => {
imports.set(key, value.importedSpecifiers)
})
importList.set(file, imports)

// build up export list only, if file is not ignored
if (ignoredFiles.has(file)) {
return
@@ -266,7 +275,7 @@ module.exports = {
if (unusedExports && !preparationDone) {
doPreparation(src, ignoreExports, context)
}

const file = context.getFilename()

const checkExportPresence = node => {
@@ -329,9 +338,9 @@ module.exports = {
}

const exportStatement = exports.get(exportedValue)

const value = exportedValue === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportedValue

if (typeof exportStatement !== 'undefined'){
if (exportStatement.whereUsed.size < 1) {
context.report(
@@ -410,7 +419,7 @@ module.exports = {
// preserve information about namespace imports
let exportAll = exports.get(EXPORT_ALL_DECLARATION)
let namespaceImports = exports.get(IMPORT_NAMESPACE_SPECIFIER)

if (typeof namespaceImports === 'undefined') {
namespaceImports = { whereUsed: new Set() }
}
@@ -434,13 +443,13 @@ module.exports = {
if (typeof oldImportPaths === 'undefined') {
oldImportPaths = new Map()
}

const oldNamespaceImports = new Set()
const newNamespaceImports = new Set()

const oldExportAll = new Set()
const newExportAll = new Set()

const oldDefaultImports = new Set()
const newDefaultImports = new Set()

@@ -493,7 +502,7 @@ module.exports = {
if (!resolvedPath) {
return
}

if (isNodeModule(resolvedPath)) {
return
}

0 comments on commit 753c9db

Please sign in to comment.
You can’t perform that action at this time.