standard-engine
Advanced tools
Comparing version 13.0.0 to 14.0.0
@@ -5,8 +5,8 @@ #!/usr/bin/env node | ||
var minimist = require('minimist') | ||
var getStdin = require('get-stdin') | ||
const minimist = require('minimist') | ||
const getStdin = require('get-stdin') | ||
function Cli (opts) { | ||
var Linter = require('../').linter | ||
var standard = opts.linter || new Linter(opts) | ||
const Linter = require('../').linter | ||
const standard = opts.linter || new Linter(opts) | ||
@@ -19,3 +19,3 @@ opts = Object.assign({ | ||
var argv = minimist(process.argv.slice(2), { | ||
const argv = minimist(process.argv.slice(2), { | ||
alias: { | ||
@@ -39,2 +39,3 @@ global: 'globals', | ||
'parser', | ||
'ext', | ||
'env' | ||
@@ -72,2 +73,3 @@ ] | ||
--stdin Read file text from stdin | ||
--ext Specify JavaScript file extensions | ||
--global Declare global variable | ||
@@ -88,4 +90,5 @@ --plugin Use custom eslint plugin | ||
var lintOpts = { | ||
const lintOpts = { | ||
fix: argv.fix, | ||
extensions: argv.ext, | ||
globals: argv.global, | ||
@@ -97,3 +100,3 @@ plugins: argv.plugin, | ||
var stdinText | ||
let stdinText | ||
@@ -130,3 +133,3 @@ if (argv.stdin) { | ||
// Are any fixable rules present? | ||
var isFixable = result.results.some(function (result) { | ||
const isFixable = result.results.some(function (result) { | ||
return result.messages.some(function (message) { | ||
@@ -149,3 +152,6 @@ return !!message.fix | ||
' %s:%d:%d: %s%s', | ||
result.filePath, message.line || 0, message.column || 0, message.message, | ||
result.filePath, | ||
message.line || 0, | ||
message.column || 0, | ||
message.message, | ||
argv.verbose ? ' (' + message.ruleId + ')' : '' | ||
@@ -164,3 +170,4 @@ ) | ||
'\nIf you think this is a bug in `%s`, open an issue: %s', | ||
opts.cmd, opts.bugs | ||
opts.cmd, | ||
opts.bugs | ||
) | ||
@@ -167,0 +174,0 @@ process.exitCode = 1 |
144
index.js
@@ -6,17 +6,17 @@ /*! standard-engine. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */ | ||
var deglob = require('deglob') | ||
var os = require('os') | ||
var path = require('path') | ||
var pkgConf = require('pkg-conf') | ||
const os = require('os') | ||
const path = require('path') | ||
const pkgConf = require('pkg-conf') | ||
const fs = require('fs') | ||
var CACHE_HOME = require('xdg-basedir').cache || os.tmpdir() | ||
const CACHE_HOME = require('xdg-basedir').cache || os.tmpdir() | ||
var DEFAULT_PATTERNS = [ | ||
'**/*.js', | ||
'**/*.jsx', | ||
'**/*.mjs', | ||
'**/*.cjs' | ||
const DEFAULT_EXTENSIONS = [ | ||
'.js', | ||
'.jsx', | ||
'.mjs', | ||
'.cjs' | ||
] | ||
var DEFAULT_IGNORE = [ | ||
const DEFAULT_IGNORE = [ | ||
'**/*.min.js', | ||
@@ -40,7 +40,7 @@ 'coverage/**', | ||
var m = opts.version && opts.version.match(/^(\d+)\./) | ||
var majorVersion = (m && m[1]) || '0' | ||
const m = opts.version && opts.version.match(/^(\d+)\./) | ||
const majorVersion = (m && m[1]) || '0' | ||
// Example cache location: ~/.cache/standard/v12/ | ||
var cacheLocation = path.join(CACHE_HOME, this.cmd, `v${majorVersion}/`) | ||
const cacheLocation = path.join(CACHE_HOME, this.cmd, `v${majorVersion}/`) | ||
@@ -53,4 +53,5 @@ this.eslintConfig = Object.assign({ | ||
globals: [], | ||
ignore: false, | ||
plugins: [], | ||
ignorePattern: [], | ||
extensions: [], | ||
useEslintrc: false | ||
@@ -85,3 +86,3 @@ }, opts.eslintConfig) | ||
if (typeof opts === 'function') return this.lintText(text, null, opts) | ||
var result | ||
let result | ||
try { | ||
@@ -111,3 +112,3 @@ result = this.lintTextSync(text, opts) | ||
Linter.prototype.lintFiles = function (files, opts, cb) { | ||
var self = this | ||
const self = this | ||
if (typeof opts === 'function') return self.lintFiles(files, null, opts) | ||
@@ -117,55 +118,79 @@ opts = self.parseOpts(opts) | ||
if (typeof files === 'string') files = [files] | ||
if (files.length === 0) files = DEFAULT_PATTERNS | ||
if (files.length === 0) files = ['.'] | ||
var deglobOpts = { | ||
ignore: opts.ignore, | ||
cwd: opts.cwd, | ||
useGitIgnore: true, | ||
usePackageJson: false | ||
let result | ||
try { | ||
result = new self.eslint.CLIEngine(opts.eslintConfig).executeOnFiles(files) | ||
} catch (err) { | ||
return cb(err) | ||
} | ||
deglob(files, deglobOpts, function (err, allFiles) { | ||
if (err) return cb(err) | ||
if (opts.fix) { | ||
self.eslint.CLIEngine.outputFixes(result) | ||
} | ||
var result | ||
try { | ||
result = new self.eslint.CLIEngine(opts.eslintConfig).executeOnFiles(allFiles) | ||
} catch (err) { | ||
return cb(err) | ||
} | ||
if (opts.fix) { | ||
self.eslint.CLIEngine.outputFixes(result) | ||
} | ||
return cb(null, result) | ||
}) | ||
return cb(null, result) | ||
} | ||
Linter.prototype.parseOpts = function (opts) { | ||
var self = this | ||
const self = this | ||
if (!opts) opts = {} | ||
opts = Object.assign({}, opts) | ||
opts.eslintConfig = Object.assign({}, self.eslintConfig) | ||
opts.eslintConfig.fix = !!opts.fix | ||
opts = { | ||
eslintConfig: { ...self.eslintConfig }, | ||
usePackageJson: true, | ||
useGitIgnore: true, | ||
gitIgnoreFile: ['.gitignore', '.git/info/exclude'], | ||
cwd: self.cwd, | ||
fix: false, | ||
ignore: [], | ||
extensions: [], | ||
...opts | ||
} | ||
if (!opts.cwd) opts.cwd = self.cwd | ||
if (!Array.isArray(opts.gitIgnoreFile)) { | ||
opts.gitIgnoreFile = [opts.gitIgnoreFile] | ||
} | ||
opts.eslintConfig.cwd = opts.cwd | ||
opts.eslintConfig.fix = opts.fix | ||
// If no usePackageJson option is given, default to `true` | ||
var usePackageJson = opts.usePackageJson != null | ||
? opts.usePackageJson | ||
: true | ||
let packageOpts = {} | ||
let rootPath = null | ||
var packageOpts = usePackageJson | ||
? pkgConf.sync(self.cmd, { cwd: opts.cwd }) | ||
: {} | ||
if (opts.usePackageJson || opts.useGitIgnore) { | ||
packageOpts = pkgConf.sync(self.cmd, { cwd: opts.cwd }) | ||
rootPath = path.dirname(pkgConf.filepath(packageOpts)) | ||
} | ||
if (!opts.ignore) opts.ignore = [] | ||
if (!opts.usePackageJson) packageOpts = {} | ||
addIgnore(packageOpts.ignore) | ||
if (!packageOpts.noDefaultIgnore) { | ||
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) { | ||
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) | ||
@@ -183,5 +208,5 @@ addGlobals(opts.globals || opts.global) | ||
if (self.customParseOpts) { | ||
var rootDir | ||
if (usePackageJson) { | ||
var filePath = pkgConf.filepath(packageOpts) | ||
let rootDir | ||
if (opts.usePackageJson) { | ||
const filePath = pkgConf.filepath(packageOpts) | ||
rootDir = filePath ? path.dirname(filePath) : opts.cwd | ||
@@ -194,5 +219,10 @@ } else { | ||
function addExtensions (extensions) { | ||
if (!extensions) return | ||
opts.eslintConfig.extensions = opts.eslintConfig.extensions.concat(extensions) | ||
} | ||
function addIgnore (ignore) { | ||
if (!ignore) return | ||
opts.ignore = opts.ignore.concat(ignore) | ||
opts.eslintConfig.ignorePattern = opts.eslintConfig.ignorePattern.concat(ignore) | ||
} | ||
@@ -199,0 +229,0 @@ |
{ | ||
"name": "standard-engine", | ||
"version": "13.0.0", | ||
"version": "14.0.0", | ||
"description": "Wrap your standards in a tortilla and cover it in special sauce.", | ||
@@ -41,3 +41,2 @@ "keywords": [ | ||
"dependencies": { | ||
"deglob": "^4.0.1", | ||
"get-stdin": "^8.0.0", | ||
@@ -50,14 +49,12 @@ "minimist": "^1.2.5", | ||
"babel-eslint": "^10.1.0", | ||
"cross-spawn": "^7.0.2", | ||
"eslint": "^6.8.0", | ||
"eslint-config-standard": "^14.1.1", | ||
"eslint-config-standard-jsx": "^8.1.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
"cross-spawn": "^7.0.3", | ||
"eslint": "^7.12.1", | ||
"eslint-config-standard": "^15.0.1", | ||
"eslint-config-standard-jsx": "^9.0.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-react": "^7.19.0", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"mkdirp": "^0.5.5", | ||
"standard": "^14.3.3", | ||
"tape": "^5.0.0" | ||
"eslint-plugin-react": "^7.21.5", | ||
"standard": "^15.0.1", | ||
"tape": "^5.0.1" | ||
}, | ||
@@ -64,0 +61,0 @@ "engines": { |
@@ -105,3 +105,3 @@ # 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": "semistandard" | ||
"standard-engine": "pocketlint" | ||
} | ||
@@ -115,3 +115,3 @@ ``` | ||
"standard-engine": { | ||
"name": "semistandard" | ||
"name": "pocketlint" | ||
} | ||
@@ -133,2 +133,15 @@ } | ||
### 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 | ||
@@ -158,10 +171,10 @@ | ||
var DEFAULT_IGNORE = [ | ||
'**/*.min.js', | ||
'coverage/**', | ||
'node_modules/**', | ||
'vendor/**' | ||
'*.min.js', | ||
'coverage/', | ||
'node_modules/', | ||
'vendor/' | ||
] | ||
``` | ||
You can disable these default ignores by setting `noDefaultIgnore` option to `true`. | ||
You can disable these default ignores by setting the `noDefaultIgnore` option to `true`. | ||
@@ -301,3 +314,3 @@ ### Hiding Warnings | ||
- `ignore`: array of file globs to ignore | ||
- `ignore`: array of file patterns (in `.gitignore` format) to ignore | ||
- `cwd`: string, the current working directory | ||
@@ -316,5 +329,9 @@ - `fix`: boolean, whether to automatically fix problems | ||
{ | ||
// unique to lintText | ||
filename: '', // path of file containing the text being linted | ||
// common to lintText and lintFiles | ||
cwd: '', // current working directory (default: process.cwd()) | ||
filename: '', // path of file containing the text being linted | ||
fix: false, // automatically fix problems | ||
extensions: [], // file extensions to lint (has sane defaults) | ||
globals: [], // custom global variables to declare | ||
@@ -324,3 +341,4 @@ plugins: [], // custom eslint plugins | ||
parser: '', // custom js parser (e.g. babel-eslint) | ||
usePackageJson: true // use options from nearest package.json? | ||
usePackageJson: true, // use options from nearest package.json? | ||
useGitIgnore: true // use file ignore patterns from .gitignore? | ||
} | ||
@@ -366,5 +384,9 @@ ``` | ||
{ | ||
// 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 | ||
@@ -374,3 +396,4 @@ plugins: [], // custom eslint plugins | ||
parser: '', // custom js parser (e.g. babel-eslint) | ||
usePackageJson: true // use options from nearest package.json? | ||
usePackageJson: true, // use options from nearest package.json? | ||
useGitIgnore: true // use file ignore patterns from .gitignore? | ||
} | ||
@@ -381,3 +404,3 @@ ``` | ||
Both `ignore` and `files` globs are resolved relative to the current working directory. | ||
Both `ignore` and `files` patterns are resolved relative to the current working directory. | ||
@@ -394,3 +417,3 @@ The `callback` will be called with an `Error` and `results` object (same as above). | ||
{ | ||
ignore: [], // file globs to ignore (has sane defaults) | ||
ignore: [], // file patterns to ignore (has sane defaults) | ||
cwd: '', // current working directory (default: process.cwd()) | ||
@@ -397,0 +420,0 @@ filename: '', // path of the file containing the text being linted (optional) |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
36083
4
11
359
431
2
- Removeddeglob@^4.0.1
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddebug-log@1.0.1(transitive)
- Removeddeglob@4.0.1(transitive)
- Removedfind-root@1.1.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedignore@5.3.2(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpkg-config@1.1.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removeduniq@1.0.1(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedxtend@4.0.2(transitive)