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 count option to newline-after-import #742

Merged
merged 9 commits into from
Feb 16, 2017

Conversation

ntdb
Copy link
Contributor

@ntdb ntdb commented Feb 12, 2017

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 the newline-after-import rule. This option defaults to 1 to maintain full backwards compatibility.

@coveralls
Copy link

coveralls commented Feb 12, 2017

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling 2ced295 on ntdb:newline-after-import into 0800951 on benmosher:master.

@ntdb
Copy link
Contributor Author

ntdb commented Feb 12, 2017

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.

@coveralls
Copy link

coveralls commented Feb 12, 2017

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling 2ced295 on ntdb:newline-after-import into 0800951 on benmosher:master.

@ljharb
Copy link
Member

ljharb commented Feb 12, 2017

@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.

@coveralls
Copy link

coveralls commented Feb 12, 2017

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling c3ed126 on ntdb:newline-after-import into 0800951 on benmosher:master.

@ljharb
Copy link
Member

ljharb commented Feb 12, 2017

@ntdb if source is the git remote for this repo, and origin is for your fork, run git fetch source && git checkout master && git reset --hard source/master && git push origin source/master:master -f && git checkout newline-after-import && git rebase source/master && git push origin HEAD:newline-after-import -f.

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.

@coveralls
Copy link

coveralls commented Feb 12, 2017

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling 8fe720e on ntdb:newline-after-import into 0800951 on benmosher:master.

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]).
Copy link
Member

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`])
Copy link
Member

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.

@ntdb
Copy link
Contributor Author

ntdb commented Feb 12, 2017

I learned some very useful things about git tonight, thanks @ljharb.

@coveralls
Copy link

coveralls commented Feb 12, 2017

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling 8c7ea26 on ntdb:newline-after-import into 0800951 on benmosher:master.

@coveralls
Copy link

coveralls commented Feb 12, 2017

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling 8c7ea26 on ntdb:newline-after-import into 0800951 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.

Let's add some test cases for 0 newlines, and an arbitrary number like, say, 4

@@ -55,7 +55,8 @@ module.exports = {
nextNode = nextNode.decorators[0]
}

if (getLineDifference(node, nextNode) < 2) {
const options = context.options[0] || { newlines: 1 }
Copy link
Member

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)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling 1d757dc on ntdb:newline-after-import into 0800951 on benmosher:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling 1d757dc on ntdb:newline-after-import into 0800951 on benmosher:master.

@coveralls
Copy link

coveralls commented Feb 14, 2017

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling 1d757dc on ntdb:newline-after-import into 0800951 on benmosher:master.

@ntdb
Copy link
Contributor Author

ntdb commented Feb 15, 2017

@ljharb Thanks, I've added a schema/tests. 👍

@duncanbeevers
Copy link
Contributor

@ntdb Nice job on the clean-up.

What do you think changing the option name to count? To me, this seems less repetitive and more explicitly descriptive.

@ntdb
Copy link
Contributor Author

ntdb commented Feb 16, 2017

@duncanbeevers I like it. Less repetitive, more explicit, and it sets a usable precedent for other rules with similar options.

@coveralls
Copy link

coveralls commented Feb 16, 2017

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling c0f733b on ntdb:newline-after-import into 0800951 on benmosher:master.

@@ -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.
Copy link
Member

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)

@coveralls
Copy link

coveralls commented Feb 16, 2017

Coverage Status

Coverage increased (+0.003%) to 94.915% when pulling 2323ece on ntdb:newline-after-import into 0800951 on benmosher:master.

@ljharb ljharb changed the title Add newlines option to newline-after-import Add count option to newline-after-import Feb 16, 2017
@ljharb ljharb removed the evaluating label Feb 16, 2017
Copy link
Collaborator

@jfmengels jfmengels left a 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`,
Copy link
Collaborator

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 jfmengels merged commit b5a962f into import-js:master Feb 16, 2017
@jfmengels
Copy link
Collaborator

Ugh, I just noticed there is already an auto-fixer PR for this rule, which now needs to be updated to handle this case #696, sorry @eelyafi...

@coveralls
Copy link

coveralls commented Feb 16, 2017

Coverage Status

Coverage decreased (-1.3%) to 93.616% when pulling 49ea883 on ntdb:newline-after-import into 0800951 on benmosher:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 93.616% when pulling 49ea883 on ntdb:newline-after-import into 0800951 on benmosher:master.

@ntdb
Copy link
Contributor Author

ntdb commented Feb 17, 2017

@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.

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

Successfully merging this pull request may close these issues.

None yet

5 participants