standard-engine
Advanced tools
Comparing version 14.0.1 to 15.0.0-0
156
bin/cmd.js
#!/usr/bin/env node | ||
module.exports = Cli | ||
const minimist = require('minimist') | ||
const getStdin = require('get-stdin') | ||
function Cli (opts) { | ||
const Linter = require('../').linter | ||
const standard = opts.linter || new Linter(opts) | ||
/** | ||
* @typedef StandardCliOptions | ||
* @property {import('../').StandardEngine} [standardEngine] | ||
* @property {string} [cmd] | ||
* @property {string} [tagline] | ||
* @property {string} [homepage] | ||
* @property {string} [bugs] | ||
*/ | ||
opts = Object.assign({ | ||
/** | ||
* @param {Omit<import('../').StandardEngineOptions, 'cmd'> & StandardCliOptions} rawOpts | ||
* @returns {void} | ||
*/ | ||
function cli (rawOpts) { | ||
const opts = { | ||
cmd: 'standard-engine', | ||
tagline: 'JavaScript Custom Style', | ||
version: '0.0.0' | ||
}, opts) | ||
version: '0.0.0', | ||
...rawOpts | ||
} | ||
const standard = rawOpts.standardEngine || new (require('../').StandardEngine)(opts) | ||
const argv = minimist(process.argv.slice(2), { | ||
@@ -23,4 +34,3 @@ alias: { | ||
env: 'envs', | ||
help: 'h', | ||
verbose: 'v' | ||
help: 'h' | ||
}, | ||
@@ -31,3 +41,2 @@ boolean: [ | ||
'stdin', | ||
'verbose', | ||
'version' | ||
@@ -66,3 +75,2 @@ ], | ||
--fix Automatically fix problems | ||
-v, --verbose Show rule names for errors (to ignore specific rules) | ||
--version Show current version | ||
@@ -98,20 +106,49 @@ -h, --help Show usage information | ||
let stdinText | ||
const outputFixed = argv.stdin && argv.fix | ||
if (argv.stdin) { | ||
getStdin().then(function (text) { | ||
stdinText = text | ||
standard.lintText(text, lintOpts, onResult) | ||
}) | ||
} else { | ||
standard.lintFiles(argv._, lintOpts, onResult) | ||
/** | ||
* Print lint errors to stdout -- this is expected output from `standard-engine`. | ||
* Note: When fixing code from stdin (`standard --stdin --fix`), the transformed | ||
* code is printed to stdout, so print lint errors to stderr in this case. | ||
* @type {typeof console.log} | ||
*/ | ||
const log = (...args) => { | ||
if (outputFixed) { | ||
args[0] = opts.cmd + ': ' + args[0] | ||
console.error.apply(console, args) | ||
} else { | ||
console.log.apply(console, args) | ||
} | ||
} | ||
function onResult (err, result) { | ||
if (err) return onError(err) | ||
Promise.resolve(argv.stdin ? getStdin() : '').then(async stdinText => { | ||
/** @type {import('eslint').ESLint.LintResult[]} */ | ||
let results | ||
if (argv.stdin && argv.fix) { | ||
if (result.results[0].output) { | ||
try { | ||
results = argv.stdin | ||
? await standard.lintText(stdinText, lintOpts) | ||
: await standard.lintFiles(argv._, lintOpts) | ||
} catch (err) { | ||
console.error(opts.cmd + ': Unexpected linter output:\n') | ||
if (err instanceof Error) { | ||
console.error(err.stack || err.message) | ||
} else { | ||
console.error(err) | ||
} | ||
console.error( | ||
'\nIf you think this is a bug in `%s`, open an issue: %s', | ||
opts.cmd, | ||
opts.bugs | ||
) | ||
process.exitCode = 1 | ||
return | ||
} | ||
if (!results) throw new Error('expected a results') | ||
if (outputFixed) { | ||
if (results[0] && results[0].output) { | ||
// Code contained fixable errors, so print the fixed code | ||
process.stdout.write(result.results[0].output) | ||
process.stdout.write(results[0].output) | ||
} else { | ||
@@ -123,3 +160,6 @@ // Code did not contain fixable errors, so print original code | ||
if (!result.errorCount && !result.warningCount) { | ||
const hasErrors = results.some(item => item.errorCount !== 0) | ||
const hasWarnings = results.some(item => item.warningCount !== 0) | ||
if (!hasErrors && !hasWarnings) { | ||
process.exitCode = 0 | ||
@@ -131,10 +171,15 @@ return | ||
if (hasWarnings) { | ||
const homepage = opts.homepage != null ? ` (${opts.homepage})` : '' | ||
console.error( | ||
'%s: %s', | ||
opts.cmd, | ||
`Some warnings are present which will be errors in the next version${homepage}` | ||
) | ||
} | ||
// Are any fixable rules present? | ||
const isFixable = result.results.some(function (result) { | ||
return result.messages.some(function (message) { | ||
return !!message.fix | ||
}) | ||
}) | ||
const hasFixable = results.some(item => item.messages.some(message => !!message.fix)) | ||
if (isFixable) { | ||
if (hasFixable) { | ||
console.error( | ||
@@ -147,42 +192,21 @@ '%s: %s', | ||
result.results.forEach(function (result) { | ||
result.messages.forEach(function (message) { | ||
for (const item of results) { | ||
for (const message of item.messages) { | ||
log( | ||
' %s:%d:%d: %s%s', | ||
result.filePath, | ||
' %s:%d:%d: %s%s%s', | ||
item.filePath, | ||
message.line || 0, | ||
message.column || 0, | ||
message.message, | ||
argv.verbose ? ' (' + message.ruleId + ')' : '' | ||
' (' + message.ruleId + ')', | ||
message.severity === 1 ? ' (warning)' : '' | ||
) | ||
}) | ||
}) | ||
} | ||
} | ||
process.exitCode = result.errorCount ? 1 : 0 | ||
} | ||
process.exitCode = hasErrors ? 1 : 0 | ||
}) | ||
.catch(err => process.nextTick(() => { throw err })) | ||
} | ||
function onError (err) { | ||
console.error(opts.cmd + ': Unexpected linter output:\n') | ||
console.error(err.stack || err.message || err) | ||
console.error( | ||
'\nIf you think this is a bug in `%s`, open an issue: %s', | ||
opts.cmd, | ||
opts.bugs | ||
) | ||
process.exitCode = 1 | ||
} | ||
/** | ||
* Print lint errors to stdout -- this is expected output from `standard-engine`. | ||
* Note: When fixing code from stdin (`standard --stdin --fix`), the transformed | ||
* code is printed to stdout, so print lint errors to stderr in this case. | ||
*/ | ||
function log () { | ||
if (argv.stdin && argv.fix) { | ||
arguments[0] = opts.cmd + ': ' + arguments[0] | ||
console.error.apply(console, arguments) | ||
} else { | ||
console.log.apply(console, arguments) | ||
} | ||
} | ||
} | ||
module.exports = cli |
@@ -5,2 +5,63 @@ # standard-engine Change Log | ||
## 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 | ||
@@ -7,0 +68,0 @@ |
304
index.js
/*! standard-engine. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */ | ||
module.exports.cli = require('./bin/cmd') | ||
module.exports.linter = Linter | ||
const os = require('os') | ||
const path = require('path') | ||
const pkgConf = require('pkg-conf') | ||
const fs = require('fs') | ||
const CACHE_HOME = require('xdg-basedir').cache || os.tmpdir() | ||
const DEFAULT_EXTENSIONS = [ | ||
'.js', | ||
'.jsx', | ||
'.mjs', | ||
'.cjs' | ||
] | ||
const { resolveEslintConfig } = require('./lib/resolve-eslint-config') | ||
const DEFAULT_IGNORE = [ | ||
'**/*.min.js', | ||
'coverage/**', | ||
'node_modules/**', | ||
'vendor/**' | ||
] | ||
/** @typedef {import('eslint').ESLint.Options} EslintOptions */ | ||
/** @typedef {Omit<import('./lib/resolve-eslint-config').ResolveOptions, 'cmd'|'cwd'>} BaseLintOptions */ | ||
function Linter (opts) { | ||
if (!(this instanceof Linter)) return new Linter(opts) | ||
if (!opts) opts = {} | ||
if (!opts.cmd) throw new Error('opts.cmd option is required') | ||
if (!opts.eslint) throw new Error('opts.eslint option is required') | ||
this.cmd = opts.cmd | ||
this.eslint = opts.eslint | ||
this.cwd = opts.cwd || process.cwd() | ||
this.customParseOpts = opts.parseOpts | ||
const m = opts.version && opts.version.match(/^(\d+)\./) | ||
const majorVersion = (m && m[1]) || '0' | ||
// Example cache location: ~/.cache/standard/v12/ | ||
const cacheLocation = path.join(CACHE_HOME, this.cmd, `v${majorVersion}/`) | ||
this.eslintConfig = Object.assign({ | ||
cache: true, | ||
cacheLocation, | ||
envs: [], | ||
fix: false, | ||
globals: [], | ||
plugins: [], | ||
ignorePattern: [], | ||
extensions: [], | ||
useEslintrc: false | ||
}, opts.eslintConfig) | ||
if (this.eslintConfig.configFile != null) { | ||
this.eslintConfig.resolvePluginsRelativeTo = | ||
path.dirname(this.eslintConfig.configFile) | ||
} | ||
} | ||
/** | ||
* Lint text to enforce JavaScript Style. | ||
* | ||
* @param {string} text file text to lint | ||
* @param {Object=} opts options object | ||
* @param {boolean=} opts.fix automatically fix problems | ||
* @param {Array.<string>=} opts.globals custom global variables to declare | ||
* @param {Array.<string>=} opts.plugins custom eslint plugins | ||
* @param {Array.<string>=} opts.envs custom eslint environment | ||
* @param {string=} opts.parser custom js parser (e.g. babel-eslint) | ||
* @param {string=} opts.filename path of file containing the text being linted | ||
* @param {boolean=} opts.usePackageJson use options from nearest package.json? (default: true) | ||
* @typedef StandardEngineOptions | ||
* @property {string} cmd | ||
* @property {import('eslint')} eslint | ||
* @property {string} [cwd] | ||
* @property {EslintOptions} [eslintConfig] | ||
* @property {import('./lib/resolve-eslint-config').CustomEslintConfigResolver} [resolveEslintConfig] | ||
* @property {string} [version] | ||
*/ | ||
Linter.prototype.lintTextSync = function (text, opts) { | ||
opts = this.parseOpts(opts) | ||
return new this.eslint.CLIEngine(opts.eslintConfig).executeOnText(text, opts.filename) | ||
} | ||
Linter.prototype.lintText = function (text, opts, cb) { | ||
if (typeof opts === 'function') return this.lintText(text, null, opts) | ||
let result | ||
try { | ||
result = this.lintTextSync(text, opts) | ||
} catch (err) { | ||
return process.nextTick(cb, err) | ||
} | ||
process.nextTick(cb, null, result) | ||
} | ||
class StandardEngine { | ||
/** | ||
* @param {StandardEngineOptions} opts | ||
*/ | ||
constructor (opts) { | ||
if (!opts || !opts.cmd) throw new Error('opts.cmd option is required') | ||
if (!opts.eslint) throw new Error('opts.eslint option is required') | ||
/** | ||
* Lint files to enforce JavaScript Style. | ||
* | ||
* @param {Array.<string>} files file globs to lint | ||
* @param {Object=} opts options object | ||
* @param {Array.<string>=} opts.ignore file globs to ignore (has sane defaults) | ||
* @param {string=} opts.cwd current working directory (default: process.cwd()) | ||
* @param {boolean=} opts.fix automatically fix problems | ||
* @param {Array.<string>=} opts.globals custom global variables to declare | ||
* @param {Array.<string>=} opts.plugins custom eslint plugins | ||
* @param {Array.<string>=} opts.envs custom eslint environment | ||
* @param {string=} opts.parser custom js parser (e.g. babel-eslint) | ||
* @param {boolean=} opts.usePackageJson use options from nearest package.json? (default: true) | ||
* @param {function(Error, Object)} cb callback | ||
*/ | ||
Linter.prototype.lintFiles = function (files, opts, cb) { | ||
const self = this | ||
if (typeof opts === 'function') return self.lintFiles(files, null, opts) | ||
opts = self.parseOpts(opts) | ||
/** @type {string} */ | ||
this.cmd = opts.cmd | ||
/** @type {import('eslint')} */ | ||
this.eslint = opts.eslint | ||
/** @type {string} */ | ||
this.cwd = opts.cwd || process.cwd() | ||
this.customEslintConfigResolver = opts.resolveEslintConfig | ||
if (typeof files === 'string') files = [files] | ||
if (files.length === 0) files = ['.'] | ||
const m = opts.version && opts.version.match(/^(\d+)\./) | ||
const majorVersion = (m && m[1]) || '0' | ||
let result | ||
try { | ||
result = new self.eslint.CLIEngine(opts.eslintConfig).executeOnFiles(files) | ||
} catch (err) { | ||
return cb(err) | ||
} | ||
// Example cache location: ~/.cache/standard/v12/ | ||
const cacheLocation = path.join(CACHE_HOME, this.cmd, `v${majorVersion}/`) | ||
if (opts.fix) { | ||
self.eslint.CLIEngine.outputFixes(result) | ||
} | ||
/** @type {EslintOptions} */ | ||
this.eslintConfig = { | ||
cache: true, | ||
cacheLocation, | ||
fix: false, | ||
extensions: [], | ||
useEslintrc: false, | ||
...(opts.eslintConfig || {}) | ||
} | ||
return cb(null, result) | ||
} | ||
Linter.prototype.parseOpts = function (opts) { | ||
const self = this | ||
opts = { | ||
eslintConfig: { ...self.eslintConfig }, | ||
usePackageJson: true, | ||
useGitIgnore: true, | ||
gitIgnoreFile: ['.gitignore', '.git/info/exclude'], | ||
cwd: self.cwd, | ||
fix: false, | ||
ignore: [], | ||
extensions: [], | ||
...opts | ||
if (this.eslintConfig.overrideConfigFile != null) { | ||
this.eslintConfig.resolvePluginsRelativeTo = path.dirname( | ||
this.eslintConfig.overrideConfigFile | ||
) | ||
} | ||
} | ||
if (!Array.isArray(opts.gitIgnoreFile)) { | ||
opts.gitIgnoreFile = [opts.gitIgnoreFile] | ||
/** | ||
* Lint text to enforce JavaScript Style. | ||
* | ||
* @param {string} text file text to lint | ||
* @param {Omit<BaseLintOptions, 'ignore'|'noDefaultIgnore'> & { filename?: string }} [opts] base options + path of file containing the text being linted | ||
* @returns {Promise<import('eslint').ESLint.LintResult[]>} | ||
*/ | ||
async lintText (text, { filename: filePath, ...opts } = {}) { | ||
const eslintConfig = this.resolveEslintConfig(opts) | ||
const engine = new this.eslint.ESLint(eslintConfig) | ||
return engine.lintText(text, { filePath }) | ||
} | ||
opts.eslintConfig.cwd = opts.cwd | ||
opts.eslintConfig.fix = opts.fix | ||
/** | ||
* Lint files to enforce JavaScript Style. | ||
* | ||
* @param {Array<string>} files file globs to lint | ||
* @param {BaseLintOptions & { cwd?: string }} [opts] base options + file globs to ignore (has sane defaults) + current working directory (default: process.cwd()) | ||
* @returns {Promise<import('eslint').ESLint.LintResult[]>} | ||
*/ | ||
async lintFiles (files, opts) { | ||
const eslintConfig = this.resolveEslintConfig(opts) | ||
let packageOpts = {} | ||
let rootPath = null | ||
if (typeof files === 'string') files = [files] | ||
if (files.length === 0) files = ['.'] | ||
if (opts.usePackageJson || opts.useGitIgnore) { | ||
packageOpts = pkgConf.sync(self.cmd, { cwd: opts.cwd }) | ||
const packageJsonPath = pkgConf.filepath(packageOpts) | ||
if (packageJsonPath) rootPath = path.dirname(packageJsonPath) | ||
} | ||
const eslintInstance = new this.eslint.ESLint(eslintConfig) | ||
const result = await eslintInstance.lintFiles(files) | ||
if (!opts.usePackageJson) packageOpts = {} | ||
addIgnore(packageOpts.ignore) | ||
addIgnore(opts.ignore) | ||
if (!packageOpts.noDefaultIgnore && !opts.noDefaultIgnore) { | ||
addIgnore(DEFAULT_IGNORE) | ||
} | ||
addExtensions(packageOpts.extensions) | ||
addExtensions(opts.extensions) | ||
if (!packageOpts.noDefaultExtensions && !opts.noDefaultExtensions) { | ||
addExtensions(DEFAULT_EXTENSIONS) | ||
} | ||
if (opts.useGitIgnore && rootPath) { | ||
opts.gitIgnoreFile | ||
.map(gitIgnoreFile => { | ||
try { | ||
return fs.readFileSync(path.join(rootPath, gitIgnoreFile), 'utf8') | ||
} catch (err) { | ||
return null | ||
} | ||
}) | ||
.filter(Boolean) | ||
.forEach(gitignore => { | ||
addIgnore(gitignore.split(/\r?\n/)) | ||
}) | ||
} | ||
addGlobals(packageOpts.globals || packageOpts.global) | ||
addGlobals(opts.globals || opts.global) | ||
addPlugins(packageOpts.plugins || packageOpts.plugin) | ||
addPlugins(opts.plugins || opts.plugin) | ||
addEnvs(packageOpts.envs || packageOpts.env) | ||
addEnvs(opts.envs || opts.env) | ||
setParser(packageOpts.parser || opts.parser) | ||
if (self.customParseOpts) { | ||
let rootDir | ||
if (opts.usePackageJson) { | ||
const filePath = pkgConf.filepath(packageOpts) | ||
rootDir = filePath ? path.dirname(filePath) : opts.cwd | ||
} else { | ||
rootDir = opts.cwd | ||
if (eslintConfig.fix) { | ||
this.eslint.ESLint.outputFixes(result) | ||
} | ||
opts = self.customParseOpts(opts, packageOpts, rootDir) | ||
} | ||
function addExtensions (extensions) { | ||
if (!extensions) return | ||
opts.eslintConfig.extensions = opts.eslintConfig.extensions.concat(extensions) | ||
return result | ||
} | ||
function addIgnore (ignore) { | ||
if (!ignore) return | ||
opts.eslintConfig.ignorePattern = opts.eslintConfig.ignorePattern.concat(ignore) | ||
} | ||
/** | ||
* @param {BaseLintOptions & { cwd?: string }} [opts] | ||
* @returns {EslintOptions} | ||
*/ | ||
resolveEslintConfig (opts) { | ||
const eslintConfig = resolveEslintConfig( | ||
{ | ||
cwd: this.cwd, | ||
...opts, | ||
cmd: this.cmd | ||
}, | ||
this.eslintConfig, | ||
this.customEslintConfigResolver | ||
) | ||
function addGlobals (globals) { | ||
if (!globals) return | ||
opts.eslintConfig.globals = self.eslintConfig.globals.concat(globals) | ||
return eslintConfig | ||
} | ||
} | ||
function addPlugins (plugins) { | ||
if (!plugins) return | ||
opts.eslintConfig.plugins = self.eslintConfig.plugins.concat(plugins) | ||
} | ||
function addEnvs (envs) { | ||
if (!envs) return | ||
if (!Array.isArray(envs) && typeof envs !== 'string') { | ||
// envs can be an object in `package.json` | ||
envs = Object.keys(envs).filter(function (env) { return envs[env] }) | ||
} | ||
opts.eslintConfig.envs = self.eslintConfig.envs.concat(envs) | ||
} | ||
function setParser (parser) { | ||
if (!parser) return | ||
opts.eslintConfig.parser = parser | ||
} | ||
return opts | ||
} | ||
module.exports.cli = require('./bin/cmd') | ||
module.exports.StandardEngine = StandardEngine |
{ | ||
"name": "standard-engine", | ||
"version": "14.0.1", | ||
"version": "15.0.0-0", | ||
"description": "Wrap your standards in a tortilla and cover it in special sauce.", | ||
@@ -38,3 +38,10 @@ "keywords": [ | ||
"scripts": { | ||
"test": "standard && tape test/clone.js test/api.js" | ||
"check:dependency-check": "dependency-check *.js 'bin/**/*.js' 'lib/**/*.js' --no-dev", | ||
"check:installed-check": "installed-check", | ||
"check:standard": "standard", | ||
"check:tsc": "tsc", | ||
"check": "run-p check:*", | ||
"test-ci": "run-s test:*", | ||
"test:tape": "c8 --reporter=lcov --reporter=text tape test/clone.js test/*.js", | ||
"test": "run-s check test:*" | ||
}, | ||
@@ -48,4 +55,11 @@ "dependencies": { | ||
"devDependencies": { | ||
"babel-eslint": "^10.1.0", | ||
"@tsconfig/node12": "^1.0.9", | ||
"@types/cross-spawn": "^6.0.2", | ||
"@types/eslint": "^7.28.0", | ||
"@types/minimist": "^1.2.2", | ||
"@types/node": "~12.20.0", | ||
"@types/tape": "^4.13.2", | ||
"c8": "^7.10.0", | ||
"cross-spawn": "^7.0.3", | ||
"dependency-check": "^5.0.0-4", | ||
"eslint": "^7.12.1", | ||
@@ -56,9 +70,12 @@ "eslint-config-standard": "^16.0.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"eslint-plugin-react": "^7.21.5", | ||
"installed-check": "^5.0.0", | ||
"npm-run-all": "^4.1.5", | ||
"standard": "*", | ||
"tape": "^5.0.1" | ||
"tape": "^5.0.1", | ||
"typescript": "~4.5.2" | ||
}, | ||
"engines": { | ||
"node": ">=8.10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -65,0 +82,0 @@ "funding": [ |
@@ -1,5 +0,5 @@ | ||
# standard-engine [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] | ||
# standard-engine [![Tests CI][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] | ||
[travis-image]: https://img.shields.io/travis/standard/standard-engine/master.svg | ||
[travis-url]: https://travis-ci.org/standard/standard-engine | ||
[ci-image]: https://github.com/standard/standard-engine/workflows/tests/badge.svg?branch=master | ||
[ci-url]: https://github.com/standard/standard-engine/actions?query=workflow%3A%22tests%22 | ||
[npm-image]: https://img.shields.io/npm/v/standard-engine.svg | ||
@@ -45,5 +45,5 @@ [npm-url]: https://npmjs.org/package/standard-engine | ||
// programmatic usage | ||
var Linter = require('standard-engine').linter | ||
var opts = require('./options.js') | ||
module.exports = new Linter(opts) | ||
const { StandardEngine } = require('standard-engine') | ||
const opts = require('./options.js') | ||
module.exports = new StandardEngine(opts) | ||
``` | ||
@@ -56,3 +56,4 @@ | ||
var opts = require('../options.js') | ||
const opts = require('../options.js') | ||
require('standard-engine').cli(opts) | ||
@@ -64,6 +65,7 @@ ``` | ||
```js | ||
var eslint = require('eslint') | ||
var path = require('path') | ||
var pkg = require('./package.json') | ||
const eslint = require('eslint') | ||
const path = require('path') | ||
const pkg = require('./package.json') | ||
/** @type {import('standard-engine').StandardEngineOptions} **/ | ||
module.exports = { | ||
@@ -78,3 +80,3 @@ // homepage, version and bugs pulled from package.json | ||
eslintConfig: { | ||
configFile: path.join(__dirname, 'eslintrc.json') | ||
overrideConfigFile: path.join(__dirname, 'eslintrc.json') | ||
}, | ||
@@ -85,3 +87,3 @@ cwd: '' // current working directory, passed to eslint | ||
Additionally an optional `parseOpts()` function can be provided. See below for details. | ||
Additionally an optional `resolveEslintConfig()` function can be provided. See below for details. | ||
@@ -172,3 +174,3 @@ ### `eslintrc.json` | ||
```js | ||
var DEFAULT_IGNORE = [ | ||
const DEFAULT_IGNORE = [ | ||
'*.min.js', | ||
@@ -185,13 +187,4 @@ 'coverage/', | ||
Since `standard-engine` uses [`eslint`](http://eslint.org/) under-the-hood, you can | ||
hide warnings as you normally would if you used `eslint` directly. | ||
Since `standard-engine` uses [`eslint`](http://eslint.org/) 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: | ||
```bash | ||
$ pocketlint --verbose | ||
Error: Live by your own standards! | ||
routes/error.js:20:36: 'file' was used before it was defined. (no-use-before-define) | ||
``` | ||
Disable **all rules** on a specific line: | ||
@@ -286,8 +279,8 @@ | ||
You can provide a `parseOpts()` function in the `options.js` exports: | ||
You can provide a `resolveEslintConfig()` function in the `options.js` exports: | ||
```js | ||
var eslint = require('eslint') | ||
var path = require('path') | ||
var pkg = require('./package.json') | ||
const eslint = require('eslint') | ||
const path = require('path') | ||
const pkg = require('./package.json') | ||
@@ -305,5 +298,5 @@ module.exports = { | ||
}, | ||
parseOpts: function (opts, packageOpts, rootDir) { | ||
// provide implementation here, then return the opts object (or a new one) | ||
return opts | ||
resolveEslintConfig: function (eslintConfig, opts, packageOpts, rootDir) { | ||
// provide implementation here, then return the eslintConfig object (or a new one) | ||
return eslintConfig | ||
} | ||
@@ -313,16 +306,9 @@ } | ||
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). | ||
This function is called with the current ESLint config (the options passed to the [`ESLint`](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions) 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 `opts`, or return a new object with the options that are to be used. | ||
Modify and return `eslintConfig`, or return a new object with the eslint config to be used. | ||
The following options are provided in the `opts` object, and must be on the returned object: | ||
- `ignore`: array of file patterns (in `.gitignore` format) to ignore | ||
- `cwd`: string, the current working directory | ||
- `fix`: boolean, whether to automatically fix problems | ||
- `eslintConfig`: object, the options passed to [ESLint's `CLIEngine`](http://eslint.org/docs/developer-guide/nodejs-api#cliengine) | ||
## API Usage | ||
### `engine.lintText(text, [opts], callback)` | ||
### `async engine.lintText(text, [opts])` | ||
@@ -354,3 +340,3 @@ Lint the provided source `text` to enforce your defined style. An `opts` object may | ||
The `callback` will be called with an `Error` and `results` object. | ||
Returns a `Promise` resolving to the `results` or rejected with an `Error`. | ||
@@ -360,3 +346,3 @@ The `results` object will contain the following properties: | ||
```js | ||
var results = { | ||
const results = { | ||
results: [ | ||
@@ -378,9 +364,4 @@ { | ||
### `results = engine.lintTextSync(text, [opts])` | ||
### `async engine.lintFiles(files, [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: | ||
@@ -410,3 +391,3 @@ | ||
The `callback` will be called with an `Error` and `results` object (same as above). | ||
Returns a `Promise` resolving to the `results` or rejected with an `Error` (same as above). | ||
@@ -413,0 +394,0 @@ **NOTE: There is no synchronous version of `engine.lintFiles()`.** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5252031
30
1033
21
2
412
2