import/order doesn't sort assets that aren't assigned to a variable (e.g. `import './file.css'`)
See original GitHub issueWhen sorting imports, any assets that aren’t assigned to a variable are ignored, and break/mess with sorting of other imports.
e.g.
import mapboxgl from 'mapbox-gl';
import './file.json';
import './file.css';
import './file.png';
import React from 'react';
import { ToastContainer } from 'react-toastify';
import { ErrorBoundary } from '@app/components';
import { useAccount, useUser } from 'src/state';
import mygif from './file.gif';
import Routes from './Routes';
If I change the above and assign assets to a variable, sorting is applied as expected.
import mapboxgl from 'mapbox-gl';
import React from 'react';
import { ToastContainer } from 'react-toastify';
import { ErrorBoundary } from '@app/components';
import { useAccount, useUser } from 'src/state';
import b from './file.css';
import mygif from './file.gif';
import a from './file.json';
import c from './file.png';
import Routes from './Routes';
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Issues - GitHub
import /order doesn't sort assets that aren't assigned to a variable (e.g. import './file.css' ) #1639.
Read more >Next.js Global CSS cannot be imported from files other than ...
js, and it was previously working? I've moved my main.scss import to the pages/_app.js page, but the styles still aren't coming through. This ......
Read more >import - CSS: Cascading Style Sheets - MDN Web Docs
The @import CSS at-rule is used to import style rules from other valid stylesheets. An @import rule must be defined at the top...
Read more >The Django admin site
from django.contrib import admin from myapp.models import Author class ... In the preceding example, the ModelAdmin class doesn't define any custom values ...
Read more >Example Code To Simplify Your Imports and Exports
It can also be due to odd import file formats that aren't fully compatible ... WP All Import doesn't touch product stock when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I totally agree that it’s a smell - but a rule that risks making people do the wrong thing, without knowing why, isn’t a good rule.
It might be possible to make this warnable, but never to make it autofixable.
Your arguments are correct for complicated cases, but it would be nice if you could optionally configure to do something with the side-effect-only imports. I’m currently using a vscode plugin (TypeScript Import Sorter) that puts them on the top, in a separate group, plus a tslint rule that checks that.
IMHO side-effect imports should be used cautiously and only if absolutely necessary, so
I’m using side-effect imports only for “global” stuff like
reflect-metadata
&tsconfig-paths/register
on the backend, some jest plugins in tests, or storybook plugins on the frontend. I’ve just moved from tslint to eslint, and I’d like to keep enforcing grouping side-effect imports together 😃