question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best Practices for Multi-Line Imports?

See original GitHub issue

It would be great if the style guide could weigh in on import lines that exceed the character limit (and thus need to be broken up on to multiple lines) …

 import {longNameA, longNameB, longNameC, longNameD, longNameE} from '/some/pretty/long/path/

vs.

 import {longNameA, longNameB, longNameC, longNameD, longNameE}
 from '/some/pretty/long/path/

vs.

 import {longNameA, longNameB, longNameC, longNameD, 
         longNameE} from '/some/pretty/long/path/

vs.

 import {longNameA, longNameB, longNameC, longNameD, 
         longNameE
} from '/some/pretty/long/path/

vs.

 import {
      longNameA,
      longNameB, 
      longNameC,
      longNameD,
      longNameE
  } from '/some/pretty/long/path/

vs.

 import {
      longNameA,
      longNameB, 
      longNameC,
      longNameD,
      longNameE
  } 
  from '/some/pretty/long/path/

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
ljharbcommented, Sep 3, 2016

The only example that would be acceptable is:

import {
  a,
  b,
  c,
} from 'path';

The curly braces thus follow the same indentation rules as every other curly brace block in the style guide, as do the trailing commas.

Adding a section on that to https://github.com/airbnb/javascript#modules would be great.

2reactions
machineghostcommented, Sep 3, 2016

Great, thanks for the response.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Is there a recommended format for multi-line imports?
As all those names are made available in your scope, I personally think that options 2 is the most clearest as you can...
Read more >
PEP 328 – Imports: Multi-Line and Absolute/Relative
The import statement has two problems: Long import statements can be difficult to write, requiring various contortions to fit Pythonic style ...
Read more >
JavaScript Best Practices — Comments, Imports, and ...
JavaScript Best Practices — Comments, Imports, and Indentation · No Cyclic Imports · No Default Export · No Duplicate Import · No Dynamic...
Read more >
One Import Per Line Preference - PyCharm Guide - JetBrains
One Import Per Line Preference. Tell PyCharm to put each import on a separate line when it cleans up your imports.
Read more >
AFW File Search - Import AFW Multi-Line Elements
This document introduces you to Importing Multi-Line Elements in AFW File Search. ... It is a best practice open up both the AFW...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found