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.

Please describe what the rule should do: When there is more than [x] (default: 1) exported objects in a file, rule makes sure all exported objects are combined at the bottom of the file in a single place.

What category of rule is this? (place an “X” next to just one item)

[ ] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [x] Enforces code style (layout) [ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

Bad: ES6 Export

export const MYCONST = 5;
// ...
export const myFunc = () => {};
// ...
export const myObject = {};
// ...

Good: ES6 Export

const MYCONST = 5;
// ...
const myFunc = () => {};
// ...
const myObject = {};
// ...

export {
  MYCONST,
  myFunc,
  myObject,
}

Bad: Commonjs Export

module.exports.MYCONST = 5;
// ...
module.exports.myFunc = () => {};
// ...
module.exports.myObject = {};
// ...

Good: Commonjs Export

const MYCONST = 5;
// ...
const myFunc = () => {};
// ...
const myObject = {};
// ...

module.exports = {
  MYCONST,
  myFunc,
  myObject,
}

Why should this rule be included in ESLint (instead of a plugin)? I think this rule will have a very positive impact on code readability. Because developers tend to export functions, objects, classes inline and most often, in the same file, also define unexported functions. This causes a chaotic view of the file.

As developers, like we check top of the file to see what is being imported, we should check bottom of the file to see what is being exported. This will intuitively help developers to understand what that module (file) is doing.

Are you willing to submit a pull request to implement this rule? I’d love to.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
aladdin-addcommented, May 22, 2019

Thanks for your interest in improving ESLint. Unfortunately, it looks like this issue didn’t get consensus from the team, so I’m closing it. We define consensus as having three 👍s from team members, as well as a team member willing to champion the proposal. This is a high bar by design – we can’t realistically accept and maintain every feature request in the long term, so we only accept feature requests which are useful enough that there is consensus among the team that they’re worth adding.

Since ESLint is pluggable and can load custom rules at runtime, the lack of consensus among the ESLint team doesn’t need to be a blocker for you using this in your project, if you’d find it useful. It just means that you would need to implement the rule yourself, rather than using a bundled rule that is packaged with ESLint.

1reaction
golopotcommented, Apr 20, 2019

This is what your are looking for: import/group-exports .

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-sort-exports - npm
Start using eslint-plugin-sort-exports in your project by running `npm i eslint-plugin-sort-exports`. There are 5 other projects in the npm ...
Read more >
ESLint plugin to sort exports in modules - GitHub
eslint-plugin-sort-exports. Sort export declarations in modules, similarly to sort-imports. Installation. First install ESLint. yarn add - ...
Read more >
eslint-plugin-sort-export-all | Yarn - Package Manager
ESLint rule that helps sort export *. eslint, eslintplugin, eslint- ... eslint-plugin-sort-export-all. ESLint rule that sorts exports * with autofix enabled.
Read more >
JS/TS Import/Export Sorter - Visual Studio Marketplace
Use Sort Imports/Exports command in the Command Palette ( Ctrl+Shift+P ). 1. Right click on editor content and select Sort Imports/Exports .
Read more >
Eslint enforce alphabetical export order for module
Yes, you can use the sort exports eslint plugin: https://www.npmjs.com/package/eslint-plugin-sort-exports.
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