Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

standard-engine

standard1.5mMIT15.1.0TypeScript support: included

Wrap your standards in a tortilla and cover it in special sauce.

JavaScript Standard Style, check, checker, code, code checker, code linter, code standards, code style, enforce, eslint, hint, jscs, jshint, lint, policy, quality, simple, standard, standard style, style, style checker, style linter, verify

readme

standard-engine Tests CI npm downloads javascript style guide

Overview

Wrap your own eslint rules in a easy-to-use command line tool and/or a JS module.

Install

npm install standard-engine

Who is using standard-engine?

Here is a list of packages using standard-engine. Dive into them for ideas!

Did you make your own? Create a pull request and we will add it to the README!

Usage

Create the files below and fill in your own values for options.js.

index.js

// programmatic usage
const { StandardEngine } = require('standard-engine')
const opts = require('./options.js')
module.exports = new StandardEngine(opts)

cli.js

#!/usr/bin/env node

const opts = require('./options.js')

require('standard-engine').cli(opts)

options.js

const eslint = require('eslint')
const path = require('path')
const pkg = require('./package.json')

/** @type {import('standard-engine').StandardEngineOptions} **/
module.exports = {
  // homepage, version and bugs pulled from package.json
  version: pkg.version,
  homepage: pkg.homepage,
  bugs: pkg.bugs.url,
  eslint, // pass any version of eslint >= 7.0.0
  cmd: 'pocketlint', // should match the "bin" key in your package.json
  tagline: 'Live by your own standards!', // displayed in output --help
  eslintConfig: {
    overrideConfigFile: path.join(__dirname, 'eslintrc.json')
  }
}

Additionally an optional resolveEslintConfig() function can be provided. See below for details.

eslintrc.json

Put all your .eslintrc rules in this file. A good practice is to create an ESLint Shareable Config and extend it, but its not required:

{
  // pretend that the package eslint-config-pocketlint exists!
  "extends": ["pocketlint"]
}

Take a look at eslint-config-standard as an example, or if you want to extend/mutate standard, see eslint-config-semistandard.

Editor Integrations

Integrations and plugins should recognize the standard-engine tag in a package.json file. This allows end users to specify an arbitrary standard-engine compatible linter that the plugin should use. The standard-engine tag can be a string of the package:

{
  "standard-engine": "pocketlint"
}

or an object with a name value of the package:

{
  "standard-engine": {
    "name": "pocketlint"
  }
}

Atom

linter-js-standard-engine is an Atom plugin that supports some of the more popular standard-engine implementations out of the box. It detects them by scanning through the dependencies of the project that you are editing. You can use it with any other implementation through configuration in the projects package.json file.

Engine Features

Extensions

The extensions .js, .jsx, .mjs, and .cjs are linted by default. If you pass directory paths to the standardEngine.lintFiles() method, standard-engine checks the files in those directories that have the given extensions.

For example, when passing the src/ directory and the extensions option is ['.js', '.jsx'], standard-engine will lint *.js and *.jsx files in src/.

You can disable these default ignores by setting the noDefaultExensions option to true.

Ignoring Files

The paths node_modules/**, *.min.js, coverage/**, hidden files/folders (beginning with .), and all patterns in a project's root .gitignore file are automatically ignored.

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

"pocketlint": { // this key should equal the value of cmd in options.js
  "ignore": [
    "**/out/",
    "/lib/select2/",
    "/lib/ckeditor/",
    "tmp.js"
  ]
}

Some files are ignored by default:

const DEFAULT_IGNORE = [
  '*.min.js',
  'coverage/',
  'node_modules/',
  'vendor/'
]

You can disable these default ignores by setting the noDefaultIgnore option to true.

Hiding Warnings

Since standard-engine uses eslint under-the-hood, you can hide warnings as you normally would if you used eslint directly.

Disable all rules on a specific line:

file = 'I know what I am doing' // eslint-disable-line

Or, disable only the "no-use-before-define" rule:

file = 'I know what I am doing' // eslint-disable-line no-use-before-define

Or, disable the "no-use-before-define" rule for multiple lines:

/*eslint-disable no-use-before-define */
// offending code here...
// offending code here...
// offending code here...
/*eslint-enable no-use-before-define */

Defining Globals in a project's package.json

standard-engine will also look in a project's package.json and respect any global variables defined like so:

{
  "pocketlint": { // this key should equal the value of cmd in options.js
    "globals": [ // can be a string or an array of strings
      "myVar1",
      "myVar2"
    ]
  }
}

You may use global as an alias for globals (just don't specify both).

Loading ESLint plugins in a project's package.json

Additional ESLint plugins can be specified like so:

{
  "pocketlint": { // this key should equal the value of cmd in options.js
    "plugins": [ // can be a string or an array of strings
      "flowtype"
    ]
  }
}

You may use plugin as an alias for plugins (just don't specify both). Plugins must be installed (example: npm install eslint-plugin-flowtype or globally: npm install eslint-plugin-flowtype -g).

Loading additional environments in a project's package.json

Additional environments can be specified like so:

{
  "pocketlint": { // this key should equal the value of cmd in options.js
    "envs": [ "browser", "mocha" ]
  }
}

envs can be a string, an array of strings, or an object. In the latter case the keys are used as the environment name, but falsy values mean the environment is not actually loaded. You cannot unload environments by setting a falsy value.

You may use env as an alias for envs (just don't specify both).

Custom JS parsers for bleeding-edge ES6 or ES7 support?

standard-engine supports custom JS parsers. To use a custom parser, install it from npm (example: npm install babel-eslint) and add this to your package.json:

{
  "pocketlint": { // this key should equal the value of cmd in your options.js
    "parser": "babel-eslint"
  }
}

If you're using your custom linter globally (you installed it with -g), then you also need to install babel-eslint globally with npm install babel-eslint -g.

Custom options

You can provide a resolveEslintConfig() function in the options.js exports:

const eslint = require('eslint')
const path = require('path')
const pkg = require('./package.json')

module.exports = {
  // homepage, version and bugs pulled from package.json
  version: pkg.version,
  homepage: pkg.homepage,
  bugs: pkg.bugs.url,
  eslint, // pass any version of eslint >= 7.0.0
  cmd: 'pocketlint', // should match the "bin" key in your package.json
  tagline: 'Live by your own standards!', // displayed in output --help
  eslintConfig: {
    overrideConfigFile: path.join(__dirname, 'eslintrc.json')
  },
  resolveEslintConfig: function (eslintConfig, opts, packageOpts, rootDir) {
    // provide implementation here, then return the eslintConfig object (or a new one)
    return eslintConfig
  }
}

This function is called with the current ESLint config (the options passed to the ESLint constructor), the options object (opts), any options extracted from the project's package.json (packageOpts), and the directory that contained that package.json file (rootDir, equivalent to opts.cwd if no file was found).

Modify and return eslintConfig, or return a new object with the eslint config to be used.

API Usage

async engine.lintText(text, [opts])

Lint the provided source text to enforce your defined style. An opts object may be provided:

{
  // unique to lintText
  filename: '',         // path of file containing the text being linted

  // common to lintText and lintFiles
  cwd: '',              // current working directory (default: process.cwd())
  fix: false,           // automatically fix problems
  extensions: [],       // file extensions to lint (has sane defaults)
  globals: [],          // custom global variables to declare
  plugins: [],          // custom eslint plugins
  envs: [],             // custom eslint environment
  parser: '',           // custom js parser (e.g. babel-eslint)
  usePackageJson: true, // use options from nearest package.json?
  useGitIgnore: true    // use file ignore patterns from .gitignore?
}

All options are optional, though some ESLint plugins require the filename option.

Additional options may be loaded from a package.json if it's found for the current working directory. See below for further details.

Returns a Promise resolving to the results or rejected with an Error.

The results object will contain the following properties:

const results = {
  results: [
    {
      filePath: '',
      messages: [
        { ruleId: '', message: '', line: 0, column: 0 }
      ],
      errorCount: 0,
      warningCount: 0,
      output: '' // fixed source code (only present with {fix: true} option)
    }
  ],
  errorCount: 0,
  warningCount: 0
}

async engine.lintFiles(files, [opts])

Lint the provided files globs. An opts object may be provided:

{
  // unique to lintFiles
  ignore: [],           // file globs to ignore (has sane defaults)

  // common to lintText and lintFiles
  cwd: '',              // current working directory (default: process.cwd())
  fix: false,           // automatically fix problems
  extensions: [],       // file extensions to lint (has sane defaults)
  globals: [],          // custom global variables to declare
  plugins: [],          // custom eslint plugins
  envs: [],             // custom eslint environment
  parser: '',           // custom js parser (e.g. babel-eslint)
  usePackageJson: true, // use options from nearest package.json?
  useGitIgnore: true    // use file ignore patterns from .gitignore?
}

Additional options may be loaded from a package.json if it's found for the current working directory. See below for further details.

Both ignore and files patterns are resolved relative to the current working directory.

Returns a Promise resolving to the results or rejected with an Error (same as above).

NOTE: There is no synchronous version of engine.lintFiles().

Full set of opts

This is the full set of options accepted by the above APIs. Not all options make sense for each API, for example ignore is not used with lintText(), and filename is not used with lintFiles().

{
  ignore: [],   // file patterns to ignore (has sane defaults)
  cwd: '',      // current working directory (default: process.cwd())
  filename: '', // path of the file containing the text being linted (optional)
  fix: false,   // automatically fix problems
  globals: [],  // custom global variables to declare
  plugins: [],  // custom eslint plugins
  envs: [],     // custom eslint environment
  parser: ''    // custom js parser (e.g. babel-eslint)
}

The following aliases are available:

{
  global: [],  // custom global variables to declare
  plugin: [],  // custom eslint plugins
  env: [],     // custom eslint environment
}

Note that globals, plugins and envs take preference.

The parser option takes preference over any parser setting in the project's package.json.

changelog

standard-engine Change Log

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

15.1.0 2022-11-23

  • Enhancement: Added --ignore option support

15.0.0 2022-04-20

  • In addition to breaking changes and other in 15.0.0-0, only some dependency updates

    15.0.0-0 2021-11-30

  • BREAKING CHANGE: To avoid confusion with ESLint exports and types, our Linter class has been renamed to StandardEngine and cli() now takes a standardEngine key instead of a linter key if a custom engine wants to be provided. #275

  • BREAKING CHANGE: Removed use of ESLint's deprecated CLIEngine API. This affects the eslintConfig option to our StandardEngine (formerly called Linter) constructor. #275
  • BREAKING CHANGE: Print additional label on warnings (to separate them from errors) b7c1e17
  • BREAKING CHANGE: Drop support for Node 10.x. Now require ESM-compatible Node.js versions: ^12.20.0 || ^14.13.1 || >=16.0.0 #252
  • BREAKING CHANGE: the parseOpts option to the StandardEngine (formerly called Linter) constructor has been replaced with a new resolveEslintConfig one
  • Change: make --verbose the default #232

14.0.1 2020-08-31

  • Missing release notes

14.0.0 2020-08-29

  • Missing release notes

13.0.0 2020-08-27

  • Missing release notes

12.1.1 2020-05-21

  • Enhancement: Allow passing in a custom linter to cli

12.0.1 2020-04-30

  • Enhancements: Add ts-standard to README linters list
  • Fixes: Bump deglob & minimist dependencies

12.0.0 2019-08-19

  • BREAKING CHANGE: Remove bundle.js from the list of default ignored files
  • BREAKING CHANGE: Ignore patterns from .git/info/exclude in addition to .gitignore
  • Enhancement: Update deglob to 4.x

11.0.1 2019-07-12

  • Missing release notes

11.0.0 2019-07-11

  • Missing release notes

10.0.0 2018-08-30

  • Missing release notes

9.0.0 2018-05-15

  • Missing release notes

8.0.1 2018-03-02

  • Missing release notes

8.0.0 2018-02-18

  • Missing release notes

7.2.0 2017-11-07

  • New Feature: noDefaultIgnore option to can now be used to turn off default ignores.

7.1.0 - 2017-06-21

  • engine.lintText and engine.lintTextSync do not take into account the package.json configuration settings. These now do not behave differently depending on the current working directory. See https://github.com/Flet/standard-engine/pull/166

7.0.0 - 2017-04-04

  • BREAKING: rename the synchronous lintText method to lintTextSync
  • Add an asyncronous lintText method (that just calls lintTextSync internally)

This effectively undoes the breaking change introduced in 6.0.0, making it safe to upgrade from standard-engine 5.x to 7.x without introducing any breaking changes.

Related issues:

6.0.0 - 2017-02-20

  • BREAKING: make lintText into a sync method

Before: standardEngine.lintText(text, [opts], callback)

After: results = standardEngine.lintText(text, [opts])

If an error occurs, an exception is thrown. Otherwise, a results object is returned.

5.4.0 - 2017-02-08

  • Replace find-root and pkg-config by pkg-conf
  • Support parseOpts() option
  • Improve help message
    • add missing ignored files
    • add note about .gitignore files
  • Prevent package.json parser option from overriding explicit option

5.3.0 - 2016-11-23

  • Resolve ignore options in standard-engine, not deglob

5.2.0 - 2016-11-22

  • Support filename option in lintText()
  • Update dependencies

5.1.1 - 2016-10-11

  • Fix crash when 'stdin' and 'fix' options are used on code with no errors

5.1.0 - 2016-08-19

  • Add ESLint cache option

5.0.3 - 2016-08-18

  • Remove unneeded xtend, defaults, multiline dependencies
  • Re-order help commands

5.0.2 - 2016-08-12

  • Clarify it's only some problems that get fixed

5.0.1 - 2016-08-12

  • Only recommend --fix when fixable rules are present

5.0.0 - 2016-08-10

  • BREAKING: Remove formatter support (replaced by ESLint's --fix)
  • BREAKING: Drop Node 0.12 and 0.10 support (because of ESLint 3)
  • Add {fix: true} option to lintFiles and lintText API
  • Support auto-fixing source text from --stdin

4.1.3 - 2016-08-07

  • Update deps, improve tests

4.1.2 - 2016-07-26

  • Add "Try standard --fix message" when errors are present

4.1.1 - 2016-07-13

  • Remove --format from help when there is only an error string

4.1.0 - 2016-07-13

  • Add --fix option (uses eslint's --fix)
  • Drop Node 0.12 and 0.10 CI testing (because of ESLint 3)
  • Update deps

4.0.5 - 2016-07-12

  • Update deps

4.0.4 - 2016-05-25

  • Fix install warning due to cross-spawn-async

4.0.3 - 2016-05-25

  • Add back node v0.10 support

4.0.2 - 2016-05-16

  • Fix truncated output on Node v6

4.0.1 - 2016-04-28

  • Do not use .eslintignore files

4.0.0 - 2016-04-24

  • Remove --rules option

3.3.1 - 2016-02-23

  • Update dependencies

3.3.0 - 2016-02-18

  • Support passing cwd option in Linter constructor

3.2.4 - 2016-02-07

  • Fix tests

3.2.3 - 2016-02-07

  • Fix tests

3.2.2 - 2016-02-06

  • Fix tests

3.2.1 - 2016-02-05

  • Fix tests

3.2.0 - 2016-02-05

  • Add --plugin option
  • Add --rules option
  • Add --env option

3.1.1 - 2016-02-03

  • Replace deprecated win-spawn dev dependency with cross-spawn-async.

3.1.0 - 2016-02-03

  • Support opts.format string option to print message about how to install formatter.

3.0.1 - 2016-02-03

  • Remove dezalgo dependency

3.0.0 - 2016-01-29

  • Breaking: eslint is now a mandatory option in your options.js

2.2.4 - 2015-12-02

  • Fixed: Log warning messages when no errors are present

2.2.3 - 2015-11-17

  • remove prepended "Use" from tagline output

2.2.2 - 2015-11-06

  • update eslint to 1.9.0

2.2.1 - 2015-11-01

  • lock down eslint to 1.7.3 to fix space-in-parens eslint bug
  • avoid mutating the eslint config object that's passed in (fixes #9)

2.2.0 - 2015-09-18

  • update eslint to 1.5.x

2.1.1 - 2015-09-18

  • fix fetching of eslint with older npm versions

2.1.0 - 2015-06-16

  • set custom parser in non-hacky way (fixes #12)

2.0.7 - 2105-08-28

  • ignore vendor/ folder by default

2.0.6 - 2105-08-07

  • readme changes

2.0.5 - 2015-08-05

standard is now using standard-engine Cool!

  • All standard maintainers have been added to standard-engine.
  • Instead of synchronizing, we will now just update standard-engine directly to add features/fixes!

    Other things

  • BREAKING CHANGE standard-engine is now using eslint 1.0!

    • Be sure your eslint configuration works with eslint 1.0 before upgrading.
  • Other dependencies were bumped in order to facilitate the update

  • The code was also meticulously synchronized with standard
    • CLI output is now identical
    • A few code style updates were made for consistency

1.11.1 - 2015-07-30

  • fix standard issues in cmd.js

1.11.0 - 2015-07-30

  • Merged standard 5.0.0-8
  • New feature: ability to specify globals via --global flag and global option

1.10.2 - 2015-07-17

  • Merged standard 4.5.4 changes: switch to using deglob

1.10.1 - 2015-07-06

  • Removed a stray console.log

1.10.0 - 2015-07-06

  • Fix bug in custom parser option to make it work.
  • Merged from standard: New "globals" option can be set in package.json to define an array of global variables.

1.9.0 - 2015-06-29

  • merge from latest standard 4.4.1 including:
    • Fixes to the gitignore feature
    • added parser parameter
    • Lots of repos added to clone.js test and made a lot faster! @feross is the best :)

1.8.1 - 2015-06-17

  • Fix NPE error when opts._config is undefined. Thanks @wombleton

1.8.0 - 2015-06-16

  • Fix gitignore support for Windows.
  • Refactor to use pkg-config.
  • Update to newer version of eslint to allow extending multiple eslint-config files.

1.7.0 - 2015-05-30

Merged from standard

  • NEW FEATURE: Add proper .gitignore support

1.6.0 - 2015-05-29

Merged from standard

  • NEW FEATURE: Custom Parsers can now be specified in package.json

    To use a custom parser, install it from npm (example: npm install babel-eslint) and add this to your package.json:

    {
    "yourcmdname": {
      "parser": "babel-eslint"
    }
    }

    (Thanks @feross)

1.5.0 - 2015-05-25

Merged from standard

  • NEW FEATURE: pass in a formatter to get --format as an option for the command line! Thanks @ricardofbarros!

1.4.3 - 2015-05-25

Merged from standard

  • Speed increased significantly by reverting a default ignore pattern change.

1.4.2 - 2015-05-22

  • Fix bug where absolute paths to files was not working.

1.4.1 - 2015-04-21

Merged from standard

  • Fix bug in parseOpts to ensure original options are not modified
  • Upgrade to eslint 0.21.0

1.4.0 - 2015-04-21

Merged from standard

  • Disable .gitignore support for now.

1.3.1 - 2015-04-14

Merged from standard

  • Fix crash on absolute filesystem path

1.3.0 - 2015-04-14

  • moved some files back to their original locations to make merging from standard easier.

Merged from standard

  • Ignore linting for all files in .gitignore.
  • Removed /git/** exclusion as its redundant.
  • Output errors to stdout instead of stderr.
  • Updated eslint-plugin-react and tape dependencies.
  • Additional tests.