It turns out that leading comment is attached to the CallExpression which is the last one and not the first one if they fit in a single line, so we want to not check that one.
Fixes#1892
* Add shebang comment nodes to Flow/TypeScript ASTs
Now we handle actually printing the shebang in `printComment`, rather
than lopping it off beforehand and reattaching it afterward, as
suggested in https://github.com/prettier/prettier/pull/1718#issuecomment-303876792
* Dedupe AST shebang-insertion code into helper function
This fixes https://github.com/prettier/prettier/issues/1890, albeit in a
quick-and-dirty way. Note also that the cursor offset may be incorrect
when there is a shebang, but that's a separate issue.
* Ignore docs/index.js when searching with ag/ripgrep/sift
This makes it easier to search through the code without getting
irrelevant results.
* Ignore docs/*.js when searching with ag/ripgrep/sift
This makes it easier to search through the code without getting
irrelevant results. I couldn't get a glob (`docs/*.js`) to work with `ag
babylon -l | ag docs`, so I just listed them out instead.
* Add `formatWithCursor` API with `cursorOffset` option
This addresses https://github.com/prettier/prettier/issues/93 by
adding a new option, `cursorOffset`, that tells prettier to determine
the location of the cursor after the code has been formatted. This is
accessible through the API via a new function, `formatWithCursor`, which
returns a `{formatted: string, cursorOffset: ?number}`.
Here's a usage example:
```js
require("prettier").formatWithCursor(" 1", { cursorOffset: 2 });
// -> { formatted: '1;\n', cursorOffset: 1 }
```
* Add `--cursor-offset` CLI option
It will print out the offset instead of the formatted output. This
makes it easier to test. For example:
echo ' 1' | prettier --stdin --cursor-offset 2
# prints 1
* Add basic test of cursor translation
* Document `cursorOffset` option and `formatWithCursor()`
* Print translated cursor offset to stderr when --cursor-offset is given
This lets us continue to print the formatted code, while also
communicating the updated cursor position.
See https://github.com/prettier/prettier/pull/1637#discussion_r119735496
* doc-print cursor placeholder in comments.printComments()
See https://github.com/prettier/prettier/pull/1637#discussion_r119735149
* Compare array index to -1 instead of >= 0 to determine element presence
See https://github.com/prettier/prettier/pull/1637#discussion_r119736623
* Return {formatted, cursor} from printDocToString() instead of mutating options
See https://github.com/prettier/prettier/pull/1637#discussion_r119737354
* Add an option to include "dot" directories.
We have some files in directories that start with a `.` that we want prettified. This PR adds the `include-dot-directories` flag to let the glob match dot directories.
* always include dot directories
* Adding --stdin-filepath option in order to enable filetype inference from
stdin
* Making sure error messages are 1 indexed based instead of zero indexed
The hackiness continues! I'm now bundling an existing bundle again in order for it to get exported as a global variable :p There's likely a better solution, but it kind of works.
Because I have to regenerate the docs, I just tagged it as 1.4.0-beta and added typescript and postcss in there.
* Adding --stdin-filepath option in order to enable filetype inference from stdin to allow chosing css parser
* Adding readme information on the filepath option
* Also including support for typescript parser inference.
* Running linter
It turns out rollup doesn't use the same algorithm for bundling commonjs files when there are cycles as node, which breaks postcss: https://twitter.com/Rich_Harris/status/869021144191561729. Webpack works just fine with it.
This sucks to have this rollup/webpack frankenstein but I really want to be able to release and don't really want to spend yet another day or two trying to make it work well.