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

Add no-default-export + docs/tests #936

Merged
merged 1 commit into from
Feb 19, 2018

Conversation

dead-claudia
Copy link
Contributor

@dead-claudia dead-claudia commented Oct 1, 2017

Fixes #889

@dead-claudia
Copy link
Contributor Author

The failing tests appear to be irrelevant (and the same error that appears in master).

Copy link
Contributor

@j-f1 j-f1 left a comment

Choose a reason for hiding this comment

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

Looks awesome! I can’t wait to put this to use! Just a few suggestions and questions.

parser: 'babel-eslint',
}),

// ...SYNTAX_CASES,
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was more or less adapted from prefer-default-export's tests.

README.md Outdated
@@ -91,6 +91,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
[`no-unassigned-import`]: ./docs/rules/no-unassigned-import.md
[`no-named-default`]: ./docs/rules/no-named-default.md
[`no-anonymous-default-export`]: ./docs/rules/no-anonymous-default-export.md
[`no-default-export`]: ./docs/rules/no-default-export.md
Copy link
Contributor

Choose a reason for hiding this comment

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

You should mention this under one of the headers so it is visible in the README.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I completely missed that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

node.exported.name === 'default') {
context.report({
node: ast,
message: 'Prefer named exports.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you extract this message to an external variable? Naming it message would it be destructured in.

}

return {
ExportDefaultDeclaration: function (ast) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you call this node to match the other rules?

@@ -0,0 +1,40 @@
module.exports = {
meta: {
docs: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put a description and category in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't include it because it seemed that none of the other rules appeared to use it (example).

}),

// ...SYNTAX_CASES,
],
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test for something like import defaultImport from 'module-from-npm'? This should be legal, since we can’t control how other libraries are structured.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add a test for it, since it only checks export and export ... from. I can add a test to clarify this, though.

@coveralls
Copy link

coveralls commented Oct 17, 2017

Coverage Status

Coverage decreased (-0.02%) to 96.012% when pulling 5f9e0ce on isiahmeadows:no-default-import into cef88f2 on benmosher:master.

@dead-claudia
Copy link
Contributor Author

Ping, eslint-plugin-import people? (I feel this might have gotten lost in the weeds a little bit...)

@ljharb
Copy link
Member

ljharb commented Nov 26, 2017

@isiahmeadows if you rebase this (rather than using the "update branch" button), it should rerun the travis tests.

I'll give it a review, but I'm not a fan of even the existence of this rule, so I'm going to leave it to the other collaborators to review/merge.

@@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## [2.8.0] - 2017-10-18
### Added
- [`no-default-export`] rule ([#889], thanks [@isiahmeadows])
Copy link
Contributor

Choose a reason for hiding this comment

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

Don’t forget to add [@isiahmeadows]: https://github.com/isiahmeadows to the bottom of this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah...oops

@@ -0,0 +1,63 @@
# no-default-export
Copy link
Member

Choose a reason for hiding this comment

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

i think maybe forbid-default-export would be a more typical name for a rule like this, and for the opposite of "prefer"

Copy link
Member

Choose a reason for hiding this comment

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

ping

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was following the naming convention the other rules have - there's also no-dynamic-require, no-named-as-default, and no-anonymous-default-export. So IMHO it wouldn't make sense to use forbid-${name} when all the others use no-. Also, ESLint recommends this convention, so I'm kind of hesitant to deviate from it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, I kind of missed these comments somehow; sorry about that. 😦

Copy link
Member

Choose a reason for hiding this comment

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

fair enough; this one isn't a blocker or anything.

test({
code: 'export { a, b } from "foo.js"',
parser: 'babel-eslint',
}),
Copy link
Member

Choose a reason for hiding this comment

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

all these }), need to be de-indented a level (it seems like this is already the way it is in the prefer-default-export tests, but let's fix it here anyways)

Copy link
Member

Choose a reason for hiding this comment

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

the indentation here is still off; the } should match the indentation level of the line that ends with }

return {}
}

var message = 'Prefer named exports.'
Copy link
Member

Choose a reason for hiding this comment

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

this should be a const.

also, i wonder if this is an opportunity here to make the message a bit more explanatory?

Copy link
Member

Choose a reason for hiding this comment

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

ping

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. I'll just note that the code base is a haphazard mix of var, let, and const, and ES6 features are used very inconsistently.

also, i wonder if this is an opportunity here to make the message a bit more explanatory?

For the case of export {foo as default}, sure. For the rest, I'm not sure there is more that needs to be done IMHO. There's not really any extra context needed.

@dead-claudia
Copy link
Contributor Author

@ljharb I rebased locally and resolved the issue.

FWIW, this article just ran through JavaScript Weekly, and I feel it's highly relevant. I agree with most of what that article states, but it's purely an opinion, and although I happen to agree with most of it, I'm very against making it the default.

Also, not all languages have default imports/exports (in my experience, most with module systems built-in don't).

@coveralls
Copy link

coveralls commented Nov 27, 2017

Coverage Status

Coverage decreased (-0.02%) to 96.068% when pulling 862cdcf on isiahmeadows:no-default-import into 9db95b3 on benmosher:master.

@ljharb
Copy link
Member

ljharb commented Nov 27, 2017

I've seen it - that article is full of "arguments" supporting named exports that apply identically to default exports; it doesn't make a convincing case at all.

Most languages also don't have a package manager that allows conflicting nested dependencies, but luckily JS isn't constrained by that :-)

README.md Outdated
* Prefer named exports to be grouped together in a single export declaration ([`group-exports`])
* Forbid default exports ([`no-default-export`])
Copy link
Member

Choose a reason for hiding this comment

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

this rebase seems to have left this item here twice


ExportNamedDeclaration: function (node) {
for (var i = 0; i < node.specifiers.length; i++) {
var specifier = node.specifiers[i]
Copy link
Member

Choose a reason for hiding this comment

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

this should use node.specifiers.forEach instead of a loop (which will allow both var instances to be removed)

test({
code: 'export { a, b } from "foo.js"',
parser: 'babel-eslint',
}),
Copy link
Member

Choose a reason for hiding this comment

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

the indentation here is still off; the } should match the indentation level of the line that ends with }

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

whoops, clicked "approve" by accident; there's still some issues left to resolve

@dead-claudia
Copy link
Contributor Author

@ljharb All fixed (plus some other indentation oddities).

@coveralls
Copy link

coveralls commented Nov 27, 2017

Coverage Status

Coverage decreased (-0.02%) to 96.066% when pulling 212555f on isiahmeadows:no-default-import into 9db95b3 on benmosher:master.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

LGTM, pending the last comments

return {}
}

var message = 'Prefer named exports.'
Copy link
Member

Choose a reason for hiding this comment

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

ping

@@ -0,0 +1,63 @@
# no-default-export
Copy link
Member

Choose a reason for hiding this comment

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

ping

@dead-claudia
Copy link
Contributor Author

@ljharb I added a new commit to address your other feedback (that I somehow missed), and I also fixed a bug in the process (with the proposed export foo from "bar.js", which exports a named binding, not a default one).

@coveralls
Copy link

coveralls commented Nov 29, 2017

Coverage Status

Coverage decreased (-0.02%) to 96.07% when pulling 9a1450e on isiahmeadows:no-default-import into 9f42bed on benmosher:master.

@coveralls
Copy link

coveralls commented Jan 4, 2018

Coverage Status

Coverage decreased (-0.02%) to 96.185% when pulling acf9633 on isiahmeadows:no-default-import into 2aef76e on benmosher:master.

@dead-claudia
Copy link
Contributor Author

dead-claudia commented Jan 5, 2018

Ping, @ljharb / @benmosher?

@ljharb
Copy link
Member

ljharb commented Jan 5, 2018

@isiahmeadows I rebased this branch for you. It's still waiting on reviews from other collabs though.

@j-f1 j-f1 mentioned this pull request Jan 9, 2018
@dead-claudia
Copy link
Contributor Author

Ping @benmosher / @jfmengels?

@dead-claudia
Copy link
Contributor Author

Ping? @benmosher / @jfmengels

@sergeysova
Copy link

Any progress here?

Copy link
Member

@benmosher benmosher left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@benmosher benmosher merged commit 5b0777d into import-js:master Feb 19, 2018
@dead-claudia dead-claudia deleted the no-default-import branch February 19, 2018 15:48
@dead-claudia dead-claudia mentioned this pull request Feb 19, 2018
@sergeysova
Copy link

Add to readme?

@dead-claudia dead-claudia mentioned this pull request Feb 19, 2018
@dead-claudia
Copy link
Contributor Author

@sergeysova #1026

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

Successfully merging this pull request may close these issues.

None yet

6 participants