Skip to content

Commit

Permalink
[Fix] first handling of import = require
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasKunnen committed Dec 10, 2020
1 parent 8dd6d03 commit 277c86f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/rules/first.js
@@ -1,5 +1,11 @@
import docsUrl from '../docsUrl'

function getImportValue(node) {
return node.type === 'ImportDeclaration'
? node.source.value
: node.moduleReference.expression.value
}

module.exports = {
meta: {
type: 'suggestion',
Expand Down Expand Up @@ -43,13 +49,13 @@ module.exports = {

anyExpressions = true

if (node.type === 'ImportDeclaration') {
if (node.type === 'ImportDeclaration' || node.type === 'TSImportEqualsDeclaration') {
if (absoluteFirst) {
if (/^\./.test(node.source.value)) {
if (/^\./.test(getImportValue(node))) {
anyRelative = true
} else if (anyRelative) {
context.report({
node: node.source,
node: node.type === 'ImportDeclaration' ? node.source : node.moduleReference,
message: 'Absolute imports should come before relative imports.',
})
}
Expand Down

0 comments on commit 277c86f

Please sign in to comment.