Skip to content

enforce JS import ordering #84

@kadamwhite

Description

@kadamwhite

In #75 @igmoweb proposed the addition of the sort-imports ESLint rule, to control the ordering of modules we import into our code.

In a Slack thread @rmccue further proposed that we conform to a general ordering of absolute, then relative, then side effects (e.g. importing a CSS file to ensure it gets included in the build, but not using the return of that import), with a blank line between each, and each section alphabetized.

As an example:

import React from 'react';
import { connect } from 'react-redux';

import Foo from './Foo';

import './Bar.css';

This made sense to me, and would help a lot on several projects we've had lately.

The sort-imports rule looks like it can handle putting the import-for-side-effects after other imports, but doesn't at first glance support including the relative imports after absolute. We should investigate further.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions