Socket
Socket
Sign inDemoInstall

prettier

Package Overview
Dependencies
Maintainers
2
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

42

bin/prettier.js

@@ -69,3 +69,3 @@ #!/usr/bin/env node

if (value === "flow" || value === "babylon") {
if (value === "flow" || value === "babylon" || value === "typescript") {
return value;

@@ -186,20 +186,17 @@ }

" --write Edit the file in-place. (Beware!)\n" +
" --list-different or -l Print filenames of files that are different from prettier formatting\n" +
" --list-different or -l Print filenames of files that are different from Prettier formatting.\n" +
" --stdin Read input from stdin.\n" +
" --print-width <int> Specify the length of line that the printer will wrap on. Defaults to 80.\n" +
" --tab-width <int> Specify the number of spaces per indentation-level. Defaults to 2.\n" +
" --use-tabs Indent lines with tabs instead of spaces. Defaults to false.\n" +
" --no-semi Do not print semicolons, except at the beginning of lines which may need them. Defaults to false.\n" +
" --single-quote Use single quotes instead of double.\n" +
" --bracket-spacing Put spaces between brackets. Defaults to true.\n" +
" --jsx-bracket-same-line Put > on the last line. Defaults to false.\n" +
" --use-tabs Indent lines with tabs instead of spaces.\n" +
" --no-semi Do not print semicolons, except at the beginning of lines which may need them.\n" +
" --single-quote Use single quotes instead of double quotes.\n" +
" --no-bracket-spacing Do not print spaces between brackets.\n" +
" --jsx-bracket-same-line Put > on the last line instead of at a new line.\n" +
" --trailing-comma <none|es5|all>\n" +
" Print trailing commas wherever possible. Defaults to none.\n" +
" --parser <flow|babylon> Specify which parse to use. Defaults to babylon.\n" +
" --color Colorize error messages. Defaults to true.\n" +
" --version or -v Print prettier version.\n" +
"\n" +
"Boolean options can be turned off like this:\n" +
" --no-bracket-spacing\n" +
" --bracket-spacing=false"
" --no-color Do not colorize error messages.\n" +
" --version or -v Print Prettier version.\n" +
"\n"
);

@@ -273,9 +270,9 @@ process.exit(argv["help"] ? 0 : 1);

fs.writeFile(filename, output, "utf8", err => {
if (err) {
console.error("Unable to write file: " + filename + "\n" + err);
// Don't exit the process if one file failed
process.exitCode = 2;
}
});
try {
fs.writeFileSync(filename, output, "utf8");
} catch (err) {
console.error("Unable to write file: " + filename + "\n" + err);
// Don't exit the process if one file failed
process.exitCode = 2;
}
}

@@ -296,2 +293,7 @@ } else if (argv["debug-check"]) {

patterns.forEach(pattern => {
if (!glob.hasMagic(pattern)) {
callback(pattern);
return;
}
glob(pattern, (err, filenames) => {

@@ -298,0 +300,0 @@ if (err) {

@@ -0,1 +1,31 @@

# 1.2.0
[link](https://github.com/jlongster/prettier/compare/1.1.0...1.2.0)
* match jsx files in pre-commit hook (#1276)
* Fix isPreviousLineEmpty on Windows (#1263)
* Add --dev option to suggested install cmd (#1289)
* Write out change CLI changes synchronously. Fixes #1287. (#1292)
* Remove emoji part from lint-staged's name (#1302)
* omit 'doc' key from options object before passing it to format() (#1299)
* Skip globbing filenames with node-glob when the filename is not a glob (#1307)
* FIX: more documentation for jetbrains (#1265)
* Fix template literal comments (#1296)
* Double quotes for option values in Readme file (#1314)
* Do not print the sub-tree when using prettier-ignore (#1286)
* Bail when traversing === groups (#1294)
* Avoid breaking arguments for last arg expansion (#1305)
* Add typescript as a valid parser value (#1318)
* Add jestbrains filewatcher docs (#1310)
* Add prettier_d to Related Projects (#1328)
* Add parentheses for assignment as body of arrow (#1326)
* Add information about Vim's other autocmd events (#1333)
* add printer branch for TSFirstTypeNode (#1332)
* Optimize `prettier --help` for humans (#1340)
* Update link to @vjeux's React London presentation (#1330)
* Improve regex printing (#1341)
* Fix arrow function parenthesis with comments in flow (#1339)
* Break if () if conditional inside breaks (#1344)
* Don't inline paren at right of arguments (#1345)
# 1.1.0

@@ -6,11 +36,11 @@

* Prettier 1.0 is the stabler release we've been waiting for (#1242)
* fix small typo (#1255)
* Fix : ReferenceError: err is not defined (#1254)
* Document debugging strategies (#1253)
* Do not inline member expressions as part of assignments (#1256)
* Fix flow union params (#1251)
* Use a whitelist instead of blacklist for member breaking (#1261)
* Remove trailing whitespace (#1259)
* Get rid of fixFaultyLocations code (#1252)
* Fixing n.comments check in printer (#1239)
* fix small typo (#1255)
* Fix : ReferenceError: err is not defined (#1254)
* Document debugging strategies (#1253)
* Do not inline member expressions as part of assignments (#1256)
* Fix flow union params (#1251)
* Use a whitelist instead of blacklist for member breaking (#1261)
* Remove trailing whitespace (#1259)
* Get rid of fixFaultyLocations code (#1252)
* Fixing n.comments check in printer (#1239)
* [WIP] no-semi comments (#1257)

@@ -17,0 +47,0 @@

@@ -1,15 +0,26 @@

### Configure External Tool
## Configure External Tool
Go to *File | Settings | Tools | External Tools* for Windows and Linux or *WebStorm | Preferences | Tools | External Tools* for OS X and click **+** to add a new tool. Let’s name it **Prettify**.
https://blog.jetbrains.com/webstorm/2016/08/using-external-tools/
In **Program** set `prettier`
Go to *File | Settings | Tools | External Tools* for Windows and Linux or *WebStorm | Preferences | Tools | External Tools* for OS X and click **+** to add a new tool. Let’s name it **Prettier**.
In **Parameters** set `--write [other opts] $FilePathRelativeToProjectRoot$`
* **Program** set `prettier`
In **Working directory** set `$ProjectFileDir$`
> If on the other hand you have `prettier` installed locally, replace the **Program** with `./node_modules/.bin/prettier` (on OS X and Linux) or `.\node_modules\.bin\prettier.cmd` (on Windows).
![Example](https://raw.githubusercontent.com/jlongster/prettier/master/editors/jetbrains/with-prettier.png)
* **Parameters** set `--write [other opts] $FilePathRelativeToProjectRoot$`
* **Working directory** set `$ProjectFileDir$`
If on the other hand you have `prettier` installed locally, replace the **Program** with `./node_modules/.bin/prettier` (on OS X and Linux) or `.\node_modules\.bin\prettier.cmd` (on Windows).
![Example](https://raw.githubusercontent.com/prettier/prettier/master/editors/jetbrains/with-prettier.png)
### Process directories
* Clone the External tool created above and name it `Prettier Directories`
* **Parameters** set `--write [other opts] $FileDirRelativeToProjectRoot$/**/(*.js|*.jsx)`
## Usage
* Cmd-Shift-A on OS X or Ctrl+Shift+A on Windows and Linux
* Type: 'prettier' and hit enter
### Configure Keymap

@@ -20,1 +31,11 @@

See [this documentation](https://www.jetbrains.com/help/webstorm/configuring-keyboard-shortcuts.html) about configuring keyboard shortcuts.
## Using File Watcher
To automatically format using `prettier` on save, you can use a file watcher.
Go to *File | Settings | Tools | File Watchers* for Windows and Linux or *WebStorm | Preferences | Tools | File Watchers* for OS X and click **+** to add a new tool. Let’s name it **Prettier**.
* **Program** set the full path to a `prettier` executable, such as `/Users/developer/repo/jest/node_modules/.bin/prettier` (on OS X and Linux) or `C:/\Users\developer\repo\jest\node_modules\.bin\prettier.cmd` (on Windows).
* **Parameters** set `--write [other opts] $FilePath$`
* **Working directory** set `$ProjectFileDir$`

@@ -59,2 +59,10 @@ "use strict";

function ensureAllCommentsPrinted(astComments) {
for (let i = 0; i < astComments.length; ++i) {
if (astComments[i].value.trim() === "prettier-ignore") {
// If there's a prettier-ignore, we're not printing that sub-tree so we
// don't know if the comments was printed or not.
return;
}
}
astComments.forEach(comment => {

@@ -61,0 +69,0 @@ if (!comment.printed) {

{
"name": "prettier",
"version": "1.1.0",
"version": "1.2.0",
"description": "Prettier is an opinionated JavaScript formatter",

@@ -5,0 +5,0 @@ "bin": {

@@ -41,3 +41,3 @@ # Prettier

<a href="https://www.youtube.com/watch?v=hkfBvpEfWdA"><img width="298" src="https://cloud.githubusercontent.com/assets/197597/24886367/dda8a6f0-1e08-11e7-865b-22492450f10f.png"></a> <a href="https://www.youtube.com/watch?v=ziAShzxAVKY"><img width="298" src="https://cloud.githubusercontent.com/assets/197597/24886368/ddacd6f8-1e08-11e7-806a-9febd23cbf47.png"></a>
<a href="https://www.youtube.com/watch?v=hkfBvpEfWdA"><img width="298" src="https://cloud.githubusercontent.com/assets/197597/24886367/dda8a6f0-1e08-11e7-865b-22492450f10f.png"></a> <a href="https://www.youtube.com/watch?v=0Q4kUNx85_4"><img width="298" src="https://cloud.githubusercontent.com/assets/197597/24886368/ddacd6f8-1e08-11e7-806a-9febd23cbf47.png"></a>

@@ -121,3 +121,3 @@ This goes way beyond [ESLint](http://eslint.org/) and other projects

```
yarn add prettier
yarn add prettier --dev
```

@@ -162,3 +162,3 @@

[🚫💩 lint-staged](https://github.com/okonet/lint-staged) can re-format your files that are marked as "staged" via `git add` before you commit.
[lint-staged](https://github.com/okonet/lint-staged) can re-format your files that are marked as "staged" via `git add` before you commit.

@@ -187,3 +187,3 @@ Install it along with [husky](https://github.com/typicode/husky):

See https://github.com/okonet/lint-staged#configuration for more details about how you can configure 🚫💩 lint-staged.
See https://github.com/okonet/lint-staged#configuration for more details about how you can configure lint-staged.

@@ -194,3 +194,3 @@ Alternately you can just save this script as `.git/hooks/pre-commit` and give it execute permission:

#!/bin/sh
jsfiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.js$' | tr '\n' ' ')
jsfiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.jsx\?$' | tr '\n' ' ')
[ -z "$jsfiles" ] && exit 0

@@ -245,4 +245,4 @@

// Which parser to use. Valid options are 'flow' and 'babylon'
parser: 'babylon',
// Which parser to use. Valid options are "flow" and "babylon"
parser: "babylon",

@@ -354,2 +354,17 @@ // Whether to add a semicolon at the end of every line (semi: true),

#### Other `autocmd` events
You can also make Vim format your code more frequently, by setting an `autocmd` for other events. Here are a couple of useful ones:
* `TextChanged`: after a change was made to the text in Normal mode
* `InsertLeave`: when leaving Insert mode
For example, you can format on both of the above events together with `BufWritePre` like this:
```vim
autocmd BufWritePre,TextChanged,InsertLeave *.js Neoformat
```
See `:help autocmd-events` in Vim for details.
#### Customizing Prettier in Vim

@@ -420,2 +435,3 @@

- [`neutrino-preset-prettier`](https://github.com/SpencerCDixon/neutrino-preset-prettier) allows you to use Prettier as a Neutrino preset
- [`prettier_d`](https://github.com/josephfrazier/prettier_d.js) runs Prettier as a server to avoid Node.js startup delay

@@ -422,0 +438,0 @@

@@ -247,3 +247,3 @@ "use strict";

handleTemplateLiteralComments(enclosingNode, comment) ||
handleCommentInEmptyParens(enclosingNode, comment) ||
handleCommentInEmptyParens(text, enclosingNode, comment) ||
handleOnlyComments(enclosingNode, ast, comment, isLastComment)

@@ -509,3 +509,3 @@ ) {

const expressionIndex = findExpressionIndexForComment(
enclosingNode.expressions,
enclosingNode.quasis,
comment

@@ -521,3 +521,7 @@ );

function handleCommentInEmptyParens(enclosingNode, comment) {
function handleCommentInEmptyParens(text, enclosingNode, comment) {
if (getNextNonSpaceNonCommentCharacter(text, comment) !== ")") {
return false;
}
// Only add dangling comments to fix the case when no params are present,

@@ -786,23 +790,17 @@ // i.e. a function without any argument.

function findExpressionIndexForComment(expressions, comment) {
let match;
function findExpressionIndexForComment(quasis, comment) {
const startPos = locStart(comment) - 1;
const endPos = locEnd(comment) + 1;
for (let i = 0; i < expressions.length; ++i) {
const range = getExpressionRange(expressions[i]);
if (
(startPos >= range.start && startPos <= range.end) ||
(endPos >= range.start && endPos <= range.end)
) {
match = i;
break;
for (let i = 1; i < quasis.length; ++i) {
if (startPos < getQuasiRange(quasis[i]).start) {
return i - 1;
}
}
return match;
// We haven't found it, it probably means that some of the locations are off.
// Let's just return the first one.
return 0;
}
function getExpressionRange(expr) {
function getQuasiRange(expr) {
if (expr.start !== undefined) {

@@ -809,0 +807,0 @@ // Babylon

"use strict";
function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
var hasStopped = false;
function traverseDocRec(doc) {
var shouldRecurse = true;
if (onEnter) {
hasStopped = hasStopped || onEnter(doc) === false;
if (onEnter(doc) === false) {
shouldRecurse = false;
}
}
if (hasStopped) {
return;
}
if (doc.type === "concat") {
for (var i = 0; i < doc.parts.length; i++) {
traverseDocRec(doc.parts[i]);
}
} else if (doc.type === "if-break") {
if (doc.breakContents) {
traverseDocRec(doc.breakContents);
}
if (doc.flatContents) {
traverseDocRec(doc.flatContents);
}
} else if (doc.type === "group" && doc.expandedStates) {
if (shouldTraverseConditionalGroups) {
doc.expandedStates.forEach(traverseDocRec);
} else {
if (shouldRecurse) {
if (doc.type === "concat") {
for (var i = 0; i < doc.parts.length; i++) {
traverseDocRec(doc.parts[i]);
}
} else if (doc.type === "if-break") {
if (doc.breakContents) {
traverseDocRec(doc.breakContents);
}
if (doc.flatContents) {
traverseDocRec(doc.flatContents);
}
} else if (doc.type === "group" && doc.expandedStates) {
if (shouldTraverseConditionalGroups) {
doc.expandedStates.forEach(traverseDocRec);
} else {
traverseDocRec(doc.contents);
}
} else if (doc.contents) {
traverseDocRec(doc.contents);
}
} else if (doc.contents) {
traverseDocRec(doc.contents);
}

@@ -63,6 +64,10 @@

var result = defaultValue;
var hasStopped = false;
traverseDoc(doc, function(doc) {
var maybeResult = fn(doc);
if (maybeResult !== undefined) {
hasStopped = true;
result = maybeResult;
}
if (hasStopped) {
return false;

@@ -124,2 +129,3 @@ }

function propagateBreaks(doc) {
var alreadyVisited = new Map();
const groupStack = [];

@@ -134,2 +140,6 @@ traverseDoc(

groupStack.push(doc);
if (alreadyVisited.has(doc)) {
return false;
}
alreadyVisited.set(doc, true);
}

@@ -136,0 +146,0 @@ },

@@ -443,3 +443,3 @@ "use strict";

if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
return node.left.type === "ObjectPattern";
return true;
} else if (

@@ -446,0 +446,0 @@ parent.type === "ForStatement" &&

@@ -122,2 +122,5 @@ "use strict";

if (backwards) {
if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
return index - 2;
}
if (

@@ -131,5 +134,2 @@ atIndex === "\n" ||

}
if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
return index - 2;
}
} else {

@@ -136,0 +136,0 @@ if (atIndex === "\r" && text.charAt(index + 1) === "\n") {

@@ -1,11 +0,19 @@

let error = new Error(response.statusText);
// comment
(error: any).response = response
const Labels = {
label1: (
<fbt>
Label 1
</fbt>
),
x;
label2: (
<fbt>
Label 2
</fbt>
),
/* comment */ (error: any).response = response
x;
(error: any).response = response; /* comment */
label3: (
<fbt>
Label 3
</fbt>
),
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc