Skip to content
Advertisement

How to break long import statements into multiple lines in ES6?

I have a pretty long import statement in my JavaScript (ES6) file:

import { A, B, C, D } from '../path/to/my/module/in/very/far/directory/'

Is it OK to add new lines like this?

import { A, B, C, D } from
'../path/to/my/module/in/very/far/directory'

If not, is there any other way to write clean (keeping my code within 80 columns) import statements in ES6 syntax using Babel?

Advertisement

Answer

Here are the results from my test using ESLint.

ESLINT PASSED

import fs
from 'fs';

ESLINT PASSED

import
fs
from 
'fs';

ESLINT PASSED

import {
    moduleName
} from './my/module/file';

And the above code executes fine. I think you are good to go!

NOTE: This .eslintrc was used.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement