Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: import-js/eslint-plugin-import
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.21.1
Choose a base ref
...
head repository: import-js/eslint-plugin-import
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.21.2
Choose a head ref
  • 6 commits
  • 9 files changed
  • 1 contributor

Commits on Jun 8, 2020

  1. Copy the full SHA
    1951ef5 View commit details
  2. Copy the full SHA
    cc604c1 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    903e8fb View commit details

Commits on Jun 9, 2020

  1. Verified

    This commit was signed with the committer’s verified signature.
    stipsan Cody Olsen
    Copy the full SHA
    4ce280a View commit details
  2. Copy the full SHA
    ffd540f View commit details
  3. Bump to v2.21.2

    ljharb committed Jun 9, 2020
    Copy the full SHA
    f53e872 View commit details
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,12 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## [Unreleased]

## [2.21.2] - 2020-06-09
### Fixed
- [`order`]: avoid a crash on TypeScript’s `export import` syntax ([#1808], thanks [@ljharb])
- [`newline-after-import`]: consider TypeScript `import =` syntax' ([#1811], thanks [@ljharb])
- [`no-internal-modules`]: avoid a crash on a named export declaration ([#1814], thanks [@ljharb])

## [2.21.1] - 2020-06-07
### Fixed
- TypeScript: [`import/named`]: avoid requiring `typescript` when not using TS ([#1805], thanks [@ljharb])
@@ -897,6 +903,10 @@ for info on changes for earlier releases.
[#211]: https://github.com/benmosher/eslint-plugin-import/pull/211
[#164]: https://github.com/benmosher/eslint-plugin-import/pull/164
[#157]: https://github.com/benmosher/eslint-plugin-import/pull/157
[#1814]: https://github.com/benmosher/eslint-plugin-import/issues/1814
[#1811]: https://github.com/benmosher/eslint-plugin-import/issues/1811
[#1808]: https://github.com/benmosher/eslint-plugin-import/issues/1808
[#1805]: https://github.com/benmosher/eslint-plugin-import/issues/1805
[#1565]: https://github.com/benmosher/eslint-plugin-import/issues/1565
[#1366]: https://github.com/benmosher/eslint-plugin-import/issues/1366
[#1334]: https://github.com/benmosher/eslint-plugin-import/issues/1334
@@ -982,7 +992,8 @@ for info on changes for earlier releases.
[#119]: https://github.com/benmosher/eslint-plugin-import/issues/119
[#89]: https://github.com/benmosher/eslint-plugin-import/issues/89

[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.21.1...HEAD
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.21.2...HEAD
[2.21.2]: https://github.com/benmosher/eslint-plugin-import/compare/v2.21.1...v2.21.2
[2.21.1]: https://github.com/benmosher/eslint-plugin-import/compare/v2.21.0...v2.21.1
[2.21.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.20.2...v2.21.0
[2.20.1]: https://github.com/benmosher/eslint-plugin-import/compare/v2.20.1...v2.20.2
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-import",
"version": "2.21.1",
"version": "2.21.2",
"description": "Import with sanity.",
"engines": {
"node": ">=4"
@@ -80,7 +80,7 @@
"eslint-plugin-json": "^2.1.1",
"fs-copy-file-sync": "^1.1.1",
"glob": "^7.1.6",
"in-publish": "^2.0.0",
"in-publish": "^2.0.1",
"linklocal": "^2.8.2",
"lodash.isarray": "^4.0.0",
"mocha": "^3.5.3",
@@ -90,7 +90,7 @@
"rimraf": "^2.7.1",
"semver": "^6.3.0",
"sinon": "^2.4.1",
"typescript": "~3.8.3",
"typescript": "~3.9.5",
"typescript-eslint-parser": "^22.0.0"
},
"peerDependencies": {
2 changes: 1 addition & 1 deletion src/core/importType.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ function baseModule(name) {
}

export function isAbsolute(name) {
return name.indexOf('/') === 0
return name && name.startsWith('/')
}

// path is defined only when a resolver resolves to a non-standard path
11 changes: 7 additions & 4 deletions src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
@@ -115,16 +115,19 @@ after ${type} statement not followed by another ${type}.`,
level--
}

return {
ImportDeclaration: function (node) {
function checkImport(node) {
const { parent } = node
const nodePosition = parent.body.indexOf(node)
const nextNode = parent.body[nodePosition + 1]

if (nextNode && nextNode.type !== 'ImportDeclaration') {
if (nextNode && nextNode.type !== 'ImportDeclaration' && nextNode.type !== 'TSImportEqualsDeclaration') {
checkForNewLine(node, nextNode, 'import')
}
},
}

return {
ImportDeclaration: checkImport,
TSImportEqualsDeclaration: checkImport,
CallExpression: function(node) {
if (isStaticRequire(node) && level === 0) {
requireCalls.push(node)
4 changes: 3 additions & 1 deletion src/rules/no-internal-modules.js
Original file line number Diff line number Diff line change
@@ -95,7 +95,9 @@ module.exports = {
checkImportForReaching(node.source.value, node.source)
},
ExportNamedDeclaration(node) {
checkImportForReaching(node.source.value, node.source)
if (node.source) {
checkImportForReaching(node.source.value, node.source)
}
},
CallExpression(node) {
if (isStaticRequire(node)) {
2 changes: 2 additions & 0 deletions src/rules/order.js
Original file line number Diff line number Diff line change
@@ -611,6 +611,8 @@ module.exports = {
let name
if (node.moduleReference.type === 'TSExternalModuleReference') {
name = node.moduleReference.expression.value
} else if (node.isExport) {
name = node.moduleReference.name
} else {
name = null
}
39 changes: 39 additions & 0 deletions tests/src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { RuleTester } from 'eslint'
import flatMap from 'array.prototype.flatmap'

import { getTSParsers } from '../utils'

const IMPORT_ERROR_MESSAGE = 'Expected 1 empty line after import statement not followed by another import.'
const IMPORT_ERROR_MESSAGE_MULTIPLE = (count) => {
@@ -175,6 +178,42 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
parserOptions: { sourceType: 'module' },
parser: require.resolve('babel-eslint'),
},
...flatMap(getTSParsers(), (parser) => [
{
code: `
import { ExecaReturnValue } from 'execa';
import execa = require('execa');
`,
parser: parser,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
},
{
code: `
import execa = require('execa');
import { ExecaReturnValue } from 'execa';
`,
parser: parser,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
},
{
code: `
import { ExecaReturnValue } from 'execa';
import execa = require('execa');
import { ExecbReturnValue } from 'execb';
`,
parser: parser,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
},
{
code: `
import execa = require('execa');
import { ExecaReturnValue } from 'execa';
import execb = require('execb');
`,
parser: parser,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
},
]),
],

invalid: [
24 changes: 23 additions & 1 deletion tests/src/rules/no-internal-modules.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { RuleTester } from 'eslint'
import flatMap from 'array.prototype.flatmap'
import rule from 'rules/no-internal-modules'

import { test, testFilePath } from '../utils'
import { test, testFilePath, getTSParsers } from '../utils'

const ruleTester = new RuleTester()

@@ -92,6 +93,27 @@ ruleTester.run('no-internal-modules', rule, {
allow: [ '**/index{.js,}' ],
} ],
}),
test({
code: `
export class AuthHelper {
static checkAuth(auth) {
}
}
`,
}),
...flatMap(getTSParsers(), (parser) => [
test({
code: `
export class AuthHelper {
public static checkAuth(auth?: string): boolean {
}
}
`,
parser: parser,
}),
]),
],

invalid: [
96 changes: 51 additions & 45 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { test, getTSParsers, getNonDefaultParsers } from '../utils'
import { RuleTester } from 'eslint'
import eslintPkg from 'eslint/package.json'
import semver from 'semver'
import flatMap from 'array.prototype.flatmap'

const ruleTester = new RuleTester()
, rule = require('rules/order')
@@ -167,8 +168,8 @@ ruleTester.run('order', rule, {
var index = require('./');
`,
}),
// Export equals expressions should be on top alongside with ordinary import-statements.
...getTSParsers().map(parser => (
...flatMap(getTSParsers(), parser => [
// Export equals expressions should be on top alongside with ordinary import-statements.
test({
code: `
import async, {foo1} from 'async';
@@ -181,8 +182,15 @@ ruleTester.run('order', rule, {
var index = require('./');
`,
parser,
})
)),
}),

test({
code: `
export import CreateSomething = _CreateSomething;
`,
parser,
}),
]),
// Adding unknown import types (e.g. using a resolver alias via babel) to the groups.
test({
code: `
@@ -1158,7 +1166,7 @@ ruleTester.run('order', rule, {
message: '`fs` import should occur after import of `../foo/bar`',
}],
}),
...getTSParsers().map(parser => (
...flatMap(getTSParsers(), parser => [
test({
code: `
var fs = require('fs');
@@ -1174,8 +1182,44 @@ ruleTester.run('order', rule, {
errors: [{
message: '`fs` import should occur after import of `../foo/bar`',
}],
})
)),
}),
{
code: `
var async = require('async');
var fs = require('fs');
`,
output: `
var fs = require('fs');
var async = require('async');
`,
parser,
errors: [{
message: '`fs` import should occur before import of `async`',
}],
},
test({
code: `
import sync = require('sync');
import async, {foo1} from 'async';
import index from './';
`,
output: `
import async, {foo1} from 'async';
import sync = require('sync');
import index from './';
`,
options: [{
groups: ['external', 'index'],
alphabetize: {order: 'asc'},
}],
parser,
errors: [{
message: '`async` import should occur before import of `sync`',
}],
}),
]),
// Default order using import with custom import alias
test({
code: `
@@ -1909,20 +1953,6 @@ ruleTester.run('order', rule, {
message: '`fs` import should occur before import of `async`',
}],
})),
...getTSParsers().map(parser => ({
code: `
var async = require('async');
var fs = require('fs');
`,
output: `
var fs = require('fs');
var async = require('async');
`,
parser,
errors: [{
message: '`fs` import should occur before import of `async`',
}],
})),
// Option alphabetize: {order: 'asc'}
test({
code: `
@@ -1947,30 +1977,6 @@ ruleTester.run('order', rule, {
message: '`Bar` import should occur before import of `bar`',
}],
}),
...getTSParsers().map(parser => (
test({
code: `
import sync = require('sync');
import async, {foo1} from 'async';
import index from './';
`,
output: `
import async, {foo1} from 'async';
import sync = require('sync');
import index from './';
`,
options: [{
groups: ['external', 'index'],
alphabetize: {order: 'asc'},
}],
parser,
errors: [{
message: '`async` import should occur before import of `sync`',
}],
})
)),
// Option alphabetize: {order: 'desc'}
test({
code: `