Commit Graph

76 Commits (master)

Author SHA1 Message Date
Shinigami f059d7a31b JSDoc type added in `src/common/util.js` (#6788)
* JSDoc type added in `src/common/util.js`

* skip can return false

* Add TBD for false - 1 not allowed

* Define typedef SkipOptions

* Use method generic for node param

* Define node param for setLocStart and setLocEnd

* Copy idx param to local variable

* Add @returns false

* Update Utility functions docs

* hasNewline param index: allow only number

* Add condition

* Add function keyword to docs

* Add prettier-ignore

* Improve condition

* Remove TBD comment

* Use single quotes

* Add type to oldIndex

* Use singleline JSDocs
2019-11-05 13:28:44 +02:00
Dang Mai f6bd59dfd3 Allow plugin to specify option with type `string` (#6219) 2019-11-02 09:52:49 +01:00
Chris Brody 7eb4431350 JSDoc type fixes in `src/main/core-options.js` (#6702)
with unused `oppositeDescription` parameter removed

and reordering of some other members

to resolve checkJs issues in `src/main/core-options.js`,

as verified by the following command:

    npx tsc --allowJs --checkJs --noEmit --target es5 src/main/core-options.js
2019-10-25 19:25:15 +03:00
Georgii Dolzhykov 977b828666 Get rid of TSParenthesizedType nodes before proceeding with formatting (#6605)
* get rid of TSParenthesizedType nodes before proceeding with formatting

* fix parens for TSIndexedAccessType, TSFunctionType, TSConditionalType

fixes #6603

* workaround edge cases with one-item unions and intersections

* fix parens for TSInferType

* fix parens for rest elements in tuple types

* refactoring

* fix function types in conditional types

* move tests for rest and optional tuple elements

* fix comment issues

* tests for unions and intersections

* add parens around multiline unions in tuple

* move the parens check for TS nodes closer to the one for Flow nodes

* update CHANGELOG.unreleased.md

* remove dead code

* fix parens for TSConstructorType

* better wording in CHANGELOG.unreleased.md
2019-10-14 15:00:21 +03:00
Jack Bates af3084a63f Plugins can have falsy default options (#6348) 2019-09-12 18:52:48 +03:00
fisker Cheung 0e77cd3d33 Update ESLint to v6 (#6364) 2019-08-08 13:21:32 +03:00
Lucas Duailibe 4cc99242a8 Bump Prettier dependency to 1.18.0 2019-06-06 18:48:11 -03:00
Julian Rosse 64ab703d41 Pass options to willPrintOwnComments() (#6081) 2019-06-04 12:48:51 -03:00
Georgii Dolzhykov e4f0df5bed fix: nested embeds (JS in HTML in JS) (#6038) 2019-05-27 14:42:13 -03:00
mathieulj 26183e5be2 Use same print width for range formatting as normal formatting. (#6050)
* Use same print width for range formatting as normal formatting.

Fixes an issue were a file would end up formatted differently
with ranged formatting (--range-start & --range-end) versus
normal whole file formatting.

* Document range bugfix in changelog.
2019-05-04 10:18:55 -04:00
Warren Seine 3a9006659e Fix trailing comment output when the printer returns a doc instead of a string. (#5930)
Previously, Prettier printed `[Object object]` in that situation.
2019-03-03 11:15:08 -08:00
Lucas Azzola 2982dcd897
Fixup getSupportInfo for babylon parser prior to 1.16.0 (#5826)
This undoes an accidental breaking change where `prettier.getSupportInfo('1.0.0')` would report supporting the `babel` parser instead of `babylon`.

Fixes #5822
2019-02-03 21:57:59 +11:00
Nathan Totten a093bb3f7b Adds LWC Parser to support unquoted interop attributes (#5800)
This pull requests adds a new parser option `lwc`. This is the same as the HTML parser, but it adds support for unquoted HTML attributes per the needs of LWC. See: #5627
2019-02-01 13:58:50 +08:00
Ika a9fd8e2cf4
fix(api): do not report the same deprecation warning more than once (#5774)
A quick fix for suppressing duplicate deprecation warnings.
2019-01-20 15:38:19 +08:00
Ika 7c4cebeaa5
feat: add babel-flow (#5685) 2018-12-29 21:35:47 +08:00
Wei-Wei Wu 91c20f7fbe Rename "babylon" with "babel" (#5647) 2018-12-27 21:05:19 +08:00
lhchavez 911d6c88e5 Fix formatting with --range-start / --range-end (#5632)
This change avoids collapsing an already-formatted range into a single
overlong line when --range-start / --range-end are provided.

Fixes: #4923
2018-12-17 10:59:20 -02:00
Jed Fox b74f94d6dd
Remove the dynamic `require()` call in the standalone bundle (#5612)
* Remove the dynamic `require()` call in the standalone bundle

* Liiiint

* Just use `replaceStrings`

* Reword error message
2018-12-11 05:59:59 -05:00
Ika 952bc0cc03
fix: get rid of CRLF (#5494) 2018-12-08 18:28:29 +08:00
Ika b0b5460e8f
feat(cli): allow overriding (#5390) 2018-11-10 00:59:59 +08:00
Ika 514b6d3741 Bump Prettier dependency to 1.15.0 2018-11-07 09:12:25 +08:00
Alexander Kachkaev b87fe4cf22 Add option to enforce certain line endings (#5327) 2018-11-06 22:47:13 +08:00
Thomas Bartel dbe86abc24 Make ast-to-doc.js a little easier to understand (#5346)
Rename genericPrint function to callPluginPrintFunction to avoid similar name to printGenerically
Add comments that explain the descent/recursion
2018-11-05 07:34:27 -08:00
Ika 5e8a4a115a
feat: support HTML/Vue/Angular (#5259) 2018-11-04 23:03:07 +08:00
Petter 1244729ad7 Infer via shebang (#5149)
If no file type can be inferred, this attempts to read the first line of a file and extract a shebang, which can be checked against a known list.
2018-10-05 08:47:23 +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 4ff0f26d3e
refactor: move cli leven suggestion to options-normalizer (#5057)
Option-related processing should be done in `options-normalizer`.

- unknown flag suggestions are colored
  ![image](https://user-images.githubusercontent.com/8341033/45103027-866c7900-b161-11e8-8ee3-6467a9ca0090.png)
- unknown flags with no suggestion are now errors:
  ```
  $ bin/prettier.js --help noseminosemi
  [error] Invalid `--help` value. Expected `a flag`, but received `"noseminosemi"`.
  ```
2018-09-08 07:40:09 +08:00
Ika 50c9115632
feat: add printer.preprocess (#5041)
Sometimes we need to transform the ast to make it easier to print, but it's currently done in the parser (markdown and yaml), which leads the output ast harder to use for external users (custom parser), adding `printer.preprocess` can solve this issue.

And also this way we could move the trailing newline for json from `ast-to-doc.js` to `language-js`.
2018-09-03 23:27:50 +08:00
Ika 49e2f77bff
refactor: extract options-normalizer/validator (#5020)
- Uses [`vnopts`](https://github.com/ikatyang/vnopts#readme)
- This way it should be easier to support language-specific options (https://github.com/prettier/prettier/pull/4798#issuecomment-407258477) and map the common options to language-specific options using [`forward`](https://github.com/ikatyang/vnopts#forward), e.g. `singleQuote: true` -> `"javascript/singleQuote": "js"`, `singleQuote: false` -> `"javascript/singleQuote": "none"`.
2018-08-31 11:26:07 +08:00
Ika 1790211f76
feat: support MDX (#4975)
* feat: support MDX

* refactor: flip condition
2018-08-13 22:23:09 +08:00
Ika 53c83f97f5
fix: guess line ending before preprocess (#4957) 2018-08-09 10:51:08 +08:00
Ika 1915cc3c46
chore: enable glimmer parser on preview playground (#4915) 2018-08-01 15:44:37 +08:00
Ika 02f64af6e3
fix(vue): no error on range format (#4868) 2018-07-22 15:58:29 +08:00
Ika 1a2c4e663e
chore: use pre-release version number on master (#4855)
* chore: use pre-release version number on master

* docs: tweak comment
2018-07-18 09:38:26 +08:00
Prashant Andani cdcb7b11c9 Use destructures and refactor code for readability (#4844)
* Use destructuring for readability and optimzations at for loop length property

* Destructure variables for easy maintainability of code

* PR review fix

* refactor: fix linting

* Use destructures and refactor code for better readability

* Remove merge conflict line

* lint before commit
2018-07-17 18:01:44 -03:00
Prashant Andani 12cb8a9688 Use destructuring for readability and optimzations at 'for' loop length property… (#4842)
* Use destructuring for readability and optimzations at for loop length property

* Destructure variables for easy maintainability of code

* PR review fix

* refactor: fix linting
2018-07-16 22:39:41 +08:00
Ika 432c9d7d04
feat(yaml): support proseWrap (#4742)
- support `proseWrap` in `yaml`
- move `proseWrap` to `commonOptions`
- update to `yaml@1.0.0-rc.4` and `yaml-unist-parser@1.0.0-rc.1`
2018-07-04 00:28:47 +08:00
Ika 9bb8edf96a
feat: support .js.flow (#4777)
* feat: support .js.flow

* feat: add Flow language entry
2018-07-01 16:18:08 +08:00
Ika 0b659b898d
feat: update linguist languages (#4741)
Context: https://github.com/prettier/prettier/pull/4734#issue-196702272

Languages should be easy to maintain now.
2018-06-28 08:24:02 +08:00
Ika f53b5b8323
fix(options): inferParser for standalone (#4721) 2018-06-22 12:43:44 +08: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
Joseph Frazier 88be12ca07
Allow `originalText` to be passed to `formatAST()` (#4677)
This allows `prettier.__debug.formatAST` to not crash when given the AST
for the below code (taken from https://astexplorer.net/), which is
useful when trying to use Prettier as a code generator for an AST
without corresponding source code (https://github.com/prettier/prettier/issues/4675)

```js
let tips = [
  "Click on any AST node with a '+' to expand it",

  "Hovering over a node highlights the \
   corresponding part in the source code",

  "Shift click on an AST node expands the whole substree"
];

function printTips() {
  tips.forEach((tip, i) => console.log(`Tip ${i}:` + tip));
}
```
2018-06-13 12:30:14 -04:00
Tony Trinh dcc060a5a5 refactor: remove redundant call to normalizeOptions (#4671)
Removes redundant call to `normalizeOptions` (already done in preceding line)

8ec5432768/src/main/core.js (L260-L263)
2018-06-12 10:56:16 +08:00
Aakansha Doshi 8ec5432768 Fix empty file error in json and graphql (#4553)
* Fix empty file error in json and graphql

* fix AST_COMPARE=1 issue

* use tests/empty

* revert

* fix lint
2018-06-06 10:41:12 -03:00
Lucas Duailibe 1350edc5a6 Revert no parser error for API (#4587)
* Revert no parser error for API

* use warn
2018-05-28 23:43:44 -06: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
Lucas Duailibe 52a2a46b3c
New build system (#4449) 2018-05-24 15:30:45 -03: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
Joseph Frazier 6d49a224c9
Don't format range if required pragma is missing outside range (#3996)
* Add tests demonstrating --require-pragma behavior with range

* Don't format range if required pragma is missing outside range

Fixes https://github.com/prettier/prettier/issues/3985
2018-05-17 13:38:50 -04:00