Skip to content

Commit

Permalink
extensions: check importPath extension with a dot
Browse files Browse the repository at this point in the history
  • Loading branch information
dplusic authored and ljharb committed Nov 21, 2016
1 parent 523789f commit 3a03aca
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/rules/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = {
create: function (context) {

const props = buildProperties(context)

function getModifier(extension) {
return props.pattern[extension] || props.defaultConfig
}
Expand Down Expand Up @@ -131,11 +131,10 @@ module.exports = {
const extension = path.extname(resolvedPath || importPath).substring(1)

// determine if this is a module
const isPackageMain =
isExternalModuleMain(importPath, context.settings) ||
isScopedMain(importPath)
const isPackageMain = isExternalModuleMain(importPath, context.settings)
|| isScopedMain(importPath)

if (!extension || !importPath.endsWith(extension)) {
if (!extension || !importPath.endsWith(`.${extension}`)) {
const extensionRequired = isUseOfExtensionRequired(extension, isPackageMain)
const extensionForbidden = isUseOfExtensionForbidden(extension)
if (extensionRequired && !extensionForbidden) {
Expand Down
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions tests/files/node_modules/exceljs/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions tests/src/rules/extensions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RuleTester } from 'eslint'
import rule from 'rules/extensions'
import { test } from '../utils'
import { test, testFilePath } from '../utils'

const ruleTester = new RuleTester()

Expand Down Expand Up @@ -59,7 +59,6 @@ ruleTester.run('extensions', rule, {
test({ code: 'import thing from "./fake-file.js"', options: [ 'always' ] }),
test({ code: 'import thing from "non-package"', options: [ 'never' ] }),


test({
code: `
import foo from './foo.js'
Expand Down Expand Up @@ -90,6 +89,17 @@ ruleTester.run('extensions', rule, {
options: [ 'never', {ignorePackages: true} ],
}),

test({
code: 'import exceljs from "exceljs"',
options: [ 'always', { js: 'never', jsx: 'never' } ],
filename: testFilePath('./internal-modules/plugins/plugin.js'),
settings: {
'import/resolver': {
'node': { 'extensions': [ '.js', '.jsx', '.json' ] },
'webpack': { 'config': 'webpack.empty.config.js' },
},
},
}),
],

invalid: [
Expand Down

0 comments on commit 3a03aca

Please sign in to comment.