Gathering detailed insights and metrics for gg-standard-engine
Gathering detailed insights and metrics for gg-standard-engine
Gathering detailed insights and metrics for gg-standard-engine
Gathering detailed insights and metrics for gg-standard-engine
npm install gg-standard-engine
Typescript
Module System
Node Version
NPM Version
69.6
Supply Chain
96
Quality
80.9
Maintenance
100
Vulnerability
98.6
License
Total Downloads
9,024
Last Day
3
Last Week
31
Last Month
65
Last Year
591
Minified
Minified + Gzipped
Latest Version
1.1.4
Package Id
gg-standard-engine@1.1.4
Size
12.16 kB
NPM Version
4.2.0
Node Version
7.9.0
Cumulative downloads
Total Downloads
Last day
0%
3
Compared to previous day
Last week
1,450%
31
Compared to previous week
Last month
16.1%
65
Compared to previous month
Last year
-44.9%
591
Compared to previous year
Wrap your own eslint rules in a easy-to-use command line tool and/or a JS module.
npm install standard-engine
standard-engine
?Here is a list of packages using standard-engine
. Dive into them for ideas!
standard
with semicolons sprinkled on top.Did you make your own? Create a pull request and we will add it to the README!
Create the files below and fill in your own values for options.js
.
index.js
1// programmatic usage 2var Linter = require('standard-engine').linter 3var opts = require('./options.js') 4module.exports = new Linter(opts)
cli.js
1#!/usr/bin/env node 2 3var opts = require('../options.js') 4require('standard-engine').cli(opts)
options.js
1var eslint = require('eslint') 2var path = require('path') 3var pkg = require('./package.json') 4 5module.exports = { 6 // homepage, version and bugs pulled from package.json 7 version: pkg.version, 8 homepage: pkg.homepage, 9 bugs: pkg.bugs.url, 10 eslint: eslint, // pass any version of eslint >= 1.0.0 11 cmd: 'pocketlint', // should match the "bin" key in your package.json 12 tagline: 'Live by your own standards!', // displayed in output --help 13 eslintConfig: { 14 configFile: path.join(__dirname, 'eslintrc.json') 15 }, 16 cwd: '' // current working directory, passed to eslint 17}
Additionally an optional parseOpts()
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:
1{ 2 // pretend that the package eslint-config-pocketlint exists! 3 "extends": ["pocketlint"] 4}
Take a look at eslint-config-standard as an example, or if you want to extend/mutate standard
, see eslint-config-semistandard.
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 ignored.
Sometimes you need to ignore additional folders or specific minfied files. To do that, add
a ignore
property to package.json
:
1"pocketlint": { // this key should equal the value of cmd in options.js 2 "ignore": [ 3 "**/out/", 4 "/lib/select2/", 5 "/lib/ckeditor/", 6 "tmp.js" 7 ] 8}
Since standard-engine
uses eslint
under-the-hood, you can
hide warnings as you normally would if you used eslint
directly.
To get verbose output (so you can find the particular rule name to ignore), run:
1$ pocketlint --verbose 2Error: Live by your own standards! 3 routes/error.js:20:36: 'file' was used before it was defined. (no-use-before-define)
Disable all rules on a specific line:
1file = 'I know what I am doing' // eslint-disable-line
Or, disable only the "no-use-before-define"
rule:
1file = 'I know what I am doing' // eslint-disable-line no-use-before-define
Or, disable the "no-use-before-define"
rule for multiple lines:
1/*eslint-disable no-use-before-define */ 2// offending code here... 3// offending code here... 4// offending code here... 5/*eslint-enable no-use-before-define */
package.json
standard-engine
will also look in a project's package.json
and respect any global variables defined like so:
1{ 2 "pocketlint": { // this key should equal the value of cmd in options.js 3 "globals": [ // can be a string or an array of strings 4 "myVar1", 5 "myVar2" 6 ] 7 } 8}
You may use global
as an alias for globals
(just don't specify both).
package.json
Additional ESLint plugins can be specified like so:
1{ 2 "pocketlint": { // this key should equal the value of cmd in options.js 3 "plugins": [ // can be a string or an array of strings 4 "flowtype" 5 ] 6 } 7}
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
).
package.json
Additional environments can be specified like so:
1{ 2 "pocketlint": { // this key should equal the value of cmd in options.js 3 "envs": [ "browser", "mocha" ] 4 } 5}
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).
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
:
1{ 2 "pocketlint": { // this key should equal the value of cmd in your options.js 3 "parser": "babel-eslint" 4 } 5}
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
.
You can provide a parseOpts()
function in the options.js
exports:
1var eslint = require('eslint') 2var path = require('path') 3var pkg = require('./package.json') 4 5module.exports = { 6 // homepage, version and bugs pulled from package.json 7 version: pkg.version, 8 homepage: pkg.homepage, 9 bugs: pkg.bugs.url, 10 eslint: eslint, // pass any version of eslint >= 1.0.0 11 cmd: 'pocketlint', // should match the "bin" key in your package.json 12 tagline: 'Live by your own standards!', // displayed in output --help 13 eslintConfig: { 14 configFile: path.join(__dirname, 'eslintrc.json') 15 }, 16 parseOpts (opts, packageOpts, rootDir) { 17 // provide implementation here, then return the opts object (or a new one) 18 return opts 19 } 20}
This function is called with the current 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 opts
, or return a new object with the options that are to be used.
The following options are provided in the opts
object, and must be on the returned object:
ignore
: array of file globs to ignorecwd
: string, the current working directoryfix
: boolean, whether to automatically fix problemseslintConfig
: object, the options passed to ESLint's CLIEngine
engine.lintText(text, [opts], callback)
Lint the provided source text
to enforce your defined style. An opts
object may
be provided:
1{ 2 cwd: '', // current working directory (default: process.cwd()) 3 filename: '', // path of the file containing the text being linted (optional, though some eslint plugins require it) 4 fix: false, // automatically fix problems 5 globals: [], // custom global variables to declare 6 plugins: [], // custom eslint plugins 7 envs: [], // custom eslint environment 8 parser: '' // custom js parser (e.g. babel-eslint) 9}
Additional options may be loaded from a package.json
if it's found for the current working directory. See below for further details.
The callback
will be called with an Error
and results
object.
The results
object will contain the following properties:
1var results = { 2 results: [ 3 { 4 filePath: '', 5 messages: [ 6 { ruleId: '', message: '', line: 0, column: 0 } 7 ], 8 errorCount: 0, 9 warningCount: 0, 10 output: '' // fixed source code (only present with {fix: true} option) 11 } 12 ], 13 errorCount: 0, 14 warningCount: 0 15}
results = engine.lintTextSync(text, [opts])
Synchronous version of engine.lintText()
. If an error occurs, an exception is
thrown. Otherwise, a results
object is returned.
engine.lintFiles(files, [opts], callback)
Lint the provided files
globs. An opts
object may be provided:
1{ 2 ignore: [], // file globs to ignore (has sane defaults) 3 cwd: '', // current working directory (default: process.cwd()) 4 fix: false, // automatically fix problems 5 globals: [], // custom global variables to declare 6 plugins: [], // custom eslint plugins 7 envs: [], // custom eslint environment 8 parser: '' // custom js parser (e.g. babel-eslint) 9}
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
globs are resolved relative to the current working directory.
The callback
will be called with an Error
and results
object (same as above).
NOTE: There is no synchronous version of engine.lintFiles()
.
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()
.
1{ 2 ignore: [], // file globs to ignore (has sane defaults) 3 cwd: '', // current working directory (default: process.cwd()) 4 filename: '', // path of the file containing the text being linted (optional) 5 fix: false, // automatically fix problems 6 globals: [], // custom global variables to declare 7 plugins: [], // custom eslint plugins 8 envs: [], // custom eslint environment 9 parser: '' // custom js parser (e.g. babel-eslint) 10}
The following aliases are available:
1{ 2 global: [], // custom global variables to declare 3 plugin: [], // custom eslint plugins 4 env: [], // custom eslint environment 5}
Note that globals
, plugins
and envs
take preference.
The parser
option takes preference over any parser
setting in the project's package.json
.
No vulnerabilities found.
No security vulnerabilities found.