Commit Graph

75 Commits (master)

Author SHA1 Message Date
Ika 952bc0cc03
fix: get rid of CRLF (#5494) 2018-12-08 18:28:29 +08:00
Ika 4af3dd4b07
test: improve snapshots (#5521)
- before
  ```
  ${input}${"~".repeat(printWidth)}
  ${output}
  ```
- after
  ```
  ===options===
  ${options}
  ${" ".repeat(printWidth)}| printWidth
  ====input====
  ${input}
  ===output====
  ${output}
  =============
  ```
2018-11-25 16:21:14 +08:00
Alexander Kachkaev b87fe4cf22 Add option to enforce certain line endings (#5327) 2018-11-06 22:47:13 +08:00
Ika 5e8a4a115a
feat: support HTML/Vue/Angular (#5259) 2018-11-04 23:03:07 +08:00
Ika 13147facc5
feat(html): switch to htmlparser2 (#5127)
- switch to [`htmlparser2`](https://github.com/fb55/htmlparser2)
  - no need to fork
  - won't generate pseudo nodes ([`parse5` will](https://github.com/prettier/prettier/issues/5098#issuecomment-423055181))
  - should be [faster](https://github.com/fb55/htmlparser2#performance)
- support custom self-closing tags
- support HTML entities
- remove extra trailing newline for `<template>`
- distinguish empty/empty-string attributes (`<tag x>`/`<tag x="">`)
- rename `--parser parse5` with `--parser html`
- enable `html` since 1.15, which means it's enabled by default if you install the dev version from GitHub after this PR merged.
2018-09-22 21:53:38 +08:00
Ika 79f4251e26
chore: enable html on preview playground (#5105) 2018-09-19 09:19:18 +08:00
Ika 55e620bdc7
chore: extract jest snapshot serializers (#5034) 2018-09-01 12:11:19 +08:00
Ika 3842cbb118
fix(typescript): use the first error when both failed (#4947) 2018-08-09 10:21:00 +08:00
Ika 1915cc3c46
chore: enable glimmer parser on preview playground (#4915) 2018-08-01 15:44:37 +08:00
Simen Bekkhus e25021711d Upgrade to Jest 23 (#4809) 2018-07-04 16:54:39 -03:00
Simen Bekkhus 51b7c02e12 Upgrade jest to 22 (#4782)
* chore: upgrade Jest

* chore: update snapshots

* chore: lock down babel dependency using invalid syntax

* 2 args to test.skip

* use jest 22 for now

* Revert "2 args to test.skip"

This reverts commit 691fdc3f99e320f2303958f2b503f7b4c93fa455.

* remove snapshot name from matcher

* fix standalone tests skips
2018-07-03 03:06:29 -03:00
Ika dcf44ffbdc
feat: support YAML (#4563)
* feat: support YAML

* fix: do not indent sequence in mappingValue

* docs: add yaml to index.md

* fix: reduce `SyntaxError: Node#parse consumed no characters`

* chore: remove old-build and new-worker.js

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* fix: no space after `<<`

* fix: add yaml to standalone test

* test: add tests

* fix: next empty line in flow collection

* fix: tabs are not allowed
http://yaml.org/spec/1.2/spec.html#space/indentation/

* fix: update parser

* feat: rewrite the mappingItem logic
* feat: indent sequence in mapping
* feat(doc): add ifBreak#groupId and group#id

* chore: fix node 4

* chore: add tools_yaml.svg

* chore: remove resolved TODO

* refactor: remove unnecessary workaround

* chore(worker): importScriptOnce

* chore(build): rename with babelPlugins

* make it rollup compatible

* feat: support singleQuote

* refactor
2018-06-21 10:29:42 +08:00
Lucas Duailibe 889b7dab79
Run tests using the standalone build in an empty context (#4668)
Validate that our build is stripping all the "native" dependencies (native modules and env vars).
2018-06-12 15:05:40 -03:00
Lucas Azzola b0cb63a7bb
Use destructuring for imports (#4554)
* Use destructuring for imports

* Clean up integration tests

* Use moduleNameMapper for require_prettier
2018-05-27 21:36:12 +10:00
Ika d0f6aac001
refactor(massageAst): move stripLocation to corresponding plugins (#4477) 2018-05-14 20:52:27 +08:00
David Sheldrick d77f5e9c3a Fix cursor offset tracking (#4397)
* handle cusor position relative to comments correctly

* use more robust method of cursor offset tracking

* add support for cursorOffset with rangeStart/End

* add tests for cursorOffset

* use old JS syntax for node4

* add another cursor offset test case

* remove trailing whitespace in cursor tests

* fix null findNodeAtOffset handling

* remove dead code

* add more test cases

* use indexOf for node4

* revert comments.js

* add more comment tests

* change tests infra

* Fix AST_COMPARE

* move CURSOR to top level of file

* mutate result

* use es6 property shorthand

* simplify diff offset calculation

* put remaining test cases in individual files
2018-05-01 09:42:59 -03:00
Lucas Duailibe 67f1c4877e
Refactoring: better boundaries for different parts of the project (#4364) 2018-04-25 13:29:35 -03:00
Lucas Azzola dd78f31aaf
Run production tests on npm package (#3730)
* Run production tests on npm package

* Put back fast finish
2018-01-13 03:19:20 +11: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 e5d6a4704f
Automatically load plugins from package.json (#3624)
* Automatically load plugins from package.json

* Fix build by adding json extension

* Fixup misuse of options argument

* Rewire graceful-fs to fs

* Document graceful-fs issue

* Alias graceful-fs to fs in Rollup
2018-01-05 21:09:51 +11:00
Lucas Azzola a041914551
Extract cleanAST to language-specific files (#3610)
* Extract cleanAST to language-specific files

* Fix lint

* Fix clean-ast for vue and glimmer
2017-12-30 21:30:09 +11:00
Lucas Azzola bd78b3bfbe
Remove ALL_PARSERS, print ~ printWidth times (#3596) 2017-12-29 08:25:11 +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 Azzola d1c97b3622
Convert eslint config and users/languages/editors files to YAML (#3516)
* YAML all the things

* Cleanup website data files

* Update edit links
2017-12-18 21:55:10 +11:00
Lucas Duailibe f119d4a90f
Change run_spec to have explicit parser list (#3356) 2017-11-30 03:31:52 -03:00
Ika 76ee59a191
chore(deps): update prettier to 1.8.0 (#3167)
* chore(deps): update prettier to 1.8.0

* refactor: fix linting
2017-11-07 16:42:38 +08:00
Lucas Azzola 1d3c86be4d Fix util.getStringWidth for falsy input (#3092) 2017-10-24 15:19:27 +11:00
Chris Voll 67e4b7db04 fix: add filenames to flow-verify test descriptions (#2991) 2017-10-08 09:04:40 +02: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
Lucas Azzola 364c38de0d Implement custom parser API (#1783)
* feat(api): add custom parser API

* test(api): add integration test for parser resolution

* chore(api): fix build after resolving conflicts

* docs(api): document custom parser API

* docs(api): fix typo

* chore(build): add parse5 to build and support yarn test --prod
2017-06-12 16:51:12 +10:00
Lucas Azzola fdb7467de7 feat(html): add support for HTML fragments (#2093) 2017-06-10 20:10:34 -07:00
Lucas Azzola 8903e5e527 fix(html): fix AST_COMPARE on htmlparser2 ASTs (#2084) 2017-06-09 19:45:39 -07:00
Lucas Azzola d00956d51d feat(html): add parse5/htmlparser2 printer (#2083) 2017-06-09 19:22:59 -07: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
Jon Wong e33d6773d6 Adding support for `graphql` (#1982)
* Initial GraphQL implementation

This is the bare minimum amount of code to make graphql work. Turns out it's pretty easy to add support for other languages :)

* Fixing support for `graphql` parsing

There was a few structural changes with the addition of CSS and Typescript that we had to take into account.

* Fixing file glob, adding `graphql` to yarn.lock

* Removing extraneous file

* Adding `graphql` parser, style changes

* Splitting out graphql printer

* Removing merge conflict

* Fixing yarn.lock

* Addressing code review, using `createError`

* Adding release config

* Using exact version

* Removing destructuring
2017-06-05 12:34:08 -07:00
Joseph Frazier a983d30663 Use `filepath` option instead of `filename` in tests (#1846)
This silences the validation warnings like:

    Unknown option "filename" with value "/home/travis/build/prettier/prettier/tests/flow/es_declare_module/flow-typed/declares.js" was found.

See here for an example:
https://travis-ci.org/prettier/prettier/jobs/238474756#L397

Related to commit 0d9b04b (https://github.com/prettier/prettier/pull/1835)
2017-06-01 14:40:49 -07:00
Christopher Chedeau 05b921efdd Build the dist/ with rollup (#1794) 2017-05-28 21:49:41 -07: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
Simon Lydell 378682350f Improve ESLint setup and fix errors (#1656)
* Improve ESLint setup

- Uses `eslint:recommended` + a handful more rules.
- Uses .eslintignore so that editors can understand which files to lint.
- Uses .eslintrc<strong>.js</strong> so more editors get syntax highlighting.

* Fix ESLint errors

About half of them were fixed by `eslint . --fix`.
2017-05-21 12:11:09 -07:00
Simon Lydell bc5186e544 Run Prettier on all source files (#1648)
This commit updates `npm run format:all` to not only format .js files in
src/ and bin/, but also tests_config/ and scripts/, as well as all
jsfmt.spec.js files.

It also includes the result of running `npm run format:all`, except
changes to src/ and bin/.
2017-05-21 08:13:11 -07:00
Joseph Frazier c56a685e5d tests: Rename `RUN_AST_TESTS` variable to `AST_COMPARE` (#1563)
This makes it match the environment variable, which is consistent with
the other variables.
2017-05-09 13:32:01 -04:00
Joseph Frazier 09fd8de526 Also run normal tests when AST_COMPARE=1 (#1561)
This makes it easier to just use `AST_COMPARE=1 npm test`, instead of
having to run `npm test` separately.
2017-05-08 20:23:51 -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
Joseph Frazier 2ce6632082 Fix variable name in getParsersToVerify() (#1554)
It previously referred to an undefined variable.
2017-05-08 17:27:39 -07:00
Lucas Azzola 44934da349 feat(typescript): add fallback for JSX detection (#1551) 2017-05-08 05:57:19 -07:00
Danny Arnold 5ee0385d79 [WIP] add TSNamespaceExportDeclaration (#1459)
* add TSNamespaceExportDeclaration

* extract ast-types/fork

* add TSEnumDeclaration and TSEnumMember

* add TSImportEqualsDeclaration and TSExternalModuleReference

* add TSInterfaceDeclaration and type annotation to TSMethodSignature

* add TSModuleDeclaration, TSDeclareKeyword, TSModuleBlock and fix TSNamespaceExportDeclaration

* remove workaround
2017-05-01 09:25:49 -07:00
Davy Duperron c609a5415a [experimental] Add linting step in test pipeline (#1172)
* Add eslint as dev dep, reorder scripts.

* Add tests & docs to eslintignore.

* Add eslintcache to gitignore.

* Update yarn lock file 😽.

* Add linting step in the test pipeline.

* Add a set of really basic rules for linting.

* Fix linting 🚀.

* No need for .jsx files to be linted...

* Reorder rules alphabetically.

* Refine rules: drop styling ones, only keep what provides dead code elimination.

* Add no-console rule to be consistent along with the no-debugger one.

* Remove empty line.

* Add eslint-disable-next-line no-console where console log/warn/error are allowed.

* Drop no-console rule.

* Remove eslint-disable-next-line no-console comments.

* Remove linting step in Travis CI.

* Fix linting after merging current master.

* Run `npm test -- -u` after noticing one test was out of sync.

* Drop eslint references from previous implementation.

* Revert yarn lock file.

* Revert scripts ordering.

* Fix incorrect yarn lock file.
2017-04-25 09:48:56 -07:00
Brian Ng 485028c32f Fix ALL_PASERS typo in run_spec (#1227) 2017-04-13 07:08:55 -07:00