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

Does not understand line breaks #9

Closed
lencioni opened this issue Mar 19, 2015 · 3 comments
Closed

Does not understand line breaks #9

lencioni opened this issue Mar 19, 2015 · 3 comments
Labels

Comments

@lencioni
Copy link
Collaborator

If I have a section of required modules at the top that looks like this:

const MyModule = require('path/to/my_module');
const MyModuleThatHasALongName =
  require('path/to/my_module_that_has_a_long_name');
const SomeModule = require('path/to/some_module');

import-js gets confused when adding a new module to the list:

const AnotherModule = require('path/to/another_module');
const MyModule = require('path/to/my_module');

const MyModuleThatHasALongName =
  require('path/to/my_module_that_has_a_long_name');
const SomeModule = require('path/to/some_module');

where I would expect:

const AnotherModule = require('path/to/another_module');
const MyModule = require('path/to/my_module');
const MyModuleThatHasALongName =
  require('path/to/my_module_that_has_a_long_name');
const SomeModule = require('path/to/some_module');

It would be nice if import-js worked better with this format.

Bonus points would be specifying a character limit (defaulted to 80) that it would try to stay within when importing new dependencies.

trotzig pushed a commit that referenced this issue Mar 21, 2015
As reported by @lencioni in #9:

  If I have a section of required modules at the top that looks like this:

    const MyModule = require('path/to/my_module');
    const MyModuleThatHasALongName =
      require('path/to/my_module_that_has_a_long_name');
    const SomeModule = require('path/to/some_module');

  import-js gets confused when adding a new module to the list:

    const AnotherModule = require('path/to/another_module');
    const MyModule = require('path/to/my_module');

    const MyModuleThatHasALongName =
      require('path/to/my_module_that_has_a_long_name');
    const SomeModule = require('path/to/some_module');

  where I would expect:

    const AnotherModule = require('path/to/another_module');
    const MyModule = require('path/to/my_module');
    const MyModuleThatHasALongName =
      require('path/to/my_module_that_has_a_long_name');
    const SomeModule = require('path/to/some_module');

  It would be nice if import-js worked better with this format.

I've added basic support for line breaks in this commit. I say basic
because I expect there to be edge cases that I haven't thought of.
We use simple regexs to parse the js file content, and like all simple
regex parsers, they are bound to fail. However, I don't want to bring in
a js parsing framework just yet. So in this commit I extend the regex
approach with some logic to deal with possible line-breaks.

One idea also listed in #9 was to add support for import-js to
automatically line-break long lines. I haven't made that change in this
commit (new imports are still one-line), but I might do that later if I
find time.
@trotzig
Copy link
Collaborator

trotzig commented Mar 21, 2015

I made a change to deal with line-breaks better. I didn't add anything for auto-linebreaking yet, but I might do that next. Check it out and let me know what you think @lencioni!

@lencioni
Copy link
Collaborator Author

👍 🐰 🎩

@lencioni
Copy link
Collaborator Author

I think this is closed now. I'll open a new issue for the auto-breaking behavior.

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

No branches or pull requests

2 participants