mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
replace gruntify-eslint with basic eslint-cli wrapper
This commit is contained in:
parent
054e798a93
commit
71732e770f
6 changed files with 97 additions and 48 deletions
|
@ -1,7 +1,8 @@
|
|||
/optimize
|
||||
/src/fixtures/vislib/mock_data
|
||||
/src/ui/public/angular-bootstrap
|
||||
/test/fixtures/scenarios
|
||||
/src/core_plugins/console/public/webpackShims
|
||||
/src/core_plugins/console/public/tests/webpackShims
|
||||
/src/core_plugins/timelion/bower_components
|
||||
/src/core_plugins/timelion/vendor_components
|
||||
test/fixtures/scenarios
|
||||
optimize
|
||||
test/fixtures/scenarios
|
||||
|
|
12
Gruntfile.js
12
Gruntfile.js
|
@ -38,18 +38,6 @@ module.exports = function (grunt) {
|
|||
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= package.author.company %>;' +
|
||||
' Licensed <%= package.license %> */\n'
|
||||
},
|
||||
|
||||
lintThese: [
|
||||
'Gruntfile.js',
|
||||
'<%= root %>/tasks/**/*.js',
|
||||
'<%= root %>/test/**/*.js',
|
||||
'<%= src %>/**/*.js',
|
||||
'!<%= src %>/ui/public/angular-bootstrap/**/*.js',
|
||||
'!<%= src %>/core_plugins/timelion/bower_components/**/*.js',
|
||||
'!<%= src %>/core_plugins/timelion/vendor_components/**/*.js',
|
||||
'!<%= src %>/fixtures/**/*.js',
|
||||
'!<%= root %>/test/fixtures/scenarios/**/*.js'
|
||||
]
|
||||
};
|
||||
|
||||
grunt.config.merge(config);
|
||||
|
|
|
@ -189,7 +189,6 @@
|
|||
"grunt-karma": "2.0.0",
|
||||
"grunt-run": "0.6.0",
|
||||
"grunt-simple-mocha": "0.4.0",
|
||||
"gruntify-eslint": "3.0.0",
|
||||
"gulp-sourcemaps": "1.7.3",
|
||||
"handlebars": "4.0.5",
|
||||
"husky": "0.8.1",
|
||||
|
|
|
@ -1,30 +1,33 @@
|
|||
var resolve = require('path').resolve;
|
||||
import { resolve } from 'path';
|
||||
module.exports = grunt => ({
|
||||
options: {
|
||||
paths: [
|
||||
'Gruntfile.js',
|
||||
'bin',
|
||||
'config',
|
||||
'src',
|
||||
'tasks',
|
||||
'test',
|
||||
'utilities',
|
||||
],
|
||||
},
|
||||
|
||||
module.exports = function (grunt) {
|
||||
return {
|
||||
// just lint the source dir
|
||||
source: {
|
||||
options: {
|
||||
cache: resolve(grunt.config.get('root'), '.eslint.fixSource.cache')
|
||||
},
|
||||
source: {
|
||||
options: {
|
||||
cache: resolve(grunt.config.get('root'), '.eslint.fixSource.cache')
|
||||
}
|
||||
},
|
||||
|
||||
files: {
|
||||
src: '<%= lintThese %>'
|
||||
}
|
||||
},
|
||||
fixSource: {
|
||||
options: {
|
||||
cache: resolve(grunt.config.get('root'), '.eslint.fixSource.cache'),
|
||||
fix: true
|
||||
}
|
||||
},
|
||||
|
||||
// lint the source and fix any fixable errors
|
||||
fixSource: {
|
||||
options: {
|
||||
cache: resolve(grunt.config.get('root'), '.eslint.fixSource.cache'),
|
||||
fix: true
|
||||
},
|
||||
|
||||
files: {
|
||||
src: '<%= lintThese %>'
|
||||
}
|
||||
},
|
||||
|
||||
staged: {}
|
||||
};
|
||||
};
|
||||
staged: {
|
||||
options: {
|
||||
paths: null // overridden by lintStagedFiles task
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
42
tasks/eslint.js
Normal file
42
tasks/eslint.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { CLIEngine } from 'eslint';
|
||||
|
||||
const OPTION_DEFAULTS = {
|
||||
paths: null,
|
||||
cache: null,
|
||||
fix: false
|
||||
};
|
||||
|
||||
module.exports = grunt => {
|
||||
grunt.registerMultiTask('eslint',function () {
|
||||
const options = this.options(OPTION_DEFAULTS);
|
||||
|
||||
if (!options.paths) {
|
||||
grunt.fatal(new Error('No eslint.options.paths specified'));
|
||||
return;
|
||||
}
|
||||
|
||||
const cli = new CLIEngine({
|
||||
cache: options.cache,
|
||||
fix: options.fix,
|
||||
cwd: grunt.config.get('root'),
|
||||
});
|
||||
|
||||
const report = cli.executeOnFiles(options.paths);
|
||||
|
||||
// output fixes to disk
|
||||
if (options.fix) {
|
||||
CLIEngine.outputFixes(report);
|
||||
}
|
||||
|
||||
// log the formatted linting report
|
||||
const formatter = cli.getFormatter();
|
||||
|
||||
const errTypes = [];
|
||||
if (report.errorCount > 0) errTypes.push('errors');
|
||||
if (report.warningCount > 0) errTypes.push('warning');
|
||||
if (!errTypes.length) return;
|
||||
|
||||
grunt.log.write(formatter(report.results));
|
||||
grunt.fatal(`eslint ${errTypes.join(' & ')}`);
|
||||
});
|
||||
};
|
|
@ -1,5 +1,7 @@
|
|||
import { resolve } from 'path';
|
||||
import { isStaged, getFilename } from './utils/files_to_commit';
|
||||
import { CLIEngine } from 'eslint';
|
||||
import minimatch from 'minimatch';
|
||||
|
||||
const root = resolve(__dirname, '..');
|
||||
|
||||
|
@ -7,18 +9,32 @@ export default function (grunt) {
|
|||
grunt.registerTask('lintStagedFiles', function () {
|
||||
grunt.task.requires('collectFilesToCommit');
|
||||
|
||||
// match these patterns
|
||||
var patterns = grunt.config.get('eslint.source.files.src');
|
||||
if (!patterns) grunt.fail.warn('eslint file pattern is not defined');
|
||||
// convert eslint paths to globs
|
||||
const cli = new CLIEngine();
|
||||
const eslintSourcePaths = grunt.config.get('eslint.options.paths');
|
||||
if (!eslintSourcePaths) grunt.fail.warn('eslint.options.paths is not defined');
|
||||
|
||||
const sourcePathRegexps = cli.resolveFileGlobPatterns(eslintSourcePaths)
|
||||
.map(glob => minimatch.makeRe(glob));
|
||||
|
||||
const files = grunt.config
|
||||
.get('filesToCommit')
|
||||
.filter(isStaged)
|
||||
.map(getFilename)
|
||||
.map(file => resolve(root, file))
|
||||
.filter(file => grunt.file.isMatch(patterns, file));
|
||||
.filter(file => {
|
||||
if (!sourcePathRegexps.some(re => file.match(re))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
grunt.config.set('eslint.staged.files.src', files);
|
||||
if (cli.isPathIgnored(file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
grunt.config.set('eslint.staged.options.paths', files);
|
||||
grunt.task.run(['eslint:staged']);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue