Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "unassigned" to importType for order rule #970

Open
hotforfeature opened this issue Nov 17, 2017 · 6 comments
Open

Add "unassigned" to importType for order rule #970

hotforfeature opened this issue Nov 17, 2017 · 6 comments

Comments

@hotforfeature
Copy link

I would like to group and order unassigned imports. This specific use case is for importing Polymer 2 html elements with polymer-webpack-loader.

import { Component } from '@angular/core';

import 'bower_components/paper-button/paper-button.html';

import { value } from '../parent'; 
import { other } from './sibling';

The proposed .eslintrc to achieve the above style would be

"import/order": [
  "error", 
  {
    "groups": ["builtin", "external", "unassigned", ["parent", "sibling", "index"]],
    "newlines-between": "always"
  }
]

At the moment unassigned imports are completely ignored.

@ljharb
Copy link
Member

ljharb commented Nov 17, 2017

This seems reasonable; altho I’d call them “side-effecting” or something instead of just “unassigned”.

A use case that isn’t deprecated (ie, that doesn’t involve bower) would be shimming/polyfilling.

@lext-7
Copy link

lext-7 commented Aug 21, 2019

Unassigned imports are ignored now. In our project, there are some unassigned style imports. We think there should rank last to keep code clean. We need to config it.

@ljharb
Copy link
Member

ljharb commented Aug 21, 2019

@lext-7 they, in fact, should always be first since they typically have side effects.

@constgen
Copy link

constgen commented Jul 22, 2020

In React apps it is better to import CSS last as it is more efficient way to override public styles of imported child components. The selectors may have the same priority. So to avoid the situation when the parent can't override appearance of child components the styles should always be imported at the very end of import list in every component

@constgen
Copy link

@ljharb As I described above sometimes it may be important. Preserving the necessary order for the particular project may be highly necessary.
To not make breaking changes I propose to add an option to pathGroups so consumers may enable processing of side affect imports for certain groups. E.g.:

"pathGroups": [
  {
    "pattern": "{.,..}/**/*.+(css|sass|less|scss|pcss|styl)",
    "unnamed": true, // this is a new option
    "group": "unknown",
    "position": "after"
  }
]

@ljharb
Copy link
Member

ljharb commented Jul 26, 2020

@constgen that seems reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants