Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
prettier-eslint-cli
Advanced tools
The prettier-eslint-cli package is a command-line interface that combines the functionality of Prettier and ESLint. It allows you to format your code using Prettier and then apply ESLint fixes, ensuring that your code adheres to both formatting and linting rules.
Format and Lint Files
This command formats all JavaScript files in the 'src' directory and its subdirectories using Prettier, and then applies ESLint fixes to them.
prettier-eslint --write "src/**/*.js"
Use Custom Configuration
This command allows you to specify custom configuration files for both Prettier and ESLint. It formats and fixes the files according to the rules defined in '.prettierrc' and '.eslintrc'.
prettier-eslint --write "src/**/*.js" --prettier-config .prettierrc --eslint-config .eslintrc
Check Mode
This command checks which files in the 'src' directory and its subdirectories would be changed by Prettier and ESLint, without actually modifying the files.
prettier-eslint --list-different "src/**/*.js"
ESLint is a tool for identifying and fixing problems in JavaScript code. It is highly configurable and can be extended with plugins. Unlike prettier-eslint-cli, ESLint focuses solely on linting and does not handle code formatting.
Prettier is an opinionated code formatter that supports many languages. It enforces a consistent style by parsing your code and re-printing it with its own rules. Unlike prettier-eslint-cli, Prettier does not handle linting.
eslint-plugin-prettier is an ESLint plugin that runs Prettier as an ESLint rule. This allows you to use Prettier's formatting as part of your ESLint configuration. However, it does not provide a CLI for running both tools together like prettier-eslint-cli does.
pretty-quick is a tool that runs Prettier on your changed files. It is useful for pre-commit hooks to ensure that only formatted code is committed. Unlike prettier-eslint-cli, it does not integrate with ESLint.
CLI for prettier-eslint
You have a bunch of files that you want to format using prettier-eslint
.
But prettier-eslint
can only operate on strings.
This is a CLI that allows you to use
prettier-eslint
on one or multiple files. prettier-eslint-cli
forwards on the filePath
and other relevant options to prettier-eslint
which identifies the applicable ESLint
config for each file and uses that to determine the options for prettier
and eslint --fix
.
This module is distributed via npm which is bundled with node and should
be installed (with yarn
) as one of your project's devDependencies
:
yarn add --dev prettier-eslint-cli
If you're still using the
npm
client:npm install --save-dev prettier-eslint-cli
Typically you'll use this in your npm scripts (or package scripts):
{
"scripts": {
"format": "prettier-eslint \"src/**/*.js\""
}
}
This will format all .js
files in the src
directory. The argument you pass to the CLI
is a glob and you can pass as many as you wish. You can also pass options.
Vim users can add the following to their .vimrc:
autocmd FileType javascript set formatprg=prettier-eslint\ --stdin
This makes prettier-eslint-cli power the gq command for automatic formatting without any plugins. You can also add the following to your .vimrc to run prettier-eslint-cli when .js files are saved:
autocmd BufWritePre *.js :normal gggqG
prettier-eslint --help
Usage: prettier-eslint <globs>... [--option-1 option-1-value --option-2]
Prefix an option with "no-" to set it to false, such as --no-semi to
disable semicolons and --no-eslint-ignore to disable default ignores.
Options:
-h, --help Show help [boolean]
--version Show version number [boolean]
--write Edit the file in-place (beware!)
[boolean] [default: false]
--stdin Read input via stdin [boolean] [default: false]
--stdin-filepath Path to the file to pretend that stdin comes from.
--eslint-ignore Only format matching files even if they are not
ignored by .eslintignore. (can use --no-eslint-ignore
to disable this) [boolean] [default: true]
--prettier-ignore Only format matching files even if they are not
ignored by .prettierignore. (can use
--no-prettier-ignore to disable this)
[boolean] [default: true]
--list-different Print filenames of files that are different from
Prettier + Eslint formatting.
[boolean] [default: false]
--include-dot-files Include files that start with a dot in the search.
[boolean] [default: false]
--eslint-path The path to the eslint module to use
[default: "./node_modules/eslint"]
--eslint-config-path Path to the eslint config to use for eslint --fix
--prettier-path The path to the prettier module to use [default: "./node_modules/prettier"]
--config Path to the prettier config
--ignore pattern(s) you wish to ignore (can be used multiple
times and includes **/node_modules/** automatically)
--log-level, -l The log level to use
[choices: "silent", "error", "warn", "info", "debug", "trace"] [default:
"warn"]
--prettier-last Run prettier last [boolean] [default: false]
--use-tabs Indent lines with tabs instead of spaces. [boolean]
--print-width Specify the length of line that the printer will wrap
on. [number]
--tab-width Specify the number of spaces per indentation-level.
[number]
--trailing-comma Print trailing commas wherever possible.
Valid options:
- "none" - no trailing commas
- "es5" - trailing commas where valid in ES5
(objects, arrays, etc)
- "all" - trailing commas wherever possible (function
arguments) [string] [choices: "none", "es5", "all"]
--bracket-spacing Print spaces between brackets in object literals.
Can use --no-bracket-spacing for "false" to disable
it.
Valid options:
- true - Example: { foo: bar }
- false - Example: {foo: bar} [boolean]
--jsx-bracket-same-line Put the > of a multi-line JSX element at the end of
the last line instead of being alone on the next line
[boolean]
--parser Specify which parser to use. [string]
--semi Print semicolons at the ends of statements.
Can use --no-semi.
Valid options:
- true - add a semicolon at the end of every
statement
- false - only add semicolons at the beginning of
lines that may introduce ASI failures [boolean]
--single-quote Use single quotes instead of double quotes. [boolean]
Any number of globs you wish to use to match the files you wish to format. By default, glob
will ignore
**/node_modules/**
unless the glob you provide
includes the string node_modules
.
By default prettier-eslint
will simply log the formatted version to the terminal. If you want to overwrite the file
itself (a common use-case) then add --write
. You should quote your globs, otherwise your terminal will expand the glob before it gets to prettier-eslint
(which can have unexpected results):
{
"scripts": {
"format": "prettier-eslint --write \"src/**/*.js\""
}
}
NOTE: It is recommended that you keep your files under source control and committed before running
prettier-eslint --write
as it will overwrite your files!
Instead of printing the formatted version of the files to the terminal, prettier-eslint
will log the name of the files that are different from the expected formatting. This can be usefull when using prettier-eslint
in a version control system hook to inform the committer which files need to be formatted.
Accept input via stdin
. For example:
echo "var foo = 'bar'" | prettier-eslint --stdin
# results in: "var foo = 'bar';" (depending on your eslint config)
Forwarded as the eslintPath
option to prettier-eslint
Resolve eslint config file, parse and forward config object as the eslintConfig
option to
prettier-eslint
Forwarded as the prettierPath
option to prettier-eslint
Forwarded as logLevel
option to prettier-eslint
Disables application of .eslintignore
to the files resolved from the glob. By
default, prettier-eslint-cli
will exclude files if they are matched by a
.eslintignore
. Add this flag to disable this behavior.
Note: You can also set the
LOG_LEVEL
environment variable to control logging inprettier-eslint
By default, prettier-eslint-cli
will run prettier
first, then eslint --fix
. This is great if
you want to use prettier
, but override some of the styles you don't like using eslint --fix
.
An alternative approach is to use different tools for different concerns. If you provide the
argument --prettier-last
, it will run eslint --fix
first, then prettier
. This allows you to
use eslint
to look for bugs and/or bad practices, and use prettier
to enforce code style.
prettier
optionsprettier-eslint-cli
also supports the same command line options as prettier
.
For example: prettier-eslint --trailing-comma es5
Refer to the prettier-eslint docs for documentation on these options
Any linter that support ESLint CLIEngine interface can be integrate with prettier-eslint
prettier-eslint-cli
Thanks goes to these people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT
FAQs
CLI for prettier-eslint
The npm package prettier-eslint-cli receives a total of 297,273 weekly downloads. As such, prettier-eslint-cli popularity was classified as popular.
We found that prettier-eslint-cli demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.ย It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.