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
|
|
||
| ## [Unreleased] | ||
| ### Added | ||
| - [`no-anonymous-default-export`] rule: report anonymous default exports ([#712], thanks [@duncanbeevers]). |
There was a problem hiding this comment.
Please revert all the changes to this file, except for your addition of course
| @@ -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`]) | |||
8fe720e to
ba3a5c0
Compare
|
I learned some very useful things about git tonight, thanks @ljharb. |
ljharb
left a comment
There was a problem hiding this comment.
Let's add some test cases for 0 newlines, and an arbitrary number like, say, 4
src/rules/newline-after-import.js
Outdated
| } | ||
|
|
||
| if (getLineDifference(node, nextNode) < 2) { | ||
| const options = context.options[0] || { newlines: 1 } |
There was a problem hiding this comment.
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
| # 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.
"one or more empty lines" (ie, plural)
newlines option to newline-after-importcount option to newline-after-import
| "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.
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
newlinesoption to thenewline-after-importrule. This option defaults to1to maintain full backwards compatibility.