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

Import order #45

Closed
wants to merge 3 commits into from
Closed

Import order #45

wants to merge 3 commits into from

Conversation

benjervis
Copy link
Contributor

To keep things nice and readable, it's a bit nicer if the imports are split into packages, siblings, and other local, and alphabetised within their groups. This rule enforces that (which tbh we were doing most of the time anyway)

@mattcompiles
Copy link
Contributor

Is this fixable? If it's not it's a no from me lol

@benjervis
Copy link
Contributor Author

Yes, can be --fixed

@michaeltaranto
Copy link
Contributor

Can we ensure that we test this out with a web app. I have concerns around the ordering around things like importing the css reset, and other css related files that may have a side effect from their ordering.

It might be ok, but i'd want to be certain before making it a standard.

@72636c
Copy link
Member

72636c commented Jan 14, 2020

Yeah we've tested that. Should've linked this: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md

Unassigned imports are ignored, as the order they are imported in may be important.

We should also bump eslint-plugin-import to ^2.20.0 as there was surprising formatting behaviour in previous versions: import-js/eslint-plugin-import#1562 (comment)

@@ -142,6 +142,7 @@ const baseConfig = {
// prefer TypeScript exhaustiveness checking
// https://www.typescriptlang.org/docs/handbook/advanced-types.html#exhaustiveness-checking
'default-case': OFF,
'import/order': [ERROR, { 'newlines-between': 'always' }],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit more testing on the frontend led me to:

Suggested change
'import/order': [ERROR, { 'newlines-between': 'always' }],
'import/order': [
ERROR,
{
alphabetize: {
order: 'asc',
},
'newlines-between': 'always',
pathGroups: [
{
pattern: 'src/**',
group: 'external',
position: 'after',
},
],
pathGroupsExcludedImportTypes: [
{
pattern: 'src/**',
group: 'external',
position: 'after',
},
],
},
],

Which is scary (the pathGroups don't seem to work very intuitively) but nets

// doesn't touch this
import 'braid-design-system/reset';

import { BraidLoadableProvider } from 'braid-design-system';

import { Header } from 'src/components/Header';

import * as styleRefs from './App.treat.ts';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was looking at this as well. Not sure pattern: 'src/**' makes sense though as not all projects use src and some have other top-level folders.

@benjervis
Copy link
Contributor Author

Closing this out, as it will need to be implemented directly in sku/smt

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

Successfully merging this pull request may close these issues.

None yet

5 participants