Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

View File

@ -0,0 +1,198 @@
# Changelog
## 3.0.1
* Remove unnecessary `object-assign` dependency
## 3.0.0
* Bump eslint dependency to ^3.0.0 <http://eslint.org/blog/2016/07/eslint-v3.0.0-released>
* Use ES2015 syntax
* Remove these deprecated option aliases:
* `global`
* `env`
* `config`
* `rulesdir`
* `eslintrc`
* Drop support for non-array `globals` option
## 2.1.0
* Remove now obsolete error handling for formatter loading
* It's gracefully done in ESLint >=v2.10.0. <https://github.com/eslint/eslint/pull/5978>
## 2.0.0
* Update to ESLint 2.0.0, along with other dependency updates
* Replace JSCS with ESLint equivalent rules
## 1.1.1
* Fix config migration of "extends" and "ecmaFeatures" options
## 1.1.0
* Bump eslint dependency to ^1.4.0, when "fix" option was added
* Apply eslint-fixed source to gulp file contents
* Add "quiet" option to filter eslint messages
* Update .eslintignore resolution to match eslint
* Add file ignore warnings behind "warnFileIgnored" option
* Migrate "ecmaFeatures" and "extends" option to "baseConfig" option
* Add "result" and "results" methods and tests
* Refactor "failOnError", "failAfterError", "format", and "formatEach" to use "result" or "results" methods
## 1.0.0
* Bump eslint dependency to ^1.0.0
* Update dev-dependencies and js-doc formats
## 0.15.0
* Update dependencies
* Bump eslint dependency to ^0.24.0
## 0.14.0
* Bump eslint dependency to ^0.23.0
* Remove no-longer-needed code
* Fix project eslintrc syntax
## 0.13.2
* Remove dependency on through2 to address highWatermark overflow issue (#36)
## 0.13.1
* Update dependencies
## 0.13.0
* Bump eslint dependency to ^0.22.1
## 0.12.0
* Bump eslint dependency to 0.21.x
## 0.11.1
* tidying-up dependencies
## 0.11.0
* Improve code coverage
* Remove support for deprecated/legacy formatters
## 0.10.0
* Bump eslint dependency to 0.20.x
## 0.9.0
* Bump eslint dependency to 0.19.x
## 0.8.0
* Bump eslint dependency to 0.18.x
## 0.7.0
* Bump eslint dependency to 0.17.x
## 0.6.0
* Bump eslint dependency to 0.16.x
## 0.5.0
* Bump eslint dependency to 0.15.x
## 0.4.3
* Fix "rulePaths" typo
## 0.4.2
* Bump bufferstreams dependency to 1.x
* Fix wrong option handling (@Jakobo)
## 0.4.1
* Code refactoring
## 0.4.0
* Bump eslint dependency to 0.14.x
* Use Stream2 instead of older Stream
## 0.3.0
* Import filesystem-local config plugins
* Fix doc typo
## 0.2.2
* Upgraded eslint to 0.13.0
* Fix filesystem-local .eslintrc loading
* Fix filesystem-local .eslintignore loading
* Add failAfterError to fail at the end of the stream instead of the first error (works well with 'format' method)
## 0.2.1 (unreleased)
* Upgraded eslint to 0.11.0
## 0.2.0
* WAY overdue upgrade to eslint (^0.9.2)
* Use eslint's CLIEngine module to do most of the configuration work (yay!)
* Semi-Breaking Change: Remove gulpEslint.linter. Linting will occur with compatible, installed version of eslint.
## 0.1.8
* Use "dependencies" instead of "peerDependencies"
* Update .eslintrc to account for new eol-last rule in eslint 0.7.1
* Check for message.severity when evaluating messages in failOnError
## 0.1.7
* Open eslint dependency to future versions
* Cut out several unnecessary dependencies
* Declare eslint as a peer dependency to support variation in version
* Fix support for nodejs 0.11
## 0.1.6
* Update dependencies, include eslint 0.5.0
* Integrate eslint cli-config changes
* Accept string array of environments to enable
* Accept string array of globals ('key:boolean' or 'key')
## 0.1.5
* Do not format when there are no eslint'd files
## 0.1.4
* Update eslint version to 0.4.0
## 0.1.3
* Change default formatter to 'stylish'
* Add support for .eslintignore file
* Skip non-JS files to play well with multi-filetype streams
* Add "failOnError" method to stop streams when an eslint error has occurred
* Use gulp-util's PluginError
* Ignore shebangs in JS files
## 0.1.2
* Update eslint version to 0.3.0
## 0.1.1
* Update dependency versions
* Loosen version peer dependency on Gulp
## 0.1.0
* initial plugin

20
static/js/ketcher2/node_modules/gulp-eslint/LICENSE generated vendored Normal file
View File

@ -0,0 +1,20 @@
Copyright 2016 ADAMETRY
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

277
static/js/ketcher2/node_modules/gulp-eslint/README.md generated vendored Normal file
View File

@ -0,0 +1,277 @@
# gulp-eslint [![Build Status](https://travis-ci.org/adametry/gulp-eslint.svg)](https://travis-ci.org/adametry/gulp-eslint) [![Coverage Status](https://img.shields.io/coveralls/adametry/gulp-eslint.svg)](https://coveralls.io/r/adametry/gulp-eslint)
> A [gulp](http://gulpjs.com/) plugin for [ESLint](http://eslint.org/).
## Installation
[Use npm](https://docs.npmjs.com/cli/install).
```sh
npm install gulp-eslint
```
## Usage
```javascript
const gulp = require('gulp');
const eslint = require('gulp-eslint');
gulp.task('lint', () => {
// ESLint ignores files with "node_modules" paths.
// So, it's best to have gulp ignore the directory as well.
// Also, Be sure to return the stream from the task;
// Otherwise, the task may end before the stream has finished.
return gulp.src(['**/*.js','!node_modules/**'])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});
gulp.task('default', ['lint'], function () {
// This will only run if the lint task is successful...
});
```
Or use the plugin API to do things like:
```javascript
gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint({
rules: {
'my-custom-rule': 1,
'strict': 2
},
globals: [
'jQuery',
'$'
],
envs: [
'browser'
]
}))
.pipe(eslint.formatEach('compact', process.stderr));
```
For additional examples, look through the [example directory](https://github.com/adametry/gulp-eslint/tree/master/example).
## API
### eslint()
*No explicit configuration.* A `.eslintrc` file may be resolved relative to each linted file.
### eslint(options)
See [ESlint CLIEngine options](http://eslint.org/docs/developer-guide/nodejs-api#cliengine).
#### options.rules
Type: `Object`
Set [configuration](http://eslint.org/docs/user-guide/configuring#configuring-rules) of [rules](http://eslint.org/docs/rules/).
```javascript
{
"rules":{
"camelcase": 1,
"comma-dangle": 2,
"quotes": 0
}
}
```
#### options.globals
Type: `Object`
Specify [globals](http://eslint.org/docs/user-guide/configuring#specifying-globals).
```javascript
{
"globals":{
"jQuery": false,
"$": true
}
}
```
#### options.fix
Type: `Boolean`
This option instructs ESLint to try to fix as many issues as possible. The fixes are applied to the gulp stream. The fixed content can be saved to file using `gulp.dest` (See [example/fix.js](https://github.com/adametry/gulp-eslint/blob/master/example/fix.js)). Rules that are fixable can be found in ESLint's [rules list](http://eslint.org/docs/rules/).
When fixes are applied, a "fixed" property is set to `true` on the fixed file's ESLint result.
#### options.quiet
Type: `Boolean`
When `true`, this option will filter warning messages from ESLint results. This mimics the ESLint CLI [quiet option](http://eslint.org/docs/user-guide/command-line-interface#quiet).
Type: `function (message, index, list) { return Boolean(); }`
When provided a function, it will be used to filter ESLint result messages, removing any messages that do not return a `true` (or truthy) value.
#### options.envs
Type: `Array`
Specify a list of [environments](http://eslint.org/docs/user-guide/configuring#specifying-environments) to be applied.
#### options.rulePaths
Type: `Array`
This option allows you to specify additional directories from which to load rules files. This is useful when you have custom rules that aren't suitable for being bundled with ESLint. This option works much like the ESLint CLI's [rulesdir option](http://eslint.org/docs/user-guide/command-line-interface#rulesdir).
#### options.configFile
Type: `String`
Path to the ESLint rules configuration file. For more information, see the ESLint CLI [config option](http://eslint.org/docs/user-guide/command-line-interface#c-config) and [Using Configuration Files](http://eslint.org/docs/user-guide/configuring#using-configuration-files).
#### options.warnFileIgnored
Type: `Boolean`
When `true`, add a result warning when ESLint ignores a file. This can be used to file files that are needlessly being loaded by `gulp.src`. For example, since ESLint automatically ignores "node_modules" file paths and gulp.src does not, a gulp task may take seconds longer just reading files from the "node_modules" directory.
#### <a name="options.useEslintrc"></a>options.useEslintrc
Type: `Boolean`
When `false`, ESLint will not load [.eslintrc files](http://eslint.org/docs/user-guide/configuring#using-configuration-files).
### eslint(configFilePath)
Type: `String`
Shorthand for defining `options.configFile`.
### eslint.result(action)
Type: `function (result) {}`
Call a function for each ESLint file result. No returned value is expected. If an error is thrown, it will be wrapped in a Gulp PluginError and emitted from the stream.
```javascript
gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint())
.pipe(eslint.result(result => {
// Called for each ESLint result.
console.log(`ESLint result: ${result.filePath}`);
console.log(`# Messages: ${result.messages.length}`);
console.log(`# Warnings: ${result.warningCount}`);
console.log(`# Errors: ${result.errorCount}`);
}));
```
Type: `function (result, callback) { callback(error); }`
Call an asynchronous function for each ESLint file result. The callback must be called for the stream to finish. If a value is passed to the callback, it will be wrapped in a Gulp PluginError and emitted from the stream.
### eslint.results(action)
Type: `function (results) {}`
Call a function once for all ESLint file results before a stream finishes. No returned value is expected. If an error is thrown, it will be wrapped in a Gulp PluginError and emitted from the stream.
The results list has a "warningCount" property that is the sum of warnings in all results; likewise, an "errorCount" property is set to the sum of errors in all results.
```javascript
gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint())
.pipe(eslint.results(results => {
// Called once for all ESLint results.
console.log(`Total Results: ${results.length}`);
console.log(`Total Warnings: ${results.warningCount}`);
console.log(`Total Errors: ${results.errorCount}`);
}));
```
Type: `function (results, callback) { callback(error); }`
Call an asynchronous function once for all ESLint file results before a stream finishes. The callback must be called for the stream to finish. If a value is passed to the callback, it will be wrapped in a Gulp PluginError and emitted from the stream.
### eslint.failOnError()
Stop a task/stream if an ESLint error has been reported for any file.
```javascript
// Cause the stream to stop(/fail) before copying an invalid JS file to the output directory
gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint())
.pipe(eslint.failOnError());
```
### eslint.failAfterError()
Stop a task/stream if an ESLint error has been reported for any file, but wait for all of them to be processed first.
```javascript
// Cause the stream to stop(/fail) when the stream ends if any ESLint error(s) occurred.
gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint())
.pipe(eslint.failAfterError());
```
### eslint.format(formatter, output)
Format all linted files once. This should be used in the stream after piping through `eslint`; otherwise, this will find no ESLint results to format.
The `formatter` argument may be a `String`, `Function`, or `undefined`. As a `String`, a formatter module by that name or path will be resolved as a module, relative to `process.cwd()`, or as one of the [ESLint-provided formatters](https://github.com/eslint/eslint/tree/master/lib/formatters). If `undefined`, the ESLint “stylish” formatter will be resolved. A `Function` will be called with an `Array` of file linting results to format.
```javascript
// use the default "stylish" ESLint formatter
eslint.format()
// use the "checkstyle" ESLint formatter
eslint.format('checkstyle')
// use the "eslint-path-formatter" module formatter
// (@see https://github.com/Bartvds/eslint-path-formatter)
eslint.format('node_modules/eslint-path-formatter')
```
The `output` argument may be a `WritableStream`, `Function`, or `undefined`. As a `WritableStream`, the formatter results will be written to the stream. If `undefined`, the formatter results will be written to [gulps log](https://github.com/gulpjs/gulp-util#logmsg). A `Function` will be called with the formatter results as the only parameter.
```javascript
// write to gulp's log (default)
eslint.format();
// write messages to stdout
eslint.format('junit', process.stdout)
```
### eslint.formatEach(formatter, output)
Format each linted file individually. This should be used in the stream after piping through `eslint`; otherwise, this will find no ESLint results to format.
The arguments for `formatEach` are the same as the arguments for `format`.
##Configuration
ESLint may be configured explicity by using any of the following plugin options: `config`, `rules`, `globals`, or `env`. If the [useEslintrc option](#useEslintrc) is not set to `false`, ESLint will attempt to resolve a file by the name of `.eslintrc` within the same directory as the file to be linted. If not found there, parent directories will be searched until `.eslintrc` is found or the directory root is reached.
##Ignore Files
ESLint will ignore files that do not have a `.js` file extension at the point of linting ([some plugins](https://github.com/contra/gulp-coffee) may change file extensions mid-stream). This avoids unintentional linting of non-JavaScript files.
ESLint will also detect an `.eslintignore` file at the cwd or a parent directory. See the [ESLint docs](http://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories) to learn how to construct this file.
## Extensions
ESLint results are attached as an "eslint" property to the vinyl files that pass through a Gulp.js stream pipeline. This is available to streams that follow the initial `eslint` stream. The [eslint.result](#result) and [eslint.results](#results) methods are made available to support extensions and custom handling of ESLint results.
#### Gulp-Eslint Extensions:
* [gulp-eslint-if-fixed](https://github.com/lukeapage/gulp-eslint-if-fixed)
* [gulp-eslint-threshold](https://github.com/krmbkt/gulp-eslint-threshold)

202
static/js/ketcher2/node_modules/gulp-eslint/index.js generated vendored Normal file
View File

@ -0,0 +1,202 @@
'use strict';
const BufferStreams = require('bufferstreams');
const PluginError = require('gulp-util').PluginError;
const CLIEngine = require('eslint').CLIEngine;
const util = require('./util');
const path = require('path');
/**
* Append ESLint result to each file
*
* @param {(Object|String)} [options] - Configure rules, env, global, and other options for running ESLint
* @returns {stream} gulp file stream
*/
function gulpEslint(options) {
options = util.migrateOptions(options) || {};
const linter = new CLIEngine(options);
function verify(str, filePath) {
const result = linter.executeOnText(str, filePath).results[0];
// Note: Fixes are applied as part of "executeOnText".
// Any applied fix messages have been removed from the result.
if (options.quiet) {
// ignore warnings
return util.filterResult(result, options.quiet);
}
return result;
}
return util.transform((file, enc, cb) => {
const filePath = path.relative(process.cwd(), file.path);
if (file.isNull()) {
cb(null, file);
return;
}
if (linter.isPathIgnored(filePath)) {
// Note:
// Vinyl files can have an independently defined cwd, but ESLint works relative to `process.cwd()`.
// (https://github.com/gulpjs/gulp/blob/master/docs/recipes/specifying-a-cwd.md)
// Also, ESLint doesn't adjust file paths relative to an ancestory .eslintignore path.
// E.g., If ../.eslintignore has "foo/*.js", ESLint will ignore ./foo/*.js, instead of ../foo/*.js.
// Eslint rolls this into `CLIEngine.executeOnText`. So, gulp-eslint must account for this limitation.
if (linter.options.ignore && options.warnFileIgnored) {
// Warn that gulp.src is needlessly reading files that ESLint ignores
file.eslint = util.createIgnoreResult(file);
}
cb(null, file);
return;
}
if (file.isStream()) {
file.contents = file.contents.pipe(new BufferStreams((err, buf, done) => {
file.eslint = verify(String(buf), filePath);
// Update the fixed output; otherwise, fixable messages are simply ignored.
if (file.eslint.hasOwnProperty('output')) {
buf = new Buffer(file.eslint.output);
file.eslint.fixed = true;
}
done(null, buf);
cb(null, file);
}));
return;
}
file.eslint = verify(file.contents.toString(), filePath);
// Update the fixed output; otherwise, fixable messages are simply ignored.
if (file.eslint.hasOwnProperty('output')) {
file.contents = new Buffer(file.eslint.output);
file.eslint.fixed = true;
}
cb(null, file);
});
}
/**
* Handle each ESLint result as it passes through the stream.
*
* @param {Function} action - A function to handle each ESLint result
* @returns {stream} gulp file stream
*/
gulpEslint.result = action => {
if (typeof action !== 'function') {
throw new Error('Expected callable argument');
}
return util.transform((file, enc, done) => {
if (file.eslint) {
util.tryResultAction(action, file.eslint, util.handleCallback(done, file));
} else {
done(null, file);
}
});
};
/**
* Handle all ESLint results at the end of the stream.
*
* @param {Function} action - A function to handle all ESLint results
* @returns {stream} gulp file stream
*/
gulpEslint.results = function(action) {
if (typeof action !== 'function') {
throw new Error('Expected callable argument');
}
const results = [];
results.errorCount = 0;
results.warningCount = 0;
return util.transform((file, enc, done) => {
if (file.eslint) {
results.push(file.eslint);
// collect total error/warning count
results.errorCount += file.eslint.errorCount;
results.warningCount += file.eslint.warningCount;
}
done(null, file);
}, done => {
util.tryResultAction(action, results, util.handleCallback(done));
});
};
/**
* Fail when an ESLint error is found in ESLint results.
*
* @returns {stream} gulp file stream
*/
gulpEslint.failOnError = () => {
return gulpEslint.result(result => {
const error = util.firstResultMessage(result, util.isErrorMessage);
if (!error) {
return;
}
throw new PluginError('gulp-eslint', {
name: 'ESLintError',
fileName: result.filePath,
message: error.message,
lineNumber: error.line
});
});
};
/**
* Fail when the stream ends if any ESLint error(s) occurred
*
* @returns {stream} gulp file stream
*/
gulpEslint.failAfterError = () => {
return gulpEslint.results(results => {
const count = results.errorCount;
if (!count) {
return;
}
throw new PluginError('gulp-eslint', {
name: 'ESLintError',
message: 'Failed with ' + count + (count === 1 ? ' error' : ' errors')
});
});
};
/**
* Format the results of each file individually.
*
* @param {(String|Function)} [formatter=stylish] - The name or function for a ESLint result formatter
* @param {(Function|Stream)} [writable=gulp-util.log] - A funtion or stream to write the formatted ESLint results.
* @returns {stream} gulp file stream
*/
gulpEslint.formatEach = (formatter, writable) => {
formatter = util.resolveFormatter(formatter);
writable = util.resolveWritable(writable);
return gulpEslint.result(result => util.writeResults([result], formatter, writable));
};
/**
* Wait until all files have been linted and format all results at once.
*
* @param {(String|Function)} [formatter=stylish] - The name or function for a ESLint result formatter
* @param {(Function|stream)} [writable=gulp-util.log] - A funtion or stream to write the formatted ESLint results.
* @returns {stream} gulp file stream
*/
gulpEslint.format = (formatter, writable) => {
formatter = util.resolveFormatter(formatter);
writable = util.resolveWritable(writable);
return gulpEslint.results(results => {
// Only format results if files has been lint'd
if (results.length) {
util.writeResults(results, formatter, writable);
}
});
};
module.exports = gulpEslint;

View File

@ -0,0 +1,95 @@
{
"_from": "gulp-eslint@3.0.1",
"_id": "gulp-eslint@3.0.1",
"_inBundle": false,
"_integrity": "sha1-BOV+PhjGl0JnwSz2hV3HF9SjE70=",
"_location": "/gulp-eslint",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "gulp-eslint@3.0.1",
"name": "gulp-eslint",
"escapedName": "gulp-eslint",
"rawSpec": "3.0.1",
"saveSpec": null,
"fetchSpec": "3.0.1"
},
"_requiredBy": [
"#DEV:/"
],
"_resolved": "https://registry.npmjs.org/gulp-eslint/-/gulp-eslint-3.0.1.tgz",
"_shasum": "04e57e3e18c6974267c12cf6855dc717d4a313bd",
"_spec": "gulp-eslint@3.0.1",
"_where": "/home/manfred/enviPath/ketcher2/ketcher",
"author": {
"name": "Adametry"
},
"bugs": {
"url": "https://github.com/adametry/gulp-eslint/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Shinnosuke Watanabe",
"email": "snnskwtnb@gmail.com",
"url": "https://github.com/shinnn"
}
],
"dependencies": {
"bufferstreams": "^1.1.1",
"eslint": "^3.0.0",
"gulp-util": "^3.0.6"
},
"deprecated": false,
"description": "A gulp plugin for processing files with ESLint",
"devDependencies": {
"@shinnn/eslint-config-node": "^2.0.0",
"babel-eslint": "^6.1.0",
"from2-string": "^1.1.0",
"gulp": "^3.9.0",
"istanbul": "^0.4.4",
"mocha": "^2.2.5",
"should": "^9.0.2",
"vinyl": "^1.0.0"
},
"directories": {
"example": "example",
"test": "test"
},
"files": [
"index.js",
"util.js"
],
"homepage": "https://github.com/adametry/gulp-eslint#readme",
"keywords": [
"gulpplugin",
"eslint",
"gulp",
"errors",
"warnings",
"check",
"source",
"code",
"formatter",
"js",
"javascript",
"task",
"lint",
"plugin"
],
"license": "MIT",
"name": "gulp-eslint",
"repository": {
"type": "git",
"url": "git+https://github.com/adametry/gulp-eslint.git"
},
"scripts": {
"coverage": "istanbul cover _mocha",
"gulp": "gulp",
"gulp-example": "gulp --gulpfile=example/config.js",
"pretest": "gulp test",
"test": "mocha"
},
"version": "3.0.1"
}

233
static/js/ketcher2/node_modules/gulp-eslint/util.js generated vendored Normal file
View File

@ -0,0 +1,233 @@
'use strict';
const Transform = require('stream').Transform;
const gutil = require('gulp-util');
const CLIEngine = require('eslint').CLIEngine;
/**
* Convenience method for creating a transform stream in object mode
*
* @param {Function} transform - An async function that is called for each stream chunk
* @param {Function} [flush] - An async function that is called before closing the stream
* @returns {stream} A transform stream
*/
exports.transform = function(transform, flush) {
if (typeof flush === 'function') {
return new Transform({
objectMode: true,
transform,
flush
});
}
return new Transform({
objectMode: true,
transform
});
};
/**
* Mimic the CLIEngine's createIgnoreResult function,
* only without the ESLint CLI reference.
*
* @param {Object} file - file with a "path" property
* @returns {Object} An ESLint report with an ignore warning
*/
exports.createIgnoreResult = file => {
return {
filePath: file.path,
messages: [{
fatal: false,
severity: 1,
message: file.path.indexOf('node_modules/') < 0 ?
'File ignored because of .eslintignore file' :
'File ignored because it has a node_modules/** path'
}],
errorCount: 0,
warningCount: 1
};
};
/**
* Create config helper to merge various config sources
*
* @param {Object} options - options to migrate
* @returns {Object} migrated options
*/
exports.migrateOptions = function migrateOptions(options) {
if (typeof options === 'string') {
// basic config path overload: gulpEslint('path/to/config.json')
options = {
configFile: options
};
}
return options;
};
/**
* Ensure that callback errors are wrapped in a gulp PluginError
*
* @param {Function} callback - callback to wrap
* @param {Object} [value=] - A value to pass to the callback
* @returns {Function} A callback to call(back) the callback
*/
exports.handleCallback = (callback, value) => {
return err => {
if (err != null && !(err instanceof gutil.PluginError)) {
err = new gutil.PluginError(err.plugin || 'gulp-eslint', err, {
showStack: (err.showStack !== false)
});
}
callback(err, value);
};
};
/**
* Call sync or async action and handle any thrown or async error
*
* @param {Function} action - Result action to call
* @param {(Object|Array)} result - An ESLint result or result list
* @param {Function} done - An callback for when the action is complete
*/
exports.tryResultAction = function(action, result, done) {
try {
if (action.length > 1) {
// async action
action.call(this, result, done);
} else {
// sync action
action.call(this, result);
done();
}
} catch (error) {
done(error == null ? new Error('Unknown Error') : error);
}
};
/**
* Get first message in an ESLint result to meet a condition
*
* @param {Object} result - An ESLint result
* @param {Function} condition - A condition function that is passed a message and returns a boolean
* @returns {Object} The first message to pass the condition or null
*/
exports.firstResultMessage = (result, condition) => {
if (!result.messages) {
return null;
}
return result.messages.find(condition);
};
/**
* Determine if a message is an error
*
* @param {Object} message - an ESLint message
* @returns {Boolean} whether the message is an error message
*/
function isErrorMessage(message) {
const level = message.fatal ? 2 : message.severity;
if (Array.isArray(level)) {
return level[0] > 1;
}
return level > 1;
}
exports.isErrorMessage = isErrorMessage;
/**
* Increment count if message is an error
*
* @param {Number} count - count of errors
* @param {Object} message - an ESLint message
* @returns {Number} The number of errors, message included
*/
function countErrorMessage(count, message) {
return count + isErrorMessage(message);
}
/**
* Increment count if message is a warning
*
* @param {Number} count - count of warnings
* @param {Object} message - an ESLint message
* @returns {Number} The number of warnings, message included
*/
function countWarningMessage(count, message) {
return count + (message.severity === 1);
}
/**
* Filter result messages, update error and warning counts
*
* @param {Object} result - an ESLint result
* @param {Function} [filter=isErrorMessage] - A function that evaluates what messages to keep
* @returns {Object} A filtered ESLint result
*/
exports.filterResult = (result, filter) => {
if (typeof filter !== 'function') {
filter = isErrorMessage;
}
const messages = result.messages.filter(filter, result);
return {
filePath: result.filePath,
messages: messages,
errorCount: messages.reduce(countErrorMessage, 0),
warningCount: messages.reduce(countWarningMessage, 0)
};
};
/**
* Resolve formatter from unknown type (accepts string or function)
*
* @throws TypeError thrown if unable to resolve the formatter type
* @param {(String|Function)} [formatter=stylish] - A name to resolve as a formatter. If a function is provided, the same function is returned.
* @returns {Function} An ESLint formatter
*/
exports.resolveFormatter = (formatter) => {
// use ESLint to look up formatter references
if (typeof formatter !== 'function') {
// load formatter (module, relative to cwd, ESLint formatter)
formatter = CLIEngine.getFormatter(formatter) || formatter;
}
return formatter;
};
/**
* Resolve writable
*
* @param {(Function|stream)} [writable=gulp-util.log] - A stream or function to resolve as a format writer
* @returns {Function} A function that writes formatted messages
*/
exports.resolveWritable = (writable) => {
if (!writable) {
writable = gutil.log;
} else if (typeof writable.write === 'function') {
writable = writable.write.bind(writable);
}
return writable;
};
/**
* Write formatter results to writable/output
*
* @param {Object[]} results - A list of ESLint results
* @param {Function} formatter - A function used to format ESLint results
* @param {Function} writable - A function used to write formatted ESLint results
*/
exports.writeResults = (results, formatter, writable) => {
if (!results) {
results = [];
}
const firstResult = results.find(result => result.config);
const message = formatter(results, firstResult ? firstResult.config : {});
if (writable && message != null && message !== '') {
writable(message);
}
};