Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
eslint-plugin-file-extension-in-import-ts
Advanced tools
The plugin check and fix file extensions in Node.js application type module in Typescript
This is small patch to the great rule:
file-extension-in-import
from eslint-plugin-node module.
Author of code:
I've just added mapping functionality.
When we use type module we must add extension to the file
import foo from "./path/to/a/file"
It's a bad practice
import eslint from "eslint"
import foo from "./path/to/a/file.js"
It's a good practice.
node/file-extension-in-import rule raise error when we forgot to add extension to the import. But it doesn't work with Typescript.
When we use Typescript we can't add .ts extension to the file. It won't be process with Typescript compiler. In this case we need to add .js extension.
In this case we need to replace .ts extension to .js.
In this plugin I will add possibility to make mapping for extensions:
'file-extension-in-import-ts/file-extension-in-import-ts': [
'error',
'always',
{ extMapping: {'.ts': '.js' } }
]
It means, this rule will fix our ts files to .js extension in import statement.
import module from './my-module';
will be changed to:
import module from './my-module/index.js';
npm i -D eslint-plugin-file-extension-in-import-ts
{
"plugins": [
"file-extension-in-import-ts"
],
"rules": {
"file-extension-in-import-ts/file-extension-in-import-ts": "error"
}
}
By default, the plugin will process mapping:
This plugin has conflict with eslint-import-plugin, the rule: import/no-unresolved rule
To quick fix it we can skip '.js' (in the folder with TS sources JS files are not existing).
'import/no-unresolved': ['error', { ignore: [ '\\.js$' ] }],
Copyright (c)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
The plugin check and fix file extensions in Node.js application type module in Typescript
The npm package eslint-plugin-file-extension-in-import-ts receives a total of 1,983 weekly downloads. As such, eslint-plugin-file-extension-in-import-ts popularity was classified as popular.
We found that eslint-plugin-file-extension-in-import-ts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.