npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-enforce-extensions

v0.1.8

Published

A simple eslint plugin that enforces imports and exports for file locations have a file extension.

Downloads

4

Readme

eslint-plugin-enforce-extensions

codecov Build Package status License

A simple eslint plugin that enforces imports and exports for file locations have a '.js' file extension.

TypeScript doesn't transform extensions and doesn't enforce file extensions. This can be a problem when the type specified in the package.json is module, as the compiler will not complain about the lack of an extension, because an error will get thrown during runtime saying that it can't find that module.

This plugin can not only identify those problematic imports, but also automatically fix them if configured to do so.

Other plugins exist for this, but it seemed that they only accounted for relative imports stating with .. This is a problem if you have special import scenarios, for example, importing from a lambda layer in an AWS Lambda function, where the import is an absolute file location starting with /opt/.

This pluginallows you to specify exactly what import prefixes to look out for.

  1. Install
npm install --save-dev eslint-plugin-enforce-extensions
  1. Edit .eslintrc
{
    "plugins": [
        "enforce-extensions"
    ],
    "rules": {
        "enforce-extensions/extensions": ["error", {"prefixes": ["/opt/"]}
    }
}
  1. Code
// source.js

import Target from './target';
import HigherTarget from '../higherTarget';
import OtherTarget from '/opt/other';
  1. Lint
eslint .
source.js
  1:1  error  Location-based imports and exports must end with .js  enforce-extensions/extensions
  1. Fix
eslint --fix .
// source.js

import Target from './target.js';
import HigherTarget from '../higherTarget.js';
import OtherTarget from '/opt/other.js';

If, for whatever reason, you wish to exclude the default . prefix, you can provide the following option:

{
    "plugins": [
        "enforce-extensions"
    ],
    "rules": {
        "enforce-extensions/extensions": ["error", {"includeDefault": false}
    }
}