-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
The failing tests appear to be irrelevant (and the same error that appears in |
There was a problem hiding this 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.
tests/src/rules/no-default-export.js
Outdated
parser: 'babel-eslint', | ||
}), | ||
|
||
// ...SYNTAX_CASES, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
src/rules/no-default-export.js
Outdated
node.exported.name === 'default') { | ||
context.report({ | ||
node: ast, | ||
message: 'Prefer named exports.', |
There was a problem hiding this comment.
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.
src/rules/no-default-export.js
Outdated
} | ||
|
||
return { | ||
ExportDefaultDeclaration: function (ast) { |
There was a problem hiding this comment.
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: {}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
tests/src/rules/no-default-export.js
Outdated
}), | ||
|
||
// ...SYNTAX_CASES, | ||
], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
79b270b
to
5f9e0ce
Compare
Ping, |
@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]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. 😦
There was a problem hiding this comment.
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.
tests/src/rules/no-default-export.js
Outdated
test({ | ||
code: 'export { a, b } from "foo.js"', | ||
parser: 'babel-eslint', | ||
}), |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 }
src/rules/no-default-export.js
Outdated
return {} | ||
} | ||
|
||
var message = 'Prefer named exports.' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping
There was a problem hiding this comment.
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.
@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). |
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`]) |
There was a problem hiding this comment.
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
src/rules/no-default-export.js
Outdated
|
||
ExportNamedDeclaration: function (node) { | ||
for (var i = 0; i < node.specifiers.length; i++) { | ||
var specifier = node.specifiers[i] |
There was a problem hiding this comment.
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)
tests/src/rules/no-default-export.js
Outdated
test({ | ||
code: 'export { a, b } from "foo.js"', | ||
parser: 'babel-eslint', | ||
}), |
There was a problem hiding this comment.
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 }
There was a problem hiding this 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
@ljharb All fixed (plus some other indentation oddities). |
There was a problem hiding this 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
src/rules/no-default-export.js
Outdated
return {} | ||
} | ||
|
||
var message = 'Prefer named exports.' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping
@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 |
9a1450e
to
acf9633
Compare
Ping, @ljharb / @benmosher? |
@isiahmeadows I rebased this branch for you. It's still waiting on reviews from other collabs though. |
Ping @benmosher / @jfmengels? |
Ping? @benmosher / @jfmengels |
Any progress here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Add to readme? |
Fixes #889