* [eslint] upgrade to 4.10.0
* [eslint-config-kibana] limit jest config to jest test files
* [ui_framework] remove trailing comma from rest-spreads
* [dashboard/tests] tag jest helpers with .test.js suffix
* explicitly import expect.js where used
* [eslint] apply auto-fixes
* [eslint] manually add/wrap some parens for compliance
* [npm] point to local packages for testing/review
* [jest] remove .test extension from jest helpers
* [ui_framework] fix trailing comma removal from 3bc661a1c8
* [packages] upgrade eslint packages
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
|
|
import { extname, resolve, relative } from 'path';
|
|
import { isStaged, getFilename } from './utils/files_to_commit';
|
|
import { CLIEngine } from 'eslint';
|
|
import { red, blue } from 'ansicolors';
|
|
import minimatch from 'minimatch';
|
|
|
|
import { DEFAULT_ESLINT_PATHS } from '../src/dev/default_eslint_paths';
|
|
|
|
const root = resolve(__dirname, '..');
|
|
|
|
export default function (grunt) {
|
|
grunt.registerTask('lintStagedFiles', function () {
|
|
grunt.task.requires('collectFilesToCommit');
|
|
|
|
// convert eslint paths to globs
|
|
const cli = new CLIEngine();
|
|
const sourcePathGlobs = cli.resolveFileGlobPatterns(DEFAULT_ESLINT_PATHS);
|
|
|
|
const files = grunt.config
|
|
.get('filesToCommit')
|
|
.filter(isStaged)
|
|
.map(getFilename)
|
|
.map(file => relative(root, resolve(file))) // resolve to pwd, then get relative from the root
|
|
.filter(file => {
|
|
if (!sourcePathGlobs.some(glob => minimatch(file, glob))) {
|
|
if (extname(file) === '.js') {
|
|
grunt.log.writeln(`${red('WARNING:')} ${file} not selected by src/eslint/default_eslint_paths`);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
if (cli.isPathIgnored(file)) {
|
|
if (extname(file) === '.js') {
|
|
grunt.log.writeln(`${blue('DEBUG:')} ${file} ignored by .eslintignore`);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
if (files.length) {
|
|
const args = grunt.config.get('run.eslintStaged.args');
|
|
grunt.config.set('run.eslintStaged.args', [
|
|
...args,
|
|
...files
|
|
]);
|
|
|
|
grunt.task.run(['run:eslintStaged']);
|
|
}
|
|
});
|
|
}
|