在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):adametry/gulp-eslint开源软件地址(OpenSource Url):https://github.com/adametry/gulp-eslint开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-eslintInstallation
Usageconst {src, task} = require('gulp');
const eslint = require('gulp-eslint');
task('default', () => {
return src(['scripts/*.js'])
// 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());
}); Or use the plugin API to do things like: 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. APIeslint()No explicit configuration. A eslint(options)options.rulesType: Set configuration of rules. {
"rules":{
"camelcase": 1,
"comma-dangle": 2,
"quotes": 0
}
} options.globalsType: Specify global variables to declare. {
"globals":[
"jQuery",
"$"
]
} options.fixType: 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 When fixes are applied, a "fixed" property is set to options.quietType: When Type: When provided a function, it will be used to filter ESLint result messages, removing any messages that do not return a options.envsType: Specify a list of environments to be applied. options.rulePathsType: 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. options.configFileType: Path to the ESLint rules configuration file. For more information, see the ESLint CLI config option and Using Configuration Files. options.warnFileIgnoredType: When options.useEslintrcType: When eslint(configFilePath)Type: Shorthand for defining eslint.result(action)Type: 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. 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: 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: 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. 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: 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. // 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. // 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 The // 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 // 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 The arguments for ConfigurationESLint may be configured explicity by using any of the following plugin options: Ignore FilesESLint will ignore files that do not have a ESLint will also detect an ExtensionsESLint 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 Gulp-Eslint Extensions: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论