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.

Proposal: "object-curly-newline" add configuration for named imports and exports (or create new rule for import/export specifiers)

See original GitHub issue

I’m creating a new issue for this because I’d like to see it considered for inclusion.

From the original post (see #7319):

ESLint version v3.5.0

Rule object-curly-newline currently supports:

  • "ObjectExpression" configuration for object literals;
  • "ObjectPattern" configuration for object patterns of destructuring assignments.

Proposal

I propose to add similar configuration for named imports and exports:

{
    "object-curly-newline": ["error", {
        "ImportDeclaration": { "multiline": true },
        "ExportDeclaration": { "multiline": true }
    }]
}

Possible values:

always

Examples of incorrect code for this rule with the "always" option:

import {foo, bar} from 'foo-bar';
import {foo as f, bar} from 'foo-bar';
import {foo,
    bar} from 'foo-bar';

export {foo, bar};
export {foo as f, bar};
export {foo,
   bar};

Examples of correct code for this rule with the "always" option:

import {
    foo,
    bar
} from 'foo-bar';
import {
    foo as f,
    bar
} from 'foo-bar';

export {
  foo,
  bar
};
export {
  foo as f,
  bar
};

never

Examples of incorrect code for this rule with the "never" option:

import {
    foo,
    bar
} from 'foo-bar';

export {
   foo,
   bar
};

Examples of correct code for this rule with the "never" option:

import {foo, bar} from 'foo-bar';

export {foo, bar};

multiline

Examples of incorrect code for this rule with the default { "multiline": true } option:

import {
    foo, bar} from 'foo-bar';
import {foo, bar
    } from 'foo-bar';
import {
    foo, bar
} from 'foo-bar';

export {
   foo, bar};
export {
   foo, bar
};

Examples of correct code for this rule with the default { "multiline": true } option:

import {foo, bar} from 'foo-bar';
import {foo as f, bar} from 'foo-bar';
import {
    foo,
    bar
} from 'foo-bar';
import {
    foo as f,
    bar
} from 'foo-bar';

export {
   foo,
   bar
};

minProperties

Similar to current minProperties behavior. Maybe this option should be renamed to minImportSpecifiers or similar.

Question

Maybe this should be separate rule instead of configuration of object-curly-newline rule.

Regarding the above question, I like the idea of augmenting object-curly-newline if other object-related rules tend to apply to import/export specifiers, but it’s also true that some elements of objects (e.g., keys/values) simply don’t apply to import specifiers. So I’m okay with a new rule as well. Hopefully that will be a quick bikeshed.

The last issue had been 👍’d by the following people:

But we never had a champion. I’d like to see if we can get one this time. (I’m considering it. Just need to figure out my schedule.)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
alexander-akaitcommented, May 3, 2017

@kaicataldo maybe it be good do in v4? Anyway i do PR, rename is not long procedure 😄

1reaction
jouncealimbcommented, Nov 13, 2017

I’d like to work on this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Save the details of an import or export operation as a ...
When you run an import wizard or export wizard in Access, you can save the settings you used as a specification so that...
Read more >
ESLint plugin with rules that help validate proper imports.
Ensure a default export is present, given a default import. ❗ ☑️. named, Ensure named imports correspond to a named export in the...
Read more >
Eslint rule to put a new line inside import - Stack Overflow
I was looking for such a rule for both import and export declaration. As a result I've made a plugin with autofix.
Read more >
Tips for New Importers and Exporters
To assist you, we offer the following tips for new importers and exporters. What kind of license is required to import merchandise into...
Read more >
import - JavaScript - MDN Web Docs - Mozilla
In HTML, this is done by adding type="module" to the <script> tag. ... Given a value named myExport which has been exported from...
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