eslint-plugin-file-extension-in-import-ts
Advanced tools
Comparing version 1.0.1 to 1.0.2
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
const forceIndexFileImport = require('../util/force-index-file-import'); | ||
const getTryExtensions = require('../util/get-try-extensions'); | ||
@@ -17,5 +18,13 @@ const mappingExtensions = require('../util/mapping-extensions'); | ||
*/ | ||
function getExistingExtensions(filePath) { | ||
function getExistingExtensions(filePath, extSearchOptions) { | ||
const basename = path.basename(filePath, path.extname(filePath)); | ||
try { | ||
const isDirectory = fs.existsSync(filePath) && fs.statSync(filePath).isDirectory(); | ||
if (isDirectory && extSearchOptions.forceIndexFileImport) { | ||
// We are forcing index.js file import when importing from a directory | ||
return ['/index.js']; | ||
} | ||
return fs | ||
@@ -38,2 +47,5 @@ .readdirSync(path.dirname(filePath)) | ||
const extMapping = overrideStyle.extMapping || mappingExtensions.mappingDefault; | ||
const extSearchOptions = { | ||
forceIndexFileImport: overrideStyle.forceIndexFileImport || false, | ||
}; | ||
@@ -49,3 +61,3 @@ function verify({ filePath, name, node }) { | ||
const resolvedExt = path.extname(filePath); | ||
const existingExts = getExistingExtensions(filePath); | ||
const existingExts = getExistingExtensions(filePath, extSearchOptions); | ||
if (!resolvedExt && existingExts.length !== 1) { | ||
@@ -117,2 +129,3 @@ // Ignore if the file extension could not be determined one. | ||
extMapping: mappingExtensions.schema, | ||
forceIndexFileImport: forceIndexFileImport.schema, | ||
tryExtensions: getTryExtensions.schema, | ||
@@ -119,0 +132,0 @@ }, |
{ | ||
"name": "eslint-plugin-file-extension-in-import-ts", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "The plugin check and fix file extensions in Node.js application type module in Typescript", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -46,3 +46,7 @@ # eslint-plugin-file-extension-in-import-ts | ||
```js | ||
'file-extension-in-import-ts/file-extension-in-import-ts': [ 'error', 'always', { extensionsMapping: {'.ts': '.js'}}] | ||
'file-extension-in-import-ts/file-extension-in-import-ts': [ | ||
'error', | ||
'always', | ||
{ extensionsMapping: {'.ts': '.js', forceIndexFileImport: true }} | ||
] | ||
``` | ||
@@ -52,2 +56,14 @@ | ||
The property "forceIndexFileImport" will add "/index.js" if you import directory, for example: | ||
```js | ||
import module from './my-module'; | ||
``` | ||
will be changed to: | ||
```js | ||
import module from './my-module/index.js'; | ||
``` | ||
## Installation: | ||
@@ -54,0 +70,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19392
16
436
116