GithubHelp home page GithubHelp logo

nuclide-format-js's People

Contributors

aaronabramov avatar hansonw avatar kyldvs avatar qfox avatar xixixao avatar zertosh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nuclide-format-js's Issues

Formatter adds requires when I'm using ES6 and import syntax

Issue and Steps to Reproduce

I'm writing a react native app with ES6 using import ... syntax. When I run the formatter lots of require(...) statements are added as imports.

image

Expected Behavior

the formatter should recognize that I'm not using require syntax and not add them

Actual Behavior

lots of requires are added as imports

Don't flush the whole file

I wanted to do this for optimization, but it's actually more important for inline lint/flow checking. If we replace the whole file contents, all those inline warnings get messed up in Nuclide. I believe that if we only replace the imports the rest of the file should be unaffected (the warnings will just shift by lines added).

Changes required due to TextBuffer.save becoming async in Atom 1.19

Hi! Thanks for maintaining the nuclide-format-js package!

In Atom v1.19, we will release a major change to Atom's core text buffer data structure. As part of this change, we have made TextBuffer.save asynchronous; rather than blocking until the save is complete, it now immediately returns a Promise that resolves when the save is complete. Because of this, a few other Atom APIs that use save have similarly become async:

  • Pane.close
  • TextBuffer.save
  • TextEditor.save
  • Pane.saveItem
  • Pane.saveItemAs
  • Pane.saveActiveItem
  • Pane.saveActiveItemAs
  • Pane.saveItems
  • Workspace.saveActivePaneItem
  • Workspace.saveActivePaneItemAs

Effects on this package

We think this package could be impacted by this upgrade because it calls the changed methods in the following places:

  • TextEditor.save

We found these calls using a regex search, so this list might be incomplete, and it might contain some false positives.

What to do about the change

It should be pretty easy to adjust your package code and/or tests to work with the new async behavior, and to simultaneously keep it working with older versions of Atom. Here are some examples of pull requests we opened on our bundled packages to cope with the change:

Please let me know if you have any questions. I would be happy to help!

Using Image() triggers auto-require of 'Image'

Issue and Steps to Reproduce

Using the Image constructor causes require('Image') to be auto-inserted by the formatter.

let img = new Image(); // no need for require -- provided by the DOM

Expected Behavior

No require should be added, since Image() is a valid global in the browser: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image

Actual Behavior

require('Image') gets inserted, which may erroneously resolve to something like react native's implementation.

Failed to activate the nuclide-format-js package

[Enter steps to reproduce:]

  1. ...
  2. ...

Atom: 1.23.1 x64
Electron: 1.6.15
OS: Mac OS X 10.12.6
Thrown From: nuclide-format-js package 0.0.43

Stack Trace

Failed to activate the nuclide-format-js package

At Cannot add to an already disposed UniversalDisposable!

Error: Cannot add to an already disposed UniversalDisposable!
    at UniversalDisposable.add (/packages/nuclide/modules/nuclide-commons/UniversalDisposable.js:24:13)
    at Activation.consumeOrganizeRequiresService (/packages/nuclide/pkg/nuclide-js-imports-client/lib/main.js:184:31)
    at /packages/nuclide/modules/nuclide-commons-atom/createPackage.js:51:38)
    at Provider.module.exports.Provider.provide (/Applications/Atom.app/Contents/Resources/app/node_modules/service-hub/lib/provider.js:34:58)
    at ServiceHub.module.exports.ServiceHub.provide (/Applications/Atom.app/Contents/Resources/app/node_modules/service-hub/lib/service-hub.js:30:26)
    at Package.module.exports.Package.activateServices (/Applications/Atom.app/Contents/Resources/app/src/package.js:448:77)
    at Package.module.exports.Package.activateNow (/Applications/Atom.app/Contents/Resources/app/src/package.js:258:22)
    at /Applications/Atom.app/Contents/Resources/app/src/package.js:227:38
    at Package.module.exports.Package.measure (/Applications/Atom.app/Contents/Resources/app/src/package.js:99:21)
    at /Applications/Atom.app/Contents/Resources/app/src/package.js:220:32
    at Package.module.exports.Package.activate (/Applications/Atom.app/Contents/Resources/app/src/package.js:217:40)
    at PackageManager.activatePackage (/Applications/Atom.app/Contents/Resources/app/src/package-manager.js:695:42)
    at /Applications/Atom.app/Contents/Resources/app/node_modules/settings-view/lib/package-manager.js:535:35
    at exit (/Applications/Atom.app/Contents/Resources/app/node_modules/settings-view/lib/package-manager.js:128:22)
    at triggerExitCallback (/Applications/Atom.app/Contents/Resources/app/src/buffered-process.js:338:17)
    at /Applications/Atom.app/Contents/Resources/app/src/buffered-process.js:351:17
    at Socket.<anonymous> (/Applications/Atom.app/Contents/Resources/app/src/buffered-process.js:220:15)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:501:12)

Commands

  5x -3:51.3.0 core:confirm (input.hidden-input)
     -3:45 editor:consolidate-selections (input.hidden-input)
     -3:45 core:cancel (input.hidden-input)
  2x -2:58.6.0 core:backspace (input.hidden-input)
     -2:56 core:confirm (input.hidden-input)
     -2:37.3.0 core:save (input.hidden-input)
     -2:36.1.0 core:undo (input.hidden-input)
     -2:23.9.0 core:save (input.hidden-input)
     -2:22.7.0 core:undo (input.hidden-input)
     -1:48.6.0 core:save (input.hidden-input)
     -1:47.1.0 core:undo (input.hidden-input)
     -1:44.2.0 core:save-as (input.hidden-input)
     -1:12.2.0 core:undo (input.hidden-input)
     -0:58.8.0 core:select-all (input.hidden-input)
     -0:56.3.0 code-format:format-code (div.line)
     -0:07.7.0 core:select-all (input.hidden-input)

Non-Core Packages

atom-standard-format 0.2.0 
formatter-json 1.0.1 
formatter-tidy 1.0.1 
highlight-selected 0.13.1 
jsformat 0.9.3 
minimap 4.29.7 
minimap-highlight-selected 4.6.1 
nuclide 0.272.0 
nuclide-format-js 0.0.43 
react 0.17.0 
react-native-snippets 0.3.0 

Unused imported type is not removed

Something like

import type {
  A,
  B,
} from 'X';

const x: A;

Is not being fixed up for me. In fact the import statement is not touched at all.

Failed to format code: No code formatting providers found!

Issue and Steps to Reproduce

  • Installed nuclide server and client version 0.288.0. nuclide-format-js 0.0.45 is installed.
  • On a Mac, in Atom open a remote React.js project on devserver.
  • Open any .js file.
  • Press cmd-shift-i, the auto-acquire function works perfectly.
  • Press cmd-shift-c to reformat the code.

Expected Behavior

The code gets formatted.

Actual Behavior

Message pops out: Failed to format code: No code formatting providers found!

Kill "Format on Save" option

The transformation isn't reliable enough to be run on every save. I don't see a case in which it would be a good idea to have this enabled, especially since we integrated this package with Nuclide.

Fix comments transposition

/**
 * ahoj
 */

'use strict';

/**
 * very fancy comment
 */
// less fancy comment
type BundleConfigRoot = {
};

Should not be modified.

Support jsx

Issue and Steps to Reproduce

Currently this formats JSX weirdly
screen shot 2017-02-07 at 8 16 20 pm

Expected Behavior

It should format JSX like HTML tags, properly indented

Actual Behavior

It removes line breaks and pulls everything together.

Support some inline comments

We should support at least one way of adding inline comments, like

/* @lint-ignore ESLINT */
 const SideNavigation = require('SideNavigation.mamlas');

or

 const SideNavigation = require('SideNavigation.mamlas'); // @nolint

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.