* 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
* refactor: extract `splitText`
* fix: respcet CJK width in table
* test: add failing test
* fix: support emoji
* test: add failing test
* feat: support CJK character
* feat: enable adding whitespace between non-CJK/CJK-character by default
* fix: do not print softline at node that is sensitive to its identifier
* fix: treat full-width whitespace as CJK punctuation
* disallow leading/trailing full-width whitespace
* feat: remove `--split-cjk-text` option and enable it by default
* refactor: simplify regex and remove unnecessary `g` flag
* feat(markdown): inital implementation
* feat(markdown): support strong
* fix: add missing default value
* feat(markdown): support inlineCode
* feat: support delete
* feat: support link
* feat: support image
* feat: support blockquote
* feat: support heading
* feat: support code
* feat: support yaml
* feat: support html
* feat: support list
* feat: support thematicBreak
* feat: support table
* feat: support linkReference
* feat: support imageReference
* feat: support definition
* feat: support footnote
* feat: support footnoteReference
* feat: support footnoteDefinition
* test(cli): update snapshots
* refactor: extract SINGLE_LINE_NODE_TYPES
* refactor: printChildren
* fix: correct newlines
* test: add trailing newline
* fix: blockquote formatting
* fix: node types
* fix: break line correctly
* fix: remove unnecessary properties to make AST_COMPARE happy
* fix: escape `|` in tableCell content
* fix: unexpected line break
* fix: ast difference from loose list
* fix: html break lines
* refactor: fix linting
* fix: normalize ast
* fix: escape specific chars
* test: add more tests
* fix: build markdown parser
* chore: remove unnecessary *.log
* fix: escape html entity
* feat: support prettier-ignore
* fix: line break for non-loose listItem
* feat: support formatting `code` based on `lang`
* fix: add `jsx` and `tsx`
* fix: use multiparser
* refactor: fix linting
* test: update test case 😉
* feat: switch to `_` style emphasis
* fix: sequence list should use different prefix
* test: add tests
* fix: do not print additional new line after `prettier-ignore`
* fix(list): enforce `1.` to avoid unnecessary git diff
* feat: enable `commonmark` option
* feat: support `break`
* fix: escape backslash
* refactor: escape html entity using backslash
* fix: respect autolink-style link
* feat: support md`...` and markdown`...`
* docs: replace ands with commas
* fix: respect indented code block
* fix: respect html entity
* docs: add docs for modified MDAST
* fix: inlineCode is breakline-able
* feat: support backtick in inlineCode
* feat: support a-lot-of-backtick in fenced code block
* feat: use `~~~`-style code block in js template
* fix: respect escaped chars
* fix: use `*`-style emphasis for invalid `_`-style output
* test: add test cases
* fix: use `- - -`-style thematicBreak to avoid conflict with yaml
* fix: remain the same content for linkReference identifier
* fix: `inlineCode` gap can be a line break
* fix: `html` should not print trailing spaces if it's in root
* refactor: fix typo
* fix: wrap `definition`'s url if there's whitespace
* fix: remove unnecessary whitespace at the end of paragraph
* fix: fix: remove unnecessary whitespace at the start of paragraph
* fix: setence children length is possible 0
* fix: support continuous ordered list
* fix: do not print addtional hardline after loose list
* fix: use double-backtick style for single-backtick value in inlineCode
* fix: support nested emphasis
* fix: support space-url in link/image
* fix: escape `)` in link/image url
* fix: support single-quote in link/image/definition title
* fix: respect alt in image/imageReference
* fix: use `*`-style thematicBreak in list
* fix: loose/tight list linebreaks
* fix: print third linebreak before indented code block with a tight list in the previous
* test: move bug cases
* fix: remove unnecessary linebreaks
* refactor: fix typo
* 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
* Split Less and SCSS parsing into different parsers
Now, .less files are always parsed with postcss-less, and .scss files
areare always parsed with postcss-scss. This:
- Is less hacky.
- Is meant to avoid issues like #2829.
- Is probably more performant.
`parser: "postcss"` and `--parser postcss` continue to work like before:
First trying postcss-less, and if that fails, postcss-scss, unless a
regex says that we should try in the opposite order. The new values for
the parser option are "postcss-less" and "postcss-scss".
* Remove postcss from package.json since it is not used
* Rename parser-less to less and parser-scss to scss
* Deprecate parser:postcss in favor of parser:css
* Fix CSS tests
* Upgrade cosmiconfig to v3, remove hardcoded combinatoric problem
* Fix indendation change from 1.7
* Ensure default value for useCache is true
* Pin mem version
* 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
This fixes a warning when installing prettier from github:
warning prettier > chalk@2.0.1: Please upgrade to Chalk 2.1.0 - template literals in this version (2.0.1) are quite buggy.
* 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
* 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
* initial docusaurus set-up
* Delete why-prettier.md
* Update README.md
* Update Docusaurus structure
* Update package.json
* Update siteConfig.js
* Remove ~ files
* chore(website): update build script
* Add redirect script
* Get eslint working on website
* Fix to allow for baseUrl of '/'
* Update docusaurus version
* Update README.md
* Change redirect script to use baseUrl of '/'
* Fix index.js formatting
* Load redirect script
* General cleanup
* Add projects using prettier
* Update service worker to just scope to playground
* Reduce link repeatition
* Link "Try it out" button to /playground/
* Make header of playground approximately same as main site
* Remove .html from URLs (e.g. users.html -> users/)
* Link Gitter Chat
* Add circleci.yml
* Only run builds on master
* Do deployment using Travis
This changes the eslint error formatting from:
/Users/josephfrazier/workspace/prettier/src/printer-postcss.js
3:31 error Insert `;` prettier/prettier
to:
✘ prettier/prettier Insert `;`
src/printer-postcss.js:3:31
const util = require("./util")
^
which makes them clickable in terminals like iTerm2 and Guake. See
[eslint-friendly-formatter] for details.
[eslint-friendly-formatter]: https://github.com/royriojas/eslint-friendly-formatter
Before, this error happened upon `yarn build`:
🚨 (commonjs plugin) Binding arguments in strict mode (49161:16) in /Users/josephfrazier/workspace/prettier/node_modules/typescript/lib/typescript.js
* 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.
* 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
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.
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.
We use a heuristic to figure out if it's a SCSS or Less file. And if it doesn't work, we try again with the other one. We do the same for JSX and TypeScript.
Fixes#1784
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.
* 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`.
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/.
* fix TSCallSignature
* fix TSTypeReference
* remove test with invalid syntax
* --wip--
* partially fix TSTypeReference
* get comments right for TypeScript interfaces
* Extract custom tests from tests/flow/
Approach:
1. Remove all .js files in tests/flow except .snap.js files.
2. Copy over all .js files from tests/ in the flow repo.
3. Go through the diff looking for deletions.
- It was easy to see which deletions were due to changes in the tests
due to updates in the flow repo.
- For the rest of the deletions, I used `git blame` to verify that
they had been added by us since the flow tests were copied over.
This makes tests/flow/ simply a copy of the tests from the flow repo,
making it easier to sync with the upstream flow tests in the future.
* Add a script for syncing the flow tests
* Sync the flow tests
ast-types was missing a type, I sent a PR on ast-type ( https://github.com/benjamn/ast-types/pull/211 ) which was merged and released (thanks @benjamn for being super quick!). So I'm upgrading ast-types and add the test in this PR.
Fixes#1007
* Add some typescript tests
* fix: Remove extraneous colon in type parameter constraint
* style: Add missing newline at EOF in TS tests
* feat: Pretty print typescript object type annotations
* feat: Pretty print TSFunctionType
* fix: Type annotations was missing on class properties
* Add a new batch of tests
* Bump typescript-eslint-parser
* Add a new batch of tests and fix a syntax error in previous
* Bump typescript-eslint-parser
* 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
* Make `--write` logs more informative.
* Add format duration to logs.
* Use colors instead of [ignore] and [update] labels.
* Remove `colors` dependency.
* Use `chalk` to colorize logs.
* Print filename before `format` and add duration info later.
* Print filename before read error.
This let's you run `pp(x) === pp(pp(x))` across an entire codebase quickly. I think it's small enough that we can merge it in to master while we are nailing down all the issues.
You can see the output in #610
* Validate user-provided config with jest-validate
* Don't use object shorthand
* Update jest-validate to 18.2
* Fix Node4 destructuring from require
* Make use of jest-validate for deprecation message
* Remove chalk reference
* Use babel-code-frame for syntax errors
* Support the `--color` option more explicitly
* Update rollup config to handle babel-code-frame
* Use exact dependencies
It doesn't compile cleanly anymore:
- esutils checks for Buffer.isBuffer without ensuring that Buffer exists.
- for version, we require a json file, need a rollup extension for that.
I no longer hardcode the version number.
Note: we need to merge this pull request after we have done the release so that the version number is correct and need to rebuild the minified version in a subsequent commit.
The current implementation with `JSON.stringify()` is clever but unfortunately generates incorrect JavaScript. Using `jsesc` seems like a better and safer option. https://github.com/mathiasbynens/jsesc It doesn't have any dependencies and is pretty small.
I opted for escaping all the non ascii characters, so we don't display emojis anymore. I don't think that the world is ready yet for having random unicode characters inside of source files, there still are so many parts of the toolchain that breaks with them. If we want to revert back on this decision, there's a `minimal` option on jsesc which only escapes values that need to in order to generate valid JavaScript file (assuming the encoding of the file is set to utf8).
Also, while working on React Native, we've seen that there is an optimization inside of jsc for js files that are all ascii: it doesn't do a copy for the conversion to ucs16.
Fixes#163
This is a very handy way of playing out with prettier without having to install it. People have already been using it actively in the issues. Putting it directly inside of the repo would be better than on mine.
- This brings in the flow test suite that contains a ton of JavaScript parsing edge cases
- This creates snapshot tests using the pretty printer for all of them
- If uncomment `RUN_AST_TESTS` line in `tests/run_specs.js`, it checks ast(pretty_print(x)) == ast(x). Right now, "178 failed, 197 passed, 375 of 377 total". So half of the tests are not passing, most of them are crashes and many of the rest are subtle issues.