What is standard?
The 'standard' npm package is a JavaScript style guide, linter, and formatter all in one. It enforces a consistent coding style without the need for configuration, making it easier to maintain code quality across projects.
What are standard's main functionalities?
Linting
Linting is the process of running a program that will analyze code for potential errors. The 'standard' package provides a zero-configuration linter that checks for style and programming errors.
npx standard
Auto-fixing
The 'standard' package can automatically fix some of the issues it finds in your code. This feature helps in maintaining code quality by automatically correcting common style and formatting issues.
npx standard --fix
Integration with Editors
The 'standard' package can be integrated with various code editors like VSCode, Sublime Text, and Atom. This allows for real-time linting and auto-fixing as you write code.
/* Example for VSCode */
{
"editor.formatOnSave": true,
"javascript.validate.enable": false,
"standard.enable": true
}
Other packages similar to standard
eslint
ESLint is a highly configurable linter for JavaScript and JSX. Unlike 'standard', which comes with a predefined set of rules, ESLint allows you to define your own rules or extend from popular style guides like Airbnb or Google.
prettier
Prettier is an opinionated code formatter that supports many languages. It focuses on code formatting rather than linting. While 'standard' includes both linting and formatting, Prettier is often used in conjunction with ESLint for a more comprehensive solution.
xo
XO is a JavaScript linter with great defaults and minimal configuration. It is similar to 'standard' in that it aims to provide a zero-config experience, but it also allows for some customization and extends ESLint under the hood.
standard
Enforce code style standards
install
npm install standard
usage
The easiest way to use standard
is to install it globally as a Node command line
program. To do so, simply run the following command in your terminal (flag -g
installs
standard
globally on your system, omit it if you want to install in the current working
directory):
npm install standard -g
After you've done that you should be able to use the standard
program. The simplest use
case would be checking the style of all JavaScript files in the current working directory:
$ standard
Error: Code style check failed:
/Users/feross/code/webtorrent/lib/torrent.js:950:11: Expected '===' and instead saw '=='.
what you might do if you're clever
- Add it to
package.json
{
"name": "my-cool-package",
"devDependencies": {
"standard": "*"
},
"scripts": {
"test": "standard && node my-normal-tests.js"
}
}
- Check style automatically when you run
npm test
$ npm test
Error: Code style check failed:
/Users/feross/code/webtorrent/lib/torrent.js:950:11: Expected '===' and instead saw '=='.
- Never give style feedback on a pull request again!
license
MIT. Copyright (c) Feross Aboukhadijeh.
[11.0.0] - 2018-02-18
This release has no new rules, but it does update to the latest version of eslint
,
version 4, which has some significant changes to existing rules. Most updates make
the indentation rules more strict.
Thankfully, most users will just need to run standard --fix
to update code to be
compliant.
New features
-
Update eslint
from ~3.19.0 to ~4.18.0.
- The
indent
rule is more strict. - The
padded-blocks
rule is more strict. - The
space-before-function-paren
rule is more strict. - The
no-multi-spaces
rule is more strict. - Minor improvements to:
no-extra-parens
,no-unexpected-multiline
,no-regex-spaces
, andspace-unary-ops
-
Update eslint-plugin-import
from ~2.2.0
to ~2.8.0
- Updated for eslint 4.0 compatibility.
- Various small bug fixes included related to
import/*
rules.
-
Update eslint-plugin-node
from ~4.2.2
to ~6.0.0
- The
no-deprecated-api
rule is updated with Node.js 8 support and improved
Node 6 support.
-
Upodate eslint-plugin-promise
from ~3.5.0
to ~3.6.0
.
-
Update eslint-plugin-react
from ~6.10.0
to ~7.6.1
- Fix
jsx-indent
crash - Fix
jsx-indent
indentation calculation with nested JSX. - Fix
jsx-no-undef
will not check the global scope by default. - Fix
jsx-curly-spacing
newline with object literals bug. - Fix
jsx-curly-spacing
schema incompatibility with ESLint 4.2.0. - Fix alignment bug in
jsx-indent
.
Changed rules
- Relax rule: Don't mark Rails Asset Pipeline comments (comments that start with
//=
)
as errors. (spaced-comment) #918
š Huge thanks to @Flet for putting together most of this
release!