diff --git a/src/rules/extensions.js b/src/rules/extensions.js index fef898b5a..4c45ada57 100644 --- a/src/rules/extensions.js +++ b/src/rules/extensions.js @@ -96,7 +96,7 @@ module.exports = { create: function (context) { const props = buildProperties(context) - + function getModifier(extension) { return props.pattern[extension] || props.defaultConfig } @@ -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) { diff --git a/tests/files/internal-modules/package.json b/tests/files/internal-modules/package.json new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/node_modules/exceljs/excel.js b/tests/files/node_modules/exceljs/excel.js new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/node_modules/exceljs/package.json b/tests/files/node_modules/exceljs/package.json new file mode 100644 index 000000000..70d59eaaa --- /dev/null +++ b/tests/files/node_modules/exceljs/package.json @@ -0,0 +1,3 @@ +{ + "main": "./excel.js" +} diff --git a/tests/src/rules/extensions.js b/tests/src/rules/extensions.js index 1b47066f7..d34f7e1b5 100644 --- a/tests/src/rules/extensions.js +++ b/tests/src/rules/extensions.js @@ -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() @@ -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' @@ -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: [