Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pretty-quick

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pretty-quick - npm Package Compare versions

Comparing version 3.1.3 to 3.1.4

42

bin/pretty-quick.js
#!/usr/bin/env node
'use strict';
'use strict'
const chalk = require('chalk');
const mri = require('mri');
const chalk = require('chalk')
const mri = require('mri')
const prettyQuick = require('..').default;
const prettyQuick = require('..').default

@@ -15,3 +15,3 @@ const args = mri(process.argv.slice(2), {

},
});
})

@@ -26,6 +26,6 @@ const prettyQuickResult = prettyQuick(

)} revision ${chalk.bold(revision)}.`,
);
)
},
onFoundChangedFiles: (changedFiles) => {
onFoundChangedFiles: changedFiles => {
console.log(

@@ -35,11 +35,11 @@ `🎯 Found ${chalk.bold(changedFiles.length)} changed ${

}.`,
);
)
},
onPartiallyStagedFile: (file) => {
console.log(`✗ Found ${chalk.bold('partially')} staged file ${file}.`);
onPartiallyStagedFile: file => {
console.log(`✗ Found ${chalk.bold('partially')} staged file ${file}.`)
},
onWriteFile: (file) => {
console.log(`✍️ Fixing up ${chalk.bold(file)}.`);
onWriteFile: file => {
console.log(`✍️ Fixing up ${chalk.bold(file)}.`)
},

@@ -49,14 +49,14 @@

if (!isFormatted) {
console.log(`⛔️ Check failed: ${chalk.bold(file)}`);
console.log(`⛔️ Check failed: ${chalk.bold(file)}`)
}
},
onExamineFile: (file) => {
console.log(`🔍 Examining ${chalk.bold(file)}.`);
onExamineFile: file => {
console.log(`🔍 Examining ${chalk.bold(file)}.`)
},
}),
);
)
if (prettyQuickResult.success) {
console.log('✅ Everything is awesome!');
console.log('✅ Everything is awesome!')
} else {

@@ -67,3 +67,3 @@ if (prettyQuickResult.errors.indexOf('PARTIALLY_STAGED_FILE') !== -1) {

` ${chalk.bold('Please update stage before committing')}.`,
);
)
}

@@ -73,3 +73,3 @@ if (prettyQuickResult.errors.indexOf('BAIL_ON_WRITE') !== -1) {

'✗ File had to be prettified and prettyQuick was set to bail mode.',
);
)
}

@@ -79,5 +79,5 @@ if (prettyQuickResult.errors.indexOf('CHECK_FAILED') !== -1) {

'✗ Code style issues found in the above file(s). Forgot to run Prettier?',
);
)
}
process.exit(1); // ensure git hooks abort
process.exit(1) // ensure git hooks abort
}

@@ -7,14 +7,8 @@ "use strict";

exports.default = void 0;
var _fs = require("fs");
var _path = require("path");
var _ignore = _interopRequireDefault(require("ignore"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = (directory, filename = '.prettierignore') => {
const file = (0, _path.join)(directory, filename);
if ((0, _fs.existsSync)(file)) {

@@ -25,6 +19,4 @@ const text = (0, _fs.readFileSync)(file, 'utf8');

}
return () => true;
};
exports.default = _default;

@@ -7,9 +7,5 @@ "use strict";

exports.default = void 0;
var _multimatch = _interopRequireDefault(require("multimatch"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const path = require('path');
var _default = pattern => {

@@ -20,3 +16,2 @@ // Match everything if no pattern was given

}
const patterns = Array.isArray(pattern) ? pattern : [pattern];

@@ -27,3 +22,2 @@ return file => (0, _multimatch.default)(path.normalize(file), patterns, {

};
exports.default = _default;

@@ -7,15 +7,8 @@ "use strict";

exports.default = void 0;
var _scms = _interopRequireDefault(require("./scms"));
var _processFiles = _interopRequireDefault(require("./processFiles"));
var _createIgnorer = _interopRequireDefault(require("./createIgnorer"));
var _createMatcher = _interopRequireDefault(require("./createMatcher"));
var _isSupportedExtension = _interopRequireDefault(require("./isSupportedExtension"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = (currentDirectory, {

@@ -41,7 +34,5 @@ config,

const scm = (0, _scms.default)(currentDirectory);
if (!scm) {
throw new Error('Unable to detect a source control manager.');
}
const directory = scm.rootDirectory;

@@ -57,5 +48,3 @@ const revision = since || scm.getSinceRevision(directory, {

const unstagedFiles = staged ? scm.getUnstagedChangedFiles(directory, revision).filter(_isSupportedExtension.default).filter((0, _createMatcher.default)(pattern)).filter(rootIgnorer).filter(cwdIgnorer) : [];
const wasFullyStaged = f => unstagedFiles.indexOf(f) < 0;
onFoundChangedFiles && onFoundChangedFiles(changedFiles);

@@ -68,7 +57,5 @@ const failReasons = new Set();

onWriteFile && onWriteFile(file);
if (bail) {
failReasons.add('BAIL_ON_WRITE');
}
if (staged && restage) {

@@ -85,3 +72,2 @@ if (wasFullyStaged(file)) {

onCheckFile && onCheckFile(file, isFormatted);
if (!isFormatted) {

@@ -98,3 +84,2 @@ failReasons.add('CHECK_FAILED');

};
exports.default = _default;

@@ -7,5 +7,3 @@ "use strict";

exports.default = void 0;
var _prettier = require("prettier");
var _default = resolveConfig => file => Boolean(_prettier.getFileInfo.sync(file, {

@@ -19,3 +17,2 @@ resolveConfig,

}).inferredParser);
exports.default = _default;

@@ -7,13 +7,7 @@ "use strict";

exports.default = void 0;
var _fs = require("fs");
var prettier = _interopRequireWildcard(require("prettier"));
var _path = require("path");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var _default = (directory, files, {

@@ -36,3 +30,2 @@ check,

const input = (0, _fs.readFileSync)(file, 'utf8');
if (check) {

@@ -43,5 +36,3 @@ const isFormatted = prettier.check(input, options);

}
const output = prettier.format(input, options);
if (output !== input) {

@@ -53,3 +44,2 @@ (0, _fs.writeFileSync)(file, output);

};
exports.default = _default;

@@ -6,21 +6,11 @@ "use strict";

});
exports.stageFile = exports.getUnstagedChangedFiles = exports.getChangedFiles = exports.getSinceRevision = exports.detect = exports.name = void 0;
exports.stageFile = exports.name = exports.getUnstagedChangedFiles = exports.getSinceRevision = exports.getChangedFiles = exports.detect = void 0;
var _findUp = _interopRequireDefault(require("find-up"));
var _execa = _interopRequireDefault(require("execa"));
var _path = require("path");
var fs = _interopRequireWildcard(require("fs"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const name = 'git';
exports.name = name;
const name = exports.name = 'git';
const detect = directory => {

@@ -30,3 +20,2 @@ if (fs.existsSync((0, _path.join)(directory, '.git'))) {

}
const gitDirectory = _findUp.default.sync('.git', {

@@ -36,7 +25,5 @@ cwd: directory,

});
if (gitDirectory) {
return (0, _path.dirname)(gitDirectory);
}
const gitWorktreeFile = _findUp.default.sync('.git', {

@@ -46,3 +33,2 @@ cwd: directory,

});
if (gitWorktreeFile) {

@@ -52,11 +38,7 @@ return (0, _path.dirname)(gitWorktreeFile);

};
exports.detect = detect;
const runGit = (directory, args) => _execa.default.sync('git', args, {
cwd: directory
});
const getLines = execaResult => execaResult.stdout.split('\n');
const getSinceRevision = (directory, {

@@ -73,25 +55,17 @@ staged,

}
throw error;
}
};
exports.getSinceRevision = getSinceRevision;
const getChangedFiles = (directory, revision, staged) => {
return [...getLines(runGit(directory, ['diff', '--name-only', staged ? '--cached' : null, '--diff-filter=ACMRTUB', revision].filter(Boolean))), ...(staged ? [] : getLines(runGit(directory, ['ls-files', '--others', '--exclude-standard'])))].filter(Boolean);
};
exports.getChangedFiles = getChangedFiles;
const getUnstagedChangedFiles = directory => {
return getChangedFiles(directory, null, false);
};
exports.getUnstagedChangedFiles = getUnstagedChangedFiles;
const stageFile = (directory, file) => {
runGit(directory, ['add', file]);
};
exports.stageFile = stageFile;

@@ -6,15 +6,8 @@ "use strict";

});
exports.stageFile = exports.getUnstagedChangedFiles = exports.getChangedFiles = exports.getSinceRevision = exports.detect = exports.name = void 0;
exports.stageFile = exports.name = exports.getUnstagedChangedFiles = exports.getSinceRevision = exports.getChangedFiles = exports.detect = void 0;
var _findUp = _interopRequireDefault(require("find-up"));
var _execa = _interopRequireDefault(require("execa"));
var _path = require("path");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const name = 'hg';
exports.name = name;
const name = exports.name = 'hg';
const detect = directory => {

@@ -25,3 +18,2 @@ const hgDirectory = _findUp.default.sync('.hg', {

});
if (hgDirectory) {

@@ -31,11 +23,7 @@ return (0, _path.dirname)(hgDirectory);

};
exports.detect = detect;
const runHg = (directory, args) => _execa.default.sync('hg', args, {
cwd: directory
});
const getLines = execaResult => execaResult.stdout.split('\n');
const getSinceRevision = (directory, {

@@ -47,21 +35,14 @@ branch

};
exports.getSinceRevision = getSinceRevision;
const getChangedFiles = (directory, revision) => {
return [...getLines(runHg(directory, ['status', '-n', '-a', '-m', '--rev', revision]))].filter(Boolean);
};
exports.getChangedFiles = getChangedFiles;
const getUnstagedChangedFiles = () => {
return [];
};
exports.getUnstagedChangedFiles = getUnstagedChangedFiles;
const stageFile = (directory, file) => {
runHg(directory, ['add', file]);
};
exports.stageFile = stageFile;

@@ -7,17 +7,10 @@ "use strict";

exports.default = void 0;
var gitScm = _interopRequireWildcard(require("./git"));
var hgScm = _interopRequireWildcard(require("./hg"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const scms = [gitScm, hgScm];
var _default = directory => {
for (const scm of scms) {
const rootDirectory = scm.detect(directory);
if (rootDirectory) {

@@ -30,3 +23,2 @@ return Object.assign({

};
exports.default = _default;
{
"name": "pretty-quick",
"version": "3.1.3",
"version": "3.1.4",
"description": "Get Pretty Quick",
"repository": "azz/pretty-quick",
"repository": "prettier/pretty-quick",
"author": "Lucas Azzola <@azz>",
"main": "./dist",
"bin": "./bin/pretty-quick.js",
"license": "MIT",

@@ -13,2 +11,9 @@ "engines": {

},
"bin": "./bin/pretty-quick.js",
"main": "./dist",
"files": [
"bin",
"dist",
"img"
],
"keywords": [

@@ -25,46 +30,13 @@ "git",

],
"files": [
"bin",
"dist",
"img"
],
"peerDependencies": {
"prettier": "^2.0.0"
},
"dependencies": {
"chalk": "^3.0.0",
"execa": "^4.0.0",
"chalk": "^4.1.2",
"execa": "^4.1.0",
"find-up": "^4.1.0",
"ignore": "^5.1.4",
"mri": "^1.1.5",
"multimatch": "^4.0.0"
},
"scripts": {
"prepublishOnly": "yarn build",
"pretty-quick": "./bin/pretty-quick.js",
"build": "babel src -d dist --copy-files --no-copy-ignored --ignore '**/__tests__/*.js'",
"test": "jest",
"lint": "eslint . --ignore-path=.gitignore",
"semantic-release": "semantic-release"
},
"husky": {
"hooks": {
"pre-commit": "./bin/pretty-quick.js --staged"
}
},
"prettier": "@azz/prettier-config",
"peerDependencies": {
"prettier": ">=2.0.0"
},
"devDependencies": {
"@azz/prettier-config": "^1.0.0",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.2",
"husky": "^4.2.3",
"jest": "^25.2.3",
"mock-fs": "^4.11.0",
"prettier": "2.0.2"
"ignore": "^5.3.0",
"mri": "^1.2.0",
"multimatch": "^5.0.0"
}
}
}
# `pretty-quick`
[![Travis](https://img.shields.io/travis/com/azz/pretty-quick.svg?style=flat-square)](https://travis-ci.com/github/azz/pretty-quick)
[![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![npm](https://img.shields.io/npm/v/pretty-quick.svg?style=flat-square)](https://npmjs.org/pretty-quick)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
[![GitHub Actions](https://github.com/prettier/pretty-quick/workflows/CI/badge.svg)](https://github.com/prettier/pretty-quick/actions/workflows/ci.yml)
[![Codecov](https://img.shields.io/codecov/c/github/prettier/pretty-quick.svg)](https://codecov.io/gh/prettier/pretty-quick)
[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fun-ts%2Flib-boilerplate%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage)
[![npm](https://img.shields.io/npm/v/pretty-quick.svg)](https://www.npmjs.com/package/pretty-quick)
[![GitHub Release](https://img.shields.io/github/release/prettier/pretty-quick)](https://github.com/prettier/pretty-quick/releases)
[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/changesets/changesets)
> Get Pretty Quick

@@ -22,12 +28,10 @@

With `yarn`:
```shellsession
yarn add --dev prettier pretty-quick
```sh
# npm
npm install -D prettier pretty-quick
```
With `npm`:
```shellsession
npm install --save-dev prettier pretty-quick
```sh
# yarn
yarn add -D prettier pretty-quick
```

@@ -37,29 +41,20 @@

With `yarn`:
```sh
# npx
npx pretty-quick
```shellsession
# yarn
yarn pretty-quick
```
With [`npx`](https://npm.im/npx):
```shellsession
npx -p prettier@latest -p pretty-quick pretty-quick
```
> Note: You can (_should_) change `latest` to a specific version of Prettier.
With `npm`:
1. Add `"pretty-quick": "pretty-quick"` to the `"scripts"` section of `package.json`.
2. `npm run pretty-quick`
## Pre-Commit Hook
You can run `pretty-quick` as a pre-commit hook using [`husky`](https://github.com/typicode/husky).
You can run `pretty-quick` as a `pre-commit` hook using [`simple-git-hooks`](https://github.com/toplenboren/simple-git-hooks).
> For Mercurial have a look at [`husky-hg`](https://github.com/TobiasTimm/husky-hg)
```sh
# npm
npm install -D simple-git-hooks
```shellstream
yarn add --dev husky
# yarn
yarn add -D simple-git-hooks
```

@@ -70,11 +65,7 @@

```json
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
"simple-git-hooks": {
"pre-commit": "pretty-quick --staged"
}
```
![demo](./img/precommit.gif)
## CLI Flags

@@ -98,3 +89,3 @@

Filters the files for the given [minimatch](https://github.com/isaacs/minimatch) pattern.
Filters the files for the given [minimatch](https://github.com/isaacs/minimatch) pattern.
For example `pretty-quick --pattern "**/*.*(js|jsx)"` or `pretty-quick --pattern "**/*.js" --pattern "**/*.jsx"`

@@ -104,3 +95,3 @@

Outputs the name of each file right before it is proccessed. This can be useful if Prettier throws an error and you can't identify which file is causing the problem.
Outputs the name of each file right before it is processed. This can be useful if Prettier throws an error and you can't identify which file is causing the problem.

@@ -123,12 +114,12 @@ ### `--bail`

```
```json
{
"printWidth": 120,
"bracketSpacing": false,
"overrides": [
{
"files": "*.{cmp,page}",
"options": {"parser": "html"}
}
],
"printWidth": 120,
"bracketSpacing": false,
"overrides": [
{
"files": "*.{cmp,page}",
"options": { "parser": "html" }
}
]
}

@@ -135,0 +126,0 @@ ```

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