facebookarchive / nuclide-format-js Goto Github PK
View Code? Open in Web Editor NEWA collection of codemods to help auto format javascript
License: Other
A collection of codemods to help auto format javascript
License: Other
import type {AppID} from 'PubXTypes';
import type {AppID, AppWithPlatform} from 'PubXTypes';
should collapse
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.
the formatter should recognize that I'm not using require syntax and not add them
lots of require
s are added as imports
And find other built-ins like it.
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).
No idea why it doesn't work.
const {MDASH, MDASH} = require('Constants');
duplicate MDASH is not removed
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
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.
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 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
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
require('Image')
gets inserted, which may erroneously resolve to something like react native's implementation.
[Enter steps to reproduce:]
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
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)
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)
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
const SUIRadioListItem = require('SUIRadioList.react').Item;
const x = <SUIRadioListItem />;
should not be transformed
More of an FYI issue, I started cleaning up this repo over here: https://github.com/kyldvs/organize_imports using babel6 rather than babel5 and simplified a lot of code. Once I figure out what my plans are I might move that over here or make this just require and use that package.
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.
The code gets formatted.
Message pops out: Failed to format code: No code formatting providers found!
Add a blacklist of these.
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.
Hopefully from flow-typed.
/**
* ahoj
*/
'use strict';
/**
* very fancy comment
*/
// less fancy comment
type BundleConfigRoot = {
};
Should not be modified.
declare class Imm {}
should not import Imm
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
const y = (x: any);
x doesn't get required
class Bla {
static _bla: ?X = null;
}
should not require _bla
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.