New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

prettier-eslint

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-eslint - npm Package Compare versions

Comparing version

to
8.0.0

192

dist/index.js
'use strict';
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /* eslint no-console:0, global-require:0, import/no-dynamic-require:0 */
/* eslint complexity: [1, 7] */
/**
* Formats the text with prettier and then eslint based on the given options
* @param {String} options.filePath - the path of the file being formatted
* can be used in leu of `eslintConfig` (eslint will be used to find the
* relevant config for the file). Will also be used to load the `text` if
* `text` is not provided.
* @param {String} options.text - the text (JavaScript code) to format
* @param {String} options.eslintPath - the path to the eslint module to use.
* Will default to require.resolve('eslint')
* @param {String} options.prettierPath - the path to the prettier module.
* Will default to require.resovlve('prettierPath')
* @param {Object} options.eslintConfig - the config to use for formatting
* with ESLint.
* @param {Object} options.prettierOptions - the options to pass for
* formatting with `prettier`. If not provided, prettier-eslint will attempt
* to create the options based on the eslintConfig
* @param {Object} options.fallbackPrettierOptions - the options to pass for
* formatting with `prettier` if the given option is not inferrable from the
* eslintConfig.
* @param {String} options.logLevel - the level for the logs
* (error, warn, info, debug, trace)
* @param {Boolean} options.prettierLast - Run Prettier Last
* @return {String} - the formatted string
*/
var format = function () {
var _ref = _asyncToGenerator(function* (options) {
var _options$logLevel = options.logLevel,
logLevel = _options$logLevel === undefined ? getDefaultLogLevel() : _options$logLevel;
logger.setLevel(logLevel);
logger.trace('called format with options:', (0, _prettyFormat2.default)(options));
var filePath = options.filePath,
_options$text = options.text,
text = _options$text === undefined ? getTextFromFilePath(filePath) : _options$text,
_options$eslintPath = options.eslintPath,
eslintPath = _options$eslintPath === undefined ? getModulePath(filePath, 'eslint') : _options$eslintPath,
_options$prettierPath = options.prettierPath,
prettierPath = _options$prettierPath === undefined ? getModulePath(filePath, 'prettier') : _options$prettierPath,
prettierLast = options.prettierLast,
fallbackPrettierOptions = options.fallbackPrettierOptions;
var eslintConfig = (0, _lodash2.default)({}, options.eslintConfig, getConfig(filePath, eslintPath));
var prettierOptions = (0, _lodash2.default)({}, (yield getPrettierConfig(filePath, prettierPath)), options.prettierOptions);
var formattingOptions = (0, _utils.getOptionsForFormatting)(eslintConfig, prettierOptions, fallbackPrettierOptions);
logger.debug('inferred options:', (0, _prettyFormat2.default)({
filePath,
text,
eslintPath,
prettierPath,
eslintConfig: formattingOptions.eslint,
prettierOptions: formattingOptions.prettier,
logLevel,
prettierLast
}));
var isCss = /\.(css|less|scss)$/.test(filePath);
var isJson = /\.json$/.test(filePath);
var isTypeScript = /\.tsx?$/.test(filePath);
if (isCss) {
formattingOptions.prettier.parser = 'postcss';
} else if (isJson) {
formattingOptions.prettier.parser = 'json';
formattingOptions.prettier.trailingComma = 'none';
} else if (isTypeScript) {
formattingOptions.prettier.parser = 'typescript';
// XXX: It seems babylon is getting a TypeScript plugin.
// Should that be used instead?
formattingOptions.eslint.parser = 'typescript-eslint-parser';
}
var prettify = createPrettify(formattingOptions.prettier, prettierPath);
if (isCss || isJson) {
return prettify(text, filePath);
}
var eslintFix = createEslintFix(formattingOptions.eslint, eslintPath);
if (prettierLast) {
return prettify(eslintFix(text, filePath));
}
return eslintFix(prettify(text), filePath);
});
return function format(_x) {
return _ref.apply(this, arguments);
};
}();
var _fs = require('fs');

@@ -134,6 +41,2 @@

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } /* eslint no-console:0, global-require:0, import/no-dynamic-require:0 */
/* eslint complexity: [1, 7] */
var logger = (0, _loglevelColoredLevelPrefix2.default)({ prefix: 'prettier-eslint' });

@@ -144,2 +47,91 @@

/**
* Formats the text with prettier and then eslint based on the given options
* @param {String} options.filePath - the path of the file being formatted
* can be used in leu of `eslintConfig` (eslint will be used to find the
* relevant config for the file). Will also be used to load the `text` if
* `text` is not provided.
* @param {String} options.text - the text (JavaScript code) to format
* @param {String} options.eslintPath - the path to the eslint module to use.
* Will default to require.resolve('eslint')
* @param {String} options.prettierPath - the path to the prettier module.
* Will default to require.resovlve('prettierPath')
* @param {Object} options.eslintConfig - the config to use for formatting
* with ESLint.
* @param {Object} options.prettierOptions - the options to pass for
* formatting with `prettier`. If not provided, prettier-eslint will attempt
* to create the options based on the eslintConfig
* @param {Object} options.fallbackPrettierOptions - the options to pass for
* formatting with `prettier` if the given option is not inferrable from the
* eslintConfig.
* @param {String} options.logLevel - the level for the logs
* (error, warn, info, debug, trace)
* @param {Boolean} options.prettierLast - Run Prettier Last
* @return {String} - the formatted string
*/
function format(options) {
var _options$logLevel = options.logLevel,
logLevel = _options$logLevel === undefined ? getDefaultLogLevel() : _options$logLevel;
logger.setLevel(logLevel);
logger.trace('called format with options:', (0, _prettyFormat2.default)(options));
var filePath = options.filePath,
_options$text = options.text,
text = _options$text === undefined ? getTextFromFilePath(filePath) : _options$text,
_options$eslintPath = options.eslintPath,
eslintPath = _options$eslintPath === undefined ? getModulePath(filePath, 'eslint') : _options$eslintPath,
_options$prettierPath = options.prettierPath,
prettierPath = _options$prettierPath === undefined ? getModulePath(filePath, 'prettier') : _options$prettierPath,
prettierLast = options.prettierLast,
fallbackPrettierOptions = options.fallbackPrettierOptions;
var eslintConfig = (0, _lodash2.default)({}, options.eslintConfig, getConfig(filePath, eslintPath));
var prettierOptions = (0, _lodash2.default)({}, getPrettierConfig(filePath, prettierPath), options.prettierOptions);
var formattingOptions = (0, _utils.getOptionsForFormatting)(eslintConfig, prettierOptions, fallbackPrettierOptions);
logger.debug('inferred options:', (0, _prettyFormat2.default)({
filePath,
text,
eslintPath,
prettierPath,
eslintConfig: formattingOptions.eslint,
prettierOptions: formattingOptions.prettier,
logLevel,
prettierLast
}));
var isCss = /\.(css|less|scss)$/.test(filePath);
var isJson = /\.json$/.test(filePath);
var isTypeScript = /\.tsx?$/.test(filePath);
if (isCss) {
formattingOptions.prettier.parser = 'postcss';
} else if (isJson) {
formattingOptions.prettier.parser = 'json';
formattingOptions.prettier.trailingComma = 'none';
} else if (isTypeScript) {
formattingOptions.prettier.parser = 'typescript';
// XXX: It seems babylon is getting a TypeScript plugin.
// Should that be used instead?
formattingOptions.eslint.parser = 'typescript-eslint-parser';
}
var prettify = createPrettify(formattingOptions.prettier, prettierPath);
if (isCss || isJson) {
return prettify(text, filePath);
}
var eslintFix = createEslintFix(formattingOptions.eslint, eslintPath);
if (prettierLast) {
return prettify(eslintFix(text, filePath));
}
return eslintFix(prettify(text), filePath);
}
function createPrettify(formatOptions, prettierPath) {

@@ -243,3 +235,3 @@ return function prettify(text) {

var prettier = requireModule(prettierPath, 'prettier');
return prettier.resolveConfig(filePath);
return prettier.resolveConfig.sync(filePath);
}

@@ -246,0 +238,0 @@

{
"name": "prettier-eslint",
"version": "7.1.0",
"version": "8.0.0",
"description": "Formats your JavaScript using prettier followed by eslint --fix",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -23,2 +23,4 @@ # prettier-eslint

<a href="https://app.codesponsor.io/link/PKGFLnhDiFvsUA5P4kAXfiPs/prettier/prettier-eslint" rel="nofollow"><img src="https://app.codesponsor.io/embed/PKGFLnhDiFvsUA5P4kAXfiPs/prettier/prettier-eslint.svg" style="width: 888px; height: 68px;" alt="Sponsor" /></a>
## The problem

@@ -25,0 +27,0 @@