Skip to content

Require extension rule #252

@calebmer

Description

@calebmer

Could a rule be created to require the addition of an extension when importing?

So for example this would be an error:

import './hello/world' // Where we are actually importing `./hello/world.js`
import './hello/star' // Where we are actually importing `./hello/star.json`
import './hello/moon' // Where we are actually importing `./hello/moon/index.js`

But the following would not be an error:

import './hello/world.js'
import './hello/star.json'
import './hello/moon/index.js'

Why? Well the import search algorithm is faster for one, not just in Node.JS, but also for Browserify, Webpack, and Haste (React Native module system). You are also guaranteed in every module system there is you will be importing the same file.

Also, if you are watching some of the conversations at nodejs/ng and nodejs/node-eps there has recently been a swell of discussion of module loading with the EPS proposing implementing ES modules in node. One point of the conversation is removing the ability for index.js to automatically be loaded, and changing other assumed aspects of loading entirely. To be completely future proof and to avoid the footguns mentioned above this rule would be very nice to have.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions