Skip to content

Commit

Permalink
Merge 6a07c81 into 6512110
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 17, 2019
2 parents 6512110 + 6a07c81 commit 06e614b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"eslint-import-resolver-node": "^0.3.2",
"eslint-module-utils": "^2.4.0",
"has": "^1.0.3",
"lodash": "^4.17.11",
"minimatch": "^3.0.4",
"read-pkg-up": "^2.0.0",
"resolve": "^1.11.0"
Expand Down
27 changes: 11 additions & 16 deletions src/core/importType.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import cond from 'lodash/cond'
import coreModules from 'resolve/lib/core'
import { join } from 'path'

import resolve from 'eslint-module-utils/resolve'

function constant(value) {
return () => value
}

function baseModule(name) {
if (isScoped(name)) {
const [scope, pkg] = name.split('/')
Expand Down Expand Up @@ -76,17 +71,17 @@ function isRelativeToSibling(name) {
return /^\.[\\/]/.test(name)
}

const typeTest = cond([
[isAbsolute, constant('absolute')],
[isBuiltIn, constant('builtin')],
[isInternalModule, constant('internal')],
[isExternalModule, constant('external')],
[isScoped, constant('external')],
[isRelativeToParent, constant('parent')],
[isIndex, constant('index')],
[isRelativeToSibling, constant('sibling')],
[constant(true), constant('unknown')],
])
function typeTest(name, settings, path) {
if (isAbsolute(name, settings, path)) { return 'absolute' }
if (isBuiltIn(name, settings, path)) { return 'builtin' }
if (isInternalModule(name, settings, path)) { return 'internal' }
if (isExternalModule(name, settings, path)) { return 'external' }
if (isScoped(name, settings, path)) { return 'external' }
if (isRelativeToParent(name, settings, path)) { return 'parent' }
if (isIndex(name, settings, path)) { return 'index' }
if (isRelativeToSibling(name, settings, path)) { return 'sibling' }
return 'unknown'
}

export default function resolveImportType(name, context) {
return typeTest(name, context.settings, resolve(name, context))
Expand Down
9 changes: 4 additions & 5 deletions src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'path'
import fs from 'fs'
import { isArray, isEmpty } from 'lodash'
import readPkgUp from 'read-pkg-up'
import minimatch from 'minimatch'
import resolve from 'eslint-module-utils/resolve'
Expand Down Expand Up @@ -31,15 +30,15 @@ function getDependencies(context, packageDir) {
peerDependencies: {},
}

if (!isEmpty(packageDir)) {
if (!isArray(packageDir)) {
if (packageDir && packageDir.length > 0) {
if (!Array.isArray(packageDir)) {
paths = [path.resolve(packageDir)]
} else {
paths = packageDir.map(dir => path.resolve(dir))
}
}

if (!isEmpty(paths)) {
if (paths.length > 0) {
// use rule config to find package.json
paths.forEach(dir => {
const _packageContent = extractDepFields(
Expand Down Expand Up @@ -70,7 +69,7 @@ function getDependencies(context, packageDir) {

return packageContent
} catch (e) {
if (!isEmpty(paths) && e.code === 'ENOENT') {
if (paths.length > 0 && e.code === 'ENOENT') {
context.report({
message: 'The package.json file could not be found.',
loc: { line: 0, column: 0 },
Expand Down
2 changes: 1 addition & 1 deletion tests/dep-time-travel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ npm install --no-save eslint@$ESLINT_VERSION --ignore-scripts || true
# completely remove the new typescript parser for ESLint < v5
if [[ "$ESLINT_VERSION" -lt "5" ]]; then
echo "Removing @typescript-eslint/parser..."
npm uninstall @typescript-eslint/parser
npm uninstall --no-save @typescript-eslint/parser
fi

# use these alternate typescript dependencies for ESLint < v4
Expand Down
2 changes: 1 addition & 1 deletion tests/src/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('Typescript', function () {
parsers.push(require.resolve('@typescript-eslint/parser'))
}

if (semver.satisfies(eslintPkg.version, '<6.0.0')) {
if (semver.satisfies(eslintPkg.version, '> 3 && <6.0.0')) {
parsers.push(require.resolve('typescript-eslint-parser'))
}

Expand Down

0 comments on commit 06e614b

Please sign in to comment.