-
-
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 count
option to newline-after-import
#742
Conversation
That history is super messy, apparently I should have reset my fork before making these changes. Hopefully I can open a new PR without the mess shortly. |
@ntdb please don't open a new PR; if you rebase this branch on top of the latest master and force push, it should be cleaned up. |
@ntdb if After that (or amidst that if you get merge conflicts), you may want to edit the changelog so that you're not removing existing entries. |
c3ed126
to
8fe720e
Compare
CHANGELOG.md
Outdated
@@ -4,40 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). | |||
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com). | |||
|
|||
## [Unreleased] | |||
### Added | |||
- [`no-anonymous-default-export`] rule: report anonymous default exports ([#712], thanks [@duncanbeevers]). |
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.
Please revert all the changes to this file, except for your addition of course
README.md
Outdated
@@ -76,7 +76,6 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a | |||
* Limit the maximum number of dependencies a module can have ([`max-dependencies`]) | |||
* Forbid unassigned imports ([`no-unassigned-import`]) | |||
* Forbid named default exports ([`no-named-default`]) |
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.
please also revert this file.
8fe720e
to
ba3a5c0
Compare
I learned some very useful things about git tonight, thanks @ljharb. |
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.
Let's add some test cases for 0
newlines, and an arbitrary number like, say, 4
src/rules/newline-after-import.js
Outdated
@@ -55,7 +55,8 @@ module.exports = { | |||
nextNode = nextNode.decorators[0] | |||
} | |||
|
|||
if (getLineDifference(node, nextNode) < 2) { | |||
const options = context.options[0] || { newlines: 1 } |
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.
let's add a rule schema that enforces that newlines
is an integer? (ideally a positive one)
2 similar comments
@ljharb Thanks, I've added a schema/tests. 👍 |
@ntdb Nice job on the clean-up. What do you think changing the option name to |
@duncanbeevers I like it. Less repetitive, more explicit, and it sets a usable precedent for other rules with similar options. |
docs/rules/newline-after-import.md
Outdated
@@ -1,9 +1,11 @@ | |||
# newline-after-import | |||
|
|||
Enforces having an empty line after the last top-level import statement or require call. | |||
Enforces having one or more empty line after the last top-level import statement or require call. |
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.
"one or more empty lines" (ie, plural)
newlines
option to newline-after-import
count
option to newline-after-import
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. Thanks a lot for your work @ntdb :D
If you feel contributing again, you could maybe tackle adding an autofix for this rule (that could make your coworkers pretty happy 😄)
"var path = require('path');\nvar foo = require('foo');\n", | ||
"require('foo');", | ||
"switch ('foo') { case 'bar': require('baz'); }", | ||
`var path = require('path');\nvar foo = require('foo');\n`, |
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 don't mind changing this to backticks, but then we might as well replace the \n
by in-code line breaks.
(Not necessary for this PR, but if you feel like changing that at some point later, that's would be nice :D).
@jfmengels I'll open a new PR this weekend to update the auto-fixer. 👍 EDIT: Ah I see it's still in an open PR. I'm still happy to do it but I'll defer to @eelyafi for now. |
My team likes to maintain two newlines after import statements instead of just one. In the interest of making that convention enforceable, these changes add a
newlines
option to thenewline-after-import
rule. This option defaults to1
to maintain full backwards compatibility.