Commit Graph

87 Commits (master)

Author SHA1 Message Date
Ika 1965b74e61
refactor: move index.js and standalone.js to src (#5054)
There're always 2 files that they're source code but not in the `src` directory, which makes it hard to search.

- move the content of `index.js` and `standalone.js` to `src`.
- `/index.js` and `/standalone.js` are preserved as links to not break builds that's installed from git.
2018-09-06 13:51:18 +08:00
Lucas Duailibe 5c6e0802af
Don't default parser to babylon (#4528)
* Don't default parser to babylon

* Different default values according to version

* Fix error logging

* Add tests specifically for parser inference

* Add another test case

* Add API test
2018-05-23 16:55:06 -03:00
Alexander Kachkaev cc734753fc Implement prettier.getFileInfo() method and --file-info CLI option (#4341)
* Implement prettier.getFileInfo() method and --file-info CLI option

* Add empty line between functions in index.js

* Support --plugin-search-dirs / pluginSearchDirs() in --file-info / getFileInfo()

* Address review comments by @ikatyang
2018-05-10 00:53:44 +08:00
Alexander Kachkaev 7345a38e64 Fix plugin API in globally installed Prettier and introduce optional --plugin-search-dir (#4192)
* Fix plugin API in globally installed Prettier and introduce optional --plugin-search-dir

* Use find-parent-dir instead of find-up and test autoloading (with mocked fn)

* Add two test cases where --plugin-search-dir is not .

* Do not mutate pluginSearchDirs argument in load-plugins.js

* Do not test automatic plugin resolution as mocking of "find-parent-dir" does not work due to rollup

* Document --plugin-search-dir / pluginSearchDirs and improve spacing

* Address @ikatyang's review comments

* Fix require path for third-party

* Undo alphabetic sorting of third-party scripts
2018-05-09 19:17:12 +08:00
Lucas Duailibe 8015e417c0
Separate entry for web bundle (#4386) 2018-04-26 13:38:57 -03:00
Lucas Duailibe 67f1c4877e
Refactoring: better boundaries for different parts of the project (#4364) 2018-04-25 13:29:35 -03:00
Lucas Duailibe 13103101eb
Move pragma detection/insertion to plugins (#3685)
New pragma infrastructure, only JS and JSON has detection/insertion implemented
2018-03-08 13:50:33 -03:00
Christian Zosel b449a526ce Document new plugin API features (#3938)
* Document new plugin API features

* locStart / locEnd functions
* util-shared

* Expose shared util
2018-02-10 13:01:19 +11:00
Christian Zosel fac08034e7 Split out location extraction into plugin config (#3777)
* Split out location extraction into plugin config

* Reduce set of exported function, rebase to current master

* Pass custom locStart/locEnd fn's directly to affected methods

* (wip) always use locStart/locEnd from plugin

* Convert graphql implementation

* Convert HTML implementation

* (wip) convert JS implementation

* Remove unused variables

* Continue conversion of JS implementation

* Replace "util.locStart" with direct call to "options.locStart"

* Remove util closure

* Add unit test for structure of shared util

* Fix linting error, simplify locStart/End implementations
2018-02-09 23:17:48 +11:00
Lipis 7a7eb17082
fix: Proper case for Prettier, JavaScript, TypeScript, GitHub, Less (#3848) 2018-01-31 11:56:05 +01:00
Marcel Jackwerth a27d19b2c1 Allow Plugins to preprocess text (#3664)
* Allow Plugins to preprocess text

* Actually pull up text

* Always expect the preprocessor to set the text

* Add tests for preprocessing

* Remove unused variable
2018-01-10 00:27:26 +11:00
Lucas Azzola ee148bfded
Split up comment printing (#3575)
* Split up comment printing

* Refactor plugin handling

* Allow multiparser to use options normalization

* Rename to canAttachComment

* Add inline comment

* Format code

* Use prettier.__debug to get AST
2017-12-27 00:04:09 +11:00
Lucas Azzola 4c9d4061da
Prettier Plugin API (#3536)
* Move files around in preparation for refactor

* Update paths in build script

* Extract generic printing logic from the JavaScript printer

* Conform printer API

* Fixup decorator handling

* Fix multiparser

* Create plugin entry for markdown

* Create plugin entry for javascript/typescript

* Create plugin entry for html

* Create plugin entry for graphql

* Create plugin entry for css/less/scss

* Move JSON to JS plugin entry

* Integrate plugins into getSupportInfo()

* Move astFormat to parser definition

* Move util to common

* Implement parser loading

* remark -> mdast

* Rename cli/cli -> cli/index

* Rename builder -> doc package, fix printer resolution

* Fix doc shape assumption in CSS-in-JS logic

* Fix third-party.js prod resolution

* Fixup build-docs script

* Distribute multiparser code

* Remove requirement to forward options

* Flatten closure

* Remove debug directory

* Expose doc

* Add external plugins

* Pass options to loadPlugins

* Export getParsers

* Pin resolve version

* Use getSupportInfo in Markdown embed

* Document plugin API

* Update build-docs

* Add CLI for plugins

* Lint docs

* Fixup build.js

* Add vue language

* Fixup multiparser for vue

* Upgrade rollup and rollup-plugin-commonjs

* Fixup third-party build

* Change AST format in docs
2017-12-26 12:23:50 +11:00
Lucas Duailibe 90e8b13e86
Ignore whitespace in docblock right after /** (#3430) 2017-12-07 03:28:29 -02:00
Ika 76efb33e75 chore: setup markdown formatting (#3224)
* chore(deps): upgrade prettier to v1.8.2

* chore: setup lint-docs script

* docs: add `<!-- prettier-ignore -->`s

* docs: format docs

* Revert "docs: format docs"

This reverts commit 6dba903987dddc498cb589ca311905f25b6aee53.

* chore(prettierrc): set `--no-prose-wrap`

* docs: format docs

* Revert "docs: format docs"

This reverts commit 139bd744b6921916be8fac4fa3bab83bae5d12df.

* docs: tweak

* docs: format docs

* chore: rename .prettierrc

* chore: rename back to .prettierrc

* chore: split out third-party

* refactor: fix linting

* chore: do not split out third-party on website
2017-11-22 22:27:40 +11:00
Anton a0c95cf862 UTF8-BOM - if input string has BOM that mean output string also should have it (#3283)
The issue that prettier lost BOM and mean convert UTF-8 with BOM to just UTF-8
2017-11-21 14:38:21 -07:00
Lucas Azzola e436adae04
Implement getSupportInfo() and use it for inference (#3033)
* Implement getSupportInfo() and use it for inference

* Add comment with source of languages.yml

* Fix build, pin semver

* Simplify test snapshots

* Remove stray 'type' property

* Fix parser being overwritten

* Don't infer unreleased parser from extension

* Add CLI and docs for support info
2017-11-03 18:06:25 +11:00
Cyril Junod e589babeaf Split source elements relative to their language. (#3069)
* Split source elements relative to their language.

Colliding node types which are not source elements in every language.
Example ObjectExpression in JSON / JS

* Node4's Array.prototype.includes

* Ensure there is no confusion

ObjectExpression vs BlockStatement & LabeledStatement
2017-10-22 20:04:06 +11:00
Jake 50f3e646c7 Add option to insert @format to first docblock if absent (#2865)
* Add option to insert @format pragma if absent

prependPragma --> insertPragma

add tst dir, move stripBom, add to README, update snapshots

remove noise from test + update snapshots

use jest@test new functions, update docs, rerun snapshots

fix accidental upgrade to jest@test

update jest-docblock again to latest with strip()

updated snapshot

* updated snapshots

* revert jest dep change

* apply a trim to parsed comments

* remove empty object

* Revert "apply a trim to parsed comments"

This reverts commit 467f71ce5f4b4f8a1b5c4474ee0484bc96c92141.

* rerun snapshots with proper jest version

* pin jest-docblock to latest @test release

* comment out docs for new feature from readme

* remove leading newlines

* ensure blank line between docblock and rest of file

* remove backtick string
2017-10-06 19:37:14 +11:00
Simon Lydell 43cb08c45c Make production tests always run against dist/ (attempt 2) (#2942)
* Make production tests always run against dist/

* Try to mock process.stdin instead of get-stream

* fix: mock `get-stream` from `index.js`

* refactor: remove unnecessary variable

* Try `transform: {}` in jest.config.js

* Add comment explaining the unusual get-stream mocking
2017-10-02 17:58:55 +02:00
Will Binns-Smith d5e5d66407 Add option to require @prettier or @format pragma (#2772)
* Add option to require @prettier or @format pragma

Fixes #2397.

Inspired by `eslint-plugin-prettier` and the discussion in #2397, this
implements requiring a special comment pragma to be present in a file's
first comment in order to be formatted.

This will help large codebases gradually transition to prettier over
time without tons of churn or large code reviews.

I implemented this as a standard prettier "option", not just a typical
`argv` flag, as it is relevant in both the cli and the api. This way it
can be provided programmatically, on the command line, or standardized
in a prettierrc file so like the style options, every user can use this
setting consistently and only apply prettier to relevant files, no
mattier their editor integration.

This requires the pragma begin with `@` (in fact it's inserted if the
user doesn't provide it). Currently the usage implies it must be
"prettier" or "format", but it can technically be any value other than
"none", which is similar to the `trailingCommas` option.

cc @vjeux

* Don't quote anything in runPrettier; this is usually handled by a shell

* Make --require-pragma a boolean option

* Use jest-docblock to find pragmas without parsing the ast

* Clarify docs

* includes -> indexOf

* Move test out of integration
2017-09-13 09:03:18 -07:00
Joseph Frazier a78d1389f6 Use babylon.parseExpression for JSON (#2476)
* Add comments showing parser arguments

Since this is how they are invoked, the comments make it easier to maintain.

* Use babylon.parseExpression for JSON

See https://github.com/prettier/prettier/issues/2378#issuecomment-314600778

Note that this doesn't yet print comments:

    echo '{/*comment*/"K":"V"}' | ./bin/prettier.js --parser json

* Remove parser-json.js

This reduces duplicate code in the built package.
See https://github.com/prettier/prettier/pull/2476#pullrequestreview-50181398

* Add test with block comment in JSON

* Fix test with block comment in JSON

* Add test with line comment in JSON

* Don't build now-redundant parser-json.js
2017-07-24 11:43:49 +10:00
Lucas Azzola b7fa01af17 Enable code coverage in CI (#2497)
* Enable code coverage in CI

* Disable codecov comment

* Ignore some statements from coverage reports
2017-07-16 21:49:37 +10:00
Lucas Azzola 3136907a15 Expose clearCache function (#2451) 2017-07-11 20:40:51 +10:00
Lucas Azzola dcccfed366 Implement cosmiconfig for workspace configuration (#2434)
* Implement cosmiconfig

* Add resolveOptions API and extname support

* Add --resolve-config and --config, rename resolveOptions to resolveConfig

* Move color to top-level CLI options

* Fix unknown param warning

* Change from {} to null when no config is found

* Change override API to emulate eslint

* Add test for eslint-style overrides

* Delete overrides from resolveConfig
2017-07-10 22:26:36 +10:00
Joseph Frazier 0fb332b2f9 lint: Add yoda rule with range exception (#2433)
This required a small refactoring, but the code is less nested as a result.
See discussion at https://github.com/prettier/prettier/pull/2401#discussion_r125750068

http://eslint.org/docs/rules/yoda#exceptrange
2017-07-09 00:53:00 +10:00
Lucas Azzola 6f9824778d Strip BOM before parsing, fixes #2362 (#2373) 2017-07-01 18:11:13 +02:00
Joseph Frazier 8e37fd76e9 Add support for range-formatting GraphQL (#2319)
* Add test for range-formatting GraphQL

See https://github.com/prettier/prettier/issues/2296#issue-238985580

* Pass test for range-formatting GraphQL

See https://facebook.github.io/graphql/#sec-Appendix-Grammar-Summary.Query-Document

This fixes https://github.com/prettier/prettier/issues/2296

* Consider *Definition GraphQL nodes to be formattable

See https://github.com/prettier/prettier/pull/2319#discussion_r124569400
2017-06-28 09:21:11 -07:00
Joseph Frazier b47c0b4e04 Allow formatting ranges of JSON (#2298)
* Add test for https://github.com/prettier/prettier/issues/2297

* Add JSON types to isSourceElement()

See https://github.com/prettier/prettier/issues/2297

* Avoid expanding format range when possible

This fixes https://github.com/prettier/prettier/issues/2297

* Move JSON range test into tests/range_json

This is so that the AST_COMPARE=1 tests don't try to parse JSON with Flow.

* Check parser in isSourceElement()

Otherwise JSON formatting would format weird things inside of JS.
See https://github.com/prettier/prettier/pull/2298#discussion_r124407056

* Use arrow functions instead of .bind()

See https://github.com/prettier/prettier/pull/2298#discussion_r124409783

* Add test of range-formatting JSON identifier

See https://github.com/prettier/prettier/pull/2298/files#r124410750

* Allow range-formatting JSON identifier

See https://github.com/prettier/prettier/pull/2298/files#r124410750

* Fix lint
2017-06-27 16:04:42 -07:00
Cyril Junod 400f34624f Add module, class and typed nodes to sourceElements (#2266)
babylon flow typescript parsers

+ tests to cover module and class
2017-06-25 09:07:52 -07:00
Joseph Frazier 4b955a14c4 Return original input when specified range is unformattable (#2250)
* Add failing test for range-formatting whitespace

See https://github.com/prettier/prettier/issues/2247#issue-238322065

* Return original input when specified range is unformattable

Fixes https://github.com/prettier/prettier/issues/2247
2017-06-24 09:41:10 -07:00
Cyril Junod b0413fc1fe Range Formatter: Remove Program/File from valid Ancestor (#2248)
* Remove Program/File from valid Ancestor

Fix edge range formatting entire file.

* Fix lint with `yarn lint -- --fix`

See https://travis-ci.org/prettier/prettier/jobs/246569943#L242-L260
2017-06-24 12:30:27 -04:00
Christopher Chedeau f702c2c614 1.4.3
* Fix support for node 4 (#1988)
* Fix website on iOS Safari (#1970)

Formatting change:
* Position JSX whitespace (`{" "}`) at the end of lines (#1964)

Lots of small fixes, mainly for TypeScript.
2017-06-07 15:48:34 -07:00
Joseph Frazier c863cbeac8 Translate cursor relative to nearest node, not SourceElement (#1989)
* Add test demonstrating SourceElement-relative cursor translation

See https://github.com/prettier/prettier/issues/1981#issuecomment-306326739

* Translate cursor relative to nearest node, not SourceElement

This partially address https://github.com/prettier/prettier/issues/1981

See https://github.com/prettier/prettier/issues/1981#issuecomment-306326739

* Add test demonstrating incorrect cursor translation

Since the `cursorOffset` option (introduced in #1637) works by tracking
the cursor position relative to an AST node (rather than a CST token),
it can produce incorrect results.

See https://github.com/prettier/prettier/issues/1981
2017-06-05 18:51:53 -07:00
Joseph Frazier 3070884b10 Add shebang comment nodes to Flow/TypeScript ASTs (#1905)
* 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
2017-06-02 13:38:15 -07:00
Joseph Frazier c15091bea6 Preserve shebang in CLI output (#1899)
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.
2017-06-02 12:46:20 -07:00
Joseph Frazier 4bfeb9064d Add `cursorOffset` option for cursor translation (#1637)
* 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
2017-06-01 15:52:29 -07:00
Christopher Chedeau 05b921efdd Build the dist/ with rollup (#1794) 2017-05-28 21:49:41 -07:00
Joseph Frazier 9d7515907e Pass entire text through formatWithShebang() to format() (#1718)
* Verify shebang tests against Babylon as well as Flow/Typescript

* Pass entire text through formatWithShebang() to format()

That way, we won't have to do any arithmetic on range and cursor
locations when there is a shebang. See here for details:

https://github.com/prettier/prettier/pull/1637#issuecomment-303846507

This required changing comment printing such that comments that are
actually shebangs are just ignored.

* Add curly brace after `if`

See https://github.com/prettier/prettier/pull/1718#discussion_r118382574
2017-05-24 18:59:25 -04:00
Christopher Chedeau 78ba808322 Initial CSS support (#1636)
I wanted to see how hard it would be to add support for CSS inside of prettier. Turns out, it's not that hard. I spent a few hours printing post-css values and getting all the stylefmt unit tests to not throw.
2017-05-24 10:52:12 -07:00
Joseph Frazier 330601c77d Find nearest node when formatting range (#1659)
* Move range extension code into helper functions

* Add findNodeByOffset() helper

This was adapted from cbc1929c64

* Test extending formatted range to entire node

* Fix extending formatted range to entire node

* Fix style errors

* Add run_file test function

This makes it possible to use different options on a per-file basis,
which is useful for things like range formatting tests.

* Test extending the format range to nearest parseable node

This means you can select the range of a `catch` clause, attempt to
format it, and have the `try` formatted as well, rather than throwing an
error.

* Fix extending the format range to nearest parseable node

This means you can select the range of a `catch` clause, attempt to
format it, and have the `try` formatted as well, rather than throwing an
error.

* Test that external indentation is left alone when formatting a range

* Preserve external indentation when formatting a range

* Dedupe range formatting traversal callbacks

* Simplify range formatting traversal using ast-types

See https://github.com/prettier/prettier/pull/1659#issuecomment-302974798

* Make range formatting traversal more efficient

There's less unnecessary parsing now.

* Fix style errors

* Add test where range expanding fails

* Fix test where range expanding fails

This makes sure that the range contains the entirety of the nodes
containing each of the range's endpoints.

* Add test for expanding range to beginning of line

* Pass test for expanding range to beginning of line

This makes it so that indentation before the range is added to the
formatted range.

* Don't parse/stringify AST to detect pre-range indentation

See https://github.com/prettier/prettier/pull/1659#discussion_r117790671

* When formatting a range, find closest statement rather than parsing

The `isStatement` implementation came from `docs/prettier.min.js`.

See https://github.com/prettier/prettier/pull/1659#issuecomment-303154770

* Add test for range-formatting a FunctionDeclaration's argument object

* Include FunctionDeclaration when searching for nearest node to range-format

From the spec, a Program is a series of SourceElements, each of which is
either a Statement or a FunctionDeclaration. See
https://www.ecma-international.org/ecma-262/5.1/#sec-A.5

* Remove unnecessary try-catch

See https://github.com/prettier/prettier/pull/1659#discussion_r117810096

* Add tests with multiple statements

See https://github.com/prettier/prettier/pull/1659#discussion_r117810753

* Remove unnecessary arguments from findNodeByOffset()

* Contract format range to ensure it starts/ends on nodes

* Specify test ranges in the fixtures

See https://github.com/prettier/prettier/pull/1659#discussion_r117811186

* Remove unnecessary comments from range fixtures

* Remove run_file test function

It's no longer used. This essentially reverts
8241216e68f2e0da997a4f558b03658d642c89a2

* Update range formatting docs

Clarify that the range expands to the nearest statement, and not to the
end of the line.

* Don't overwrite test options when detecting range

Now that multiple files share the same object again, we shouldn't be
re-assigning to it.

* Reuse already-read fixtures for AST_COMPARE=1 tests

* Remove `run_file` global from test eslintrc

* Undo package.json churn

`yarn` reformatted it before, but the whitespace visually sets off the
comment, so let's put it back how it was before.

See https://github.com/prettier/prettier/pull/1659#discussion_r117864655

* Remove misleading comments from isSourceElement

See https://github.com/prettier/prettier/pull/1659#discussion_r117865196

* Loop backwards through string instead of reversing it

See https://github.com/prettier/prettier/pull/1659#discussion_r117865759

* Don't recompute indent string when formatting range

See https://github.com/prettier/prettier/pull/1659#discussion_r117867268

* Rename findNodeByOffset to findNodeAtOffset

"Find x by y" is the common usage for finding an `x` by a key `y`.
However, since "by" has positional meaning, let's use "at" instead.

See https://github.com/prettier/prettier/pull/1659#discussion_r117865121

* Always trimRight() in formatRange and explain why

See https://github.com/prettier/prettier/pull/1659#discussion_r117864635

* Test formatting a range that crosses AST levels

See https://github.com/prettier/prettier/pull/1659#issuecomment-303243688

* Fix formatting a range that crosses AST levels

See https://github.com/prettier/prettier/pull/1659#issuecomment-303243688

* Remove unnecessary try-catch

See e52db5e9f9 (r117878763)

* Add test demonstrating range formatting indent detection

* Detect alignment from text on line before range, but don't reformat it

This avoids reformatting non-indentation that happens to precede the
range on the same line, while still correctly indenting the range based
on it.

See https://github.com/prettier/prettier/pull/1659#discussion_r117881430
2017-05-23 07:43:58 -07:00
Joseph Frazier 569380155b Add `--range-start` and `--range-end` options to format only parts of the input (#1609)
* Add `--range-start` and `--range-end` options to format only parts of the input

These options default to `0` and `Infinity`, respectively, so that the
entire input is formatted by default. However, if either option is
specified such that a node lies completely outside the resulting range,
the node will be treated as if it has a `// prettier-ignore` comment.

Related to https://github.com/prettier/prettier/pull/1577#issuecomment-300551179
Related to https://github.com/prettier/prettier/issues/1324
Related to https://github.com/prettier/prettier/issues/593

* printer: Extract hasPrettierIgnoreComment() helper

* Move isOutsideRange() to util

* Don't throw errors about comments outside range "not printing"

* Remove unnecessary check from isOutsideRange()

* Make --range-end exclusive

This lets it use the conventional way of specifying ranges in strings.

Note that if the rangeEnd in the tests is changed to 158, it will fail,
but it wouldn't have failed before this change.

* Change range formatting approach

NOTE: This doesn't pass its test yet. Note that since we're reading the
indentation from the first line, it is expected not to change. However,
a semicolon is added, and the lines outside the range are not changed.

The new approach is roughly:

* Require that the range exactly covers an integer number of lines of the input
* Detect the indentation of the line the range starts on
* Format the range's substring using `printAstToDoc`
* Add enough `indent`s to the doc to restore the detected indentation
* Format the doc to a string with `printDocToString`
* Prepend/append the original input before/after the range

See https://github.com/prettier/prettier/pull/1609#issuecomment-301582273

---

Given `tests/range/range.js`, run the following:

    prettier tests/range/range.js --range-start 165 --range-end 246

See the range's text with:

    dd if=tests/range/range.js ibs=1 skip=165 count=81 2>/dev/null

* Don't use default function parameters

Node v4 doesn't support them. See
http://node.green/#ES2015-syntax-default-function-parameters

* Hackily fix indentation of range formatting

See
https://github.com/prettier/prettier/pull/1609#issuecomment-301625368

Also update the snapshot to reflect that the indentation actually should
decrease by one space, since there were 13 spaces in the input and we
round down after dividing by tabWidth.

* Revert "printer: Extract hasPrettierIgnoreComment() helper"

See https://github.com/prettier/prettier/pull/1609#discussion_r116804853

This reverts commit 62bf068ca98f69d4a7fd0ae188b3554d409eee8d.

* Test automatically using the beginning of the rangeStart line and same for the end

See https://github.com/prettier/prettier/pull/1609#issuecomment-301862076

* Fix automatically using the beginning of the rangeStart line and same for the end

See https://github.com/prettier/prettier/pull/1609#issuecomment-301862076

* Propagate breaks after adding an indentation-triggering hardline

See c1a61ebde8 (r116805581)

* Extract getAlignmentSize(), use instead of countIndents()

See c1a61ebde8 (r116804694)

* Extract addAlignmentToDoc(), use instead of addIndentsToDoc()

See c1a61ebde8 (r116804694)

* Document that --range-start and --range-end include the entire line

* Fix rangeStart calculation

Before, it was incorrectly resulting in 1 when the originally provided
value was 0

* Extract formatRange() helper function

* Move getAlignmentSize() from printer to util

This addresses https://github.com/prettier/prettier/pull/1609#discussion_r117636241

* Move addAlignmentToDoc() from printer to doc-builders

This addresses https://github.com/prettier/prettier/pull/1609#discussion_r117636251
2017-05-21 10:14:13 -07:00
Joseph Frazier 18fd014985 Run AST comparison tests on Travis (#1553)
* Run AST comparison tests on Travis

It looks like some of these currently fail, so we should probably also
sort that out.

Inspired by https://github.com/prettier/prettier/issues/1552

* tests: Use specified parser when AST_COMPARE=1

This fixes some of the tests with AST_COMPARE=1

* Move cleanAST() into prettier.__debug

This makes it available for tests to use.

* AST_COMPARE=1 uses cleanAst() instead of removeEmptyStatements()

Ths fixes some of the tests with AST_COMPARE=1

* Export parse() from src/parser.js

This makes it available for tests to use.

* tests: Use specified parser more when AST_COMPARE=1

This is a continuation of commit 86437a66d326919897fe89891a25824870f5bb79

This fixes some of the tests with AST_COMPARE=1

* massageAST: remove leadingComments/trailingComments

This fixes some of the tests with AST_COMPARE=1

* massageAST: remove `extra`

This fixes some of the tests with AST_COMPARE=1

* tests_config/run_spec.js: Rename variables for clarity

* AST_COMPARE=1 tests compare unstringified objects

This makes the test error output shorter.

* fixup! Export parse() from src/parser.js

* Revert "Run AST comparison tests on Travis"

See https://github.com/prettier/prettier/pull/1553#issuecomment-300027747

This reverts commit 49873a956c532f23fd216551a35ae35c1a18407e.

* fixup! fixup! Export parse() from src/parser.js

* parser: Require babel-code-frame only when needed

This addresses:
* https://github.com/prettier/prettier/pull/1553#discussion_r115386253
* https://github.com/prettier/prettier/pull/1553#discussion_r115386250

* parser: Don't export now-unused parseWith* functions

Addresses https://github.com/prettier/prettier/pull/1553#discussion_r115386964

* Move cleanAST/massageAST into own file, don't export

This addresses:
* https://github.com/prettier/prettier/pull/1553#discussion_r115386993
* https://github.com/prettier/prettier/pull/1553#discussion_r115386611

* Don't destructure require() result (Node v4 compat.)

* Fix copy/paste error
2017-05-08 18:16:35 -07:00
lamo2k123 4b3835925e fixed method 'check' error 'format' of undefined (#1424)
* fixed method 'check' error 'format' of undefined

* Added normalizeOptions
2017-04-26 11:02:53 -07:00
Christopher Chedeau 7a8380772d Have --debug-check also run ast verification (#1337) 2017-04-21 16:09:33 -07:00
Christopher Chedeau 08e4e2c04c Do not print the sub-tree when using prettier-ignore (#1286)
In #1250, @jeresig reported that adding // prettier-ignore on a file that has a ton of conditional group still took 1.7s. The issue is that we're printing before checking for the comment. Swaping the two had the unfortunate side effect of not marking the comments as being printed, so I had to skip that safety check if there's a prettier-ignore.

With this change, adding prettier-ignore makes the file be printed instantly!
2017-04-18 07:51:50 -07:00
Christopher Chedeau 8e1583fd16 Format the codebase using the pre-1.0 release (#1194) 2017-04-12 10:16:11 -07:00
Rafael Hengles 170e4d558a Refactored option to indent with tabs (#1026)
Refactored option to indent with tabs
2017-04-06 22:49:37 -04:00
Brian Holt eff5af6ca9 Add check method to Prettier Node API. (#1104)
* Add check method to Prettier. Make CLI use that method for list-different

* Catch in check and return false if it throws

* Remove catch/finally from Prettier list-different bin

* remove try catch in prettier bin for list-different
2017-04-03 09:54:10 -07:00
James Henry 72456bf06f [WIP] TypeScript Parser (#915)
* WIP immediate feedback

* typescript parser is drop-in replacement for flow parser

* Add new TypeScript Parser snapshots where drop-in replacement possible

* Snapshot updates after rebasing

* Remove unnecessary stripping of properties on TypeScript parser AST

* Remove annotated issues

* Move TS dependencies to dev for now
2017-03-08 13:18:13 -08:00