Package detail

healthier

KidkArolis895MIT7.0.0

An opinionated code linter – a friendly companion to prettier

JavaScript Standard Style, bikeshed, check, checker

readme

Healthier

npm downloads Join the chat at https://gitter.im/healthier-linter/community

An opinionated code style agnostic linter – a friendly companion to Prettier.

Why?

Prettier is a powerful code formatter. However, linting your code in addition to formatting can reveal a number of code quality issues and potential bugs.

Healthier is a code linter that you should run in addition to formatting your code with Prettier to find the most common issues with your code. It saves you having to install or configure any of the 100s of ESLint rules by hand or hand pick the plugins to use.

Healthier delegates all of the code quality related decisions to Standard. The community has put a lot of effort into that project and Healthier simply helps you get the benefits of it when using a different code style, such as Prettier.

The goal is to avoid creating yet another opinionated set of rules and instead reuse well established existing options in an easy to use workflow.

Because Healthier is only concerned with code quality linting, it means you can use any code formatter, such as Prettier or any of it's variants like prettierx or prettier-standard.

Why not just use Prettier with Standard?

Standard is not only checking your code quality, but also your code style. Unfortunately Prettier and Standard code styles are incompatible in subtle ways. This means you can't use the two tools together. Healthier completely lets go off Standard's code style in favor of Prettier's and combines the best aspects of each tool:

  1. Use Prettier to format your JavaScript, CSS and other files.
  2. Use Healthier to lint your JavaScript for code quality issues.
  3. Benefit from Healthier's Standard inspired zero config approach – no glob patterns necessary, no ESLint plugins, no manual rule configuration.

You can create a .prettierrc file in your project with the following content to bring your code style pretty close to Standard:

{
  "semi": false,
  "singleQuote": true,
  "jsxSingleQuote": true,
  "printWidth": 120
}

Usage

npm install healthier

Then run in your project:

$ npx healthier

/App.js
  4:1  error  'useState' is not defined  no-undef

✖ 1 problem (1 error, 0 warnings)

Note: npx prefix can be omitted if you have ./node_modules/.bin in your PATH.

Recommended setup

The recommended setup is to install Prettier and Healthier and configure them in package.json:

{
  "name": "my-cool-package",
  "scripts": {
    "test": "ava && healthier && prettier --check '**/*.{js,json,css}'",
    "format": "prettier --write '**/*.{js,json,css,yml}'"
  },
  "devDependencies": {
    "healthier": "*",
    "prettier": "*"
  }
}

When you use Prettier and Healthier code editor extensions, you will get both auto formatting and linting working in tandem. And in CI, npm test will warn you about missed code quality issues or if something was not formatted with Prettier.

Editor plugins

Rules

Healthier is based on standard-engine which in itself is based on eslint. Healthier combines the following ESLint config rules and plugins:

  • eslint-config-standard
  • eslint-config-standard-jsx
  • eslint-config-standard-react
  • eslint-config-prettier

Which in turn depend on the following plugins:

  • eslint-plugin-import
  • eslint-plugin-node
  • eslint-plugin-promise
  • eslint-plugin-react
  • eslint-plugin-react-hooks

That's a lot of things you don't need to install!

Review the full list of standard rules here https://github.com/standard/standard/blob/master/RULES.md.

Configuration

Healthier can be configured in package.json in healthier field.

Custom Parser

Using a custom parser is sometimes necessary when using futuristic JS features. To use one, install it from npm (e.g. npm install @babel/eslint-parser) and configure it in your package.json:

{
  "healthier": {
    "parser": "@babel/eslint-parser"
  }
}

Automatic formatter

There exist certain standard rules that prettier has no opinion about. For example the lines-between-class-members rule is turned on by standard to improve readability by enforcing lines between class members. However prettier allows class members without lines in between. In these cases you can get healthier to fix those issues for you:

You can use healthier --fix to fix such issues automatically.

Ignoring files

Just like in Standard, The paths node_modules/**, *.min.js, bundle.js, coverage/**, hidden files/folders (beginning with .), and all patterns in a project's root .gitignore file are automatically excluded when looking for .js files to check. Additionally everything in .prettierignore is also ignored, since if you're not formatting something, you probably don't want to lint it.

Sometimes you need to ignore additional folders or specific minified files. To do that, add a healthier.ignore property to package.json:

"healthier": {
  "ignore": [
    "**/out/",
    "/lib/select2/",
    "/lib/ckeditor/",
    "tmp.js"
  ]
}

Globals

If you want to allow certain globals, configure like so:

{
  "healthier": {
    "globals": ["describe", "it"]
  }
}

TypeScript

To use TypeScript, you need to run Healthier with @typescript-eslint/parser as the parser, @typescript-eslint/eslint-plugin as a plugin, and tell Healthier to lint *.ts files (since it doesn't by default).

npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin

Then run:

$ healthier --parser @typescript-eslint/parser --plugin @typescript-eslint *.ts

Or, add this to package.json:

{
  "healthier": {
    "parser": "@typescript-eslint/parser",
    "plugins": ["@typescript-eslint"]
  }
}

With that in package.json, you can run:

healthier *.ts

ESLint Environments

ESLint has an environment feature that defines what global variables are allowed to be used. For a list of what globals are available for these environments, check the globals npm module.

For example, to support mocha global variables in test files, add this to the top of the test files:

/* eslint-env mocha */

Or, run:

$ healthier --env mocha

Extending ESLint Rules

Healthier allows extending ESLint rules by creating .eslintrc file. For full documentation see Configuring ESLint.

For example, to make snake_case allowed in your code, set the following in your .eslintrc:

{
  "rules": {
    "camelcase": 0
  }
}

You can also use this method to extend other configs and plugins, for example, to use standard-react and jsx-a11y when developing a React application, install the following:

npm i -D eslint-config-standard-react eslint-plugin-jsx-a11y

And put this in your .eslintrc:

{
  "extends": ["plugin:jsx-a11y/strict", "standard-react"]
}

Ejecting

To stop using Healthier and switch to pure ESLint while preserving most of Healthier's functionality, follow this guide.

changelog

Changelog

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

7.0.0

  • Upgrade all dependencies
  • Remove React rule customisations - healthier now uses standard-react rule configuration. Most notably - this enables the react-hooks/exhaustive-deps warnings. Note: react/prop-types is still turned off.

6.5.0

Dependency maintenance:

  • Upgrade all dependencies, fix npm audit

6.4.0

Dependency maintenance:

  • Upgrade all dependencies, fix npm audit

6.3.0

Dependency maintenance:

  • Upgrade all dependencies, fix npm audit
  • Install a missing resolve dependency
  • Remove np and healthier dev dependencies

6.2.1

  • Remove the no longer needed eslint-plugin-standard dep

6.2.0

  • Update README and cli help text to reference the new @babel/eslint-parser
  • Remove the unused babel-eslint dep

6.1.0

  • Upgrade all dependencies

6.0.2

  • Fix an issue with eslint-plugin-node being replaced with eslint-plugin-n in standard

6.0.1

  • Fix an issue with eslint-config-prettier usage

6.0.0

  • Upgrade all dependencies

5.0.1

  • Log the "healthier: Friendly linter" message to stdout, instead of stderr

5.0.0

  • Upgrade all dependencies, upgrade to standard-engine 15 (pre release) and the latest eslint API

4.0.0

  • Upgrade all dependencies

3.3.0

  • Upgrade all dependencies

3.2.0

  • Auto detect if React is used and turn on eslint-config-standard-react and eslint-plugin-react-hooks rules, but turn off react/prop-types as that's really up to the project.

3.1.0

  • Re-add --fix flag since some rules in standard (e.g. lines-between-class-members) are fixable, but not enforced by prettier. Such is the price for trying to bridge the two tools.
  • Upgrade to eslint 6.3.0 and latest standard, the one that fixes no-unused-vars false positives
  • Upgrade all other dependencies

3.0.2

3.0.0

  • Upgrade to standard@14 (previously standard@12)
  • Upgrade all other dependencies

2.0.0

Huge thanks to @sheerun for all the feedback on V1. This version comes with many improvements.

tl;dr

  • Remove --fix
  • Remove --init
  • Remove --verbose
  • Remove dependency on prettier making healthier formatter agnostic
  • Use eslint output and add --format
  • Allow extending with .eslintrc
  • Support more environments, typescript, flow, react, vue
  • Merge .prettierignore into default ignores

Long form:

  • The --fix flag has been removed to make Healthier more focused on code quality linting and be unopinionated about your choice of formatter. This avoids installing 2 extra dependencies – prettier and eslint-plugin-prettier, which means installation is faster, but also the checks run faster since we avoid double parsing each file with eslint and then prettier. This makes Healthier a more friendlier and less confusing tool when using it with prettierx, prettier-standard or any other formatter. This will also avoid any version conflicts between the Prettier used in your project and the Prettier that was used in Healthier to lint the style. Inline with this, the --init flag has been removed too, because it really is not in scope for Healthier to dictate stype preference when Healthier is a pure style agnostic linter.
  • The output is now formatted using eslint's formatters and accepts any eslint --format option. This means a nicer looking default output, but also better integration with existing tooling since eslint format is more widely used. Incidentally, this helps to improve SublimeLinter-contrib-healthier plugin greatly. It's now a little bit faster and more comprehensive, it displays syntax errors and internal eslint errors, such as information about missing plugins.
  • It's possible to extend eslint rules used by creating .eslintrc (or any other form that eslint supports). Previously, it was already possible to pass --global, --env and --plugin via command line argument or package.json field in healthier key. But now it's also possible to use .eslintrc which allows granular rule overrides or using plugin rules such as react-native or react-a11y without having to eject from the tool.
  • All of the eslint-config-prettier rules are being imported to ensure that styling related rules are turned off even when you're using typescript, vue, and other supported environments.
  • .prettierignore is now taken into account as part of the ignores, if you're not formatting that code, you probably also don't want to be linting it.
  • --verbose flag was removed since the output now includes the rule names depending on the --format used

1.1.2

  • Fix dependencies, explicitly depend on minimist and get-stdin

1.1.1

  • No changes to code, only updated README.

1.1.0

  • Feature Add --init flag that creates an opinionated, standard inspired .prettierrc file.

1.0.0

Combine the best parts of eslint, prettier and standard into a single package that can format and lint your code.